b311480e |
1 | // Created on: 2001-06-25 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <LDOMString.hxx> |
17 | #include <LDOM_MemManager.hxx> |
18 | |
19 | //======================================================================= |
20 | //function : CreateDirectString |
21 | //purpose : Only for hashed strings!! |
22 | //======================================================================= |
23 | |
24 | LDOMString LDOMString::CreateDirectString (const char * aValue, |
25 | const LDOM_MemManager& aDoc) |
26 | { |
27 | LDOMString aResult; |
28 | aResult.myPtrDoc = &aDoc; |
29 | aResult.SetDirect (LDOMBasicString::LDOM_AsciiHashed, aValue); |
30 | return aResult; |
31 | } |
32 | |
33 | //======================================================================= |
34 | //function : LDOMString |
35 | //purpose : Copy from another string with allocation in the document |
36 | //======================================================================= |
37 | |
38 | LDOMString::LDOMString (const LDOMBasicString& anOther, |
39 | const Handle(LDOM_MemManager)& aDoc) |
40 | : myPtrDoc (&aDoc -> Self()) |
41 | { |
42 | myType = anOther.Type(); |
43 | switch (myType) |
44 | { |
45 | case LDOM_Integer: |
46 | anOther.GetInteger (myVal.i); |
47 | break; |
48 | case LDOM_AsciiFree: |
49 | myType = LDOM_AsciiDoc; |
b1811c1d |
50 | Standard_FALLTHROUGH |
7fd59977 |
51 | case LDOM_AsciiDocClear: |
52 | case LDOM_AsciiDoc: |
53 | { |
54 | const char * aString = anOther.GetString (); |
7dc9e047 |
55 | Standard_Integer aLen = (Standard_Integer)(strlen (aString) + 1); |
7fd59977 |
56 | myVal.ptr = ((LDOM_MemManager *) myPtrDoc) -> Allocate (aLen); |
57 | memcpy (myVal.ptr, aString, aLen); |
58 | } |
59 | break; |
60 | case LDOM_AsciiHashed: |
61 | myVal.ptr = (void *)anOther.GetString (); |
62 | break; |
63 | default: |
64 | myType = LDOM_NULL; |
65 | } |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : LDOMString |
70 | //purpose : Copy from another with allocation in the document if necessary |
71 | //======================================================================= |
72 | /* |
73 | LDOMString::LDOMString (const LDOMString& anOther, const LDOM_Document& aDoc) |
74 | : myPtrDoc (&aDoc.myMemManager -> Self()) |
75 | { |
76 | switch (anOther.Type()) |
77 | { |
78 | case LDOM_Integer: |
79 | myType = LDOM_Integer; |
80 | anOther.GetInteger (myVal.i); |
81 | break; |
82 | case LDOM_AsciiDoc: |
83 | if (aDoc == anOther.getOwnerDocument()) |
84 | case LDOM_AsciiHashed: |
85 | myVal.ptr = (void *)anOther.GetString (); |
86 | else { |
87 | case LDOM_AsciiFree: |
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; |
93 | } |
94 | break; |
95 | default: ; |
96 | } |
97 | } |
98 | */ |