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 under
8 // the terms of the GNU Lesser General Public License 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;
51 case LDOM_AsciiDocClear:
54 const char * aString = anOther.GetString ();
55 Standard_Integer aLen = (Standard_Integer)(strlen (aString) + 1);
56 myVal.ptr = ((LDOM_MemManager *) myPtrDoc) -> Allocate (aLen);
57 memcpy (myVal.ptr, aString, aLen);
60 case LDOM_AsciiHashed:
61 myVal.ptr = (void *)anOther.GetString ();
68 //=======================================================================
69 //function : LDOMString
70 //purpose : Copy from another with allocation in the document if necessary
71 //=======================================================================
73 LDOMString::LDOMString (const LDOMString& anOther, const LDOM_Document& aDoc)
74 : myPtrDoc (&aDoc.myMemManager -> Self())
76 switch (anOther.Type())
79 myType = LDOM_Integer;
80 anOther.GetInteger (myVal.i);
83 if (aDoc == anOther.getOwnerDocument())
84 case LDOM_AsciiHashed:
85 myVal.ptr = (void *)anOther.GetString ();
88 const char * aString = anOther.GetString ();
89 Standard_Integer aLen = strlen (aString) + 1;
90 myVal.ptr = aDoc.AllocMem (aLen);
91 memcpy (myVal.ptr, aString, aLen);
92 myType = LDOM_AsciiDoc;