1 // Created on: 2001-06-25
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <LDOMString.hxx>
17 #include <LDOM_MemManager.hxx>
19 //=======================================================================
20 //function : CreateDirectString
21 //purpose : Only for hashed strings!!
22 //=======================================================================
24 LDOMString LDOMString::CreateDirectString (const char * aValue,
25 const LDOM_MemManager& aDoc)
28 aResult.myPtrDoc = &aDoc;
29 aResult.SetDirect (LDOMBasicString::LDOM_AsciiHashed, aValue);
33 //=======================================================================
34 //function : LDOMString
35 //purpose : Copy from another string with allocation in the document
36 //=======================================================================
38 LDOMString::LDOMString (const LDOMBasicString& anOther,
39 const Handle(LDOM_MemManager)& aDoc)
40 : myPtrDoc (&aDoc -> Self())
42 myType = anOther.Type();
46 anOther.GetInteger (myVal.i);
49 myType = LDOM_AsciiDoc;
50 case LDOM_AsciiDocClear:
53 const char * aString = anOther.GetString ();
54 Standard_Integer aLen = (Standard_Integer)(strlen (aString) + 1);
55 myVal.ptr = ((LDOM_MemManager *) myPtrDoc) -> Allocate (aLen);
56 memcpy (myVal.ptr, aString, aLen);
59 case LDOM_AsciiHashed:
60 myVal.ptr = (void *)anOther.GetString ();
67 //=======================================================================
68 //function : LDOMString
69 //purpose : Copy from another with allocation in the document if necessary
70 //=======================================================================
72 LDOMString::LDOMString (const LDOMString& anOther, const LDOM_Document& aDoc)
73 : myPtrDoc (&aDoc.myMemManager -> Self())
75 switch (anOther.Type())
78 myType = LDOM_Integer;
79 anOther.GetInteger (myVal.i);
82 if (aDoc == anOther.getOwnerDocument())
83 case LDOM_AsciiHashed:
84 myVal.ptr = (void *)anOther.GetString ();
87 const char * aString = anOther.GetString ();
88 Standard_Integer aLen = strlen (aString) + 1;
89 myVal.ptr = aDoc.AllocMem (aLen);
90 memcpy (myVal.ptr, aString, aLen);
91 myType = LDOM_AsciiDoc;