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; |
50 | case LDOM_AsciiDocClear: |
51 | case LDOM_AsciiDoc: |
52 | { |
53 | const char * aString = anOther.GetString (); |
7dc9e047 |
54 | Standard_Integer aLen = (Standard_Integer)(strlen (aString) + 1); |
7fd59977 |
55 | myVal.ptr = ((LDOM_MemManager *) myPtrDoc) -> Allocate (aLen); |
56 | memcpy (myVal.ptr, aString, aLen); |
57 | } |
58 | break; |
59 | case LDOM_AsciiHashed: |
60 | myVal.ptr = (void *)anOther.GetString (); |
61 | break; |
62 | default: |
63 | myType = LDOM_NULL; |
64 | } |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : LDOMString |
69 | //purpose : Copy from another with allocation in the document if necessary |
70 | //======================================================================= |
71 | /* |
72 | LDOMString::LDOMString (const LDOMString& anOther, const LDOM_Document& aDoc) |
73 | : myPtrDoc (&aDoc.myMemManager -> Self()) |
74 | { |
75 | switch (anOther.Type()) |
76 | { |
77 | case LDOM_Integer: |
78 | myType = LDOM_Integer; |
79 | anOther.GetInteger (myVal.i); |
80 | break; |
81 | case LDOM_AsciiDoc: |
82 | if (aDoc == anOther.getOwnerDocument()) |
83 | case LDOM_AsciiHashed: |
84 | myVal.ptr = (void *)anOther.GetString (); |
85 | else { |
86 | case LDOM_AsciiFree: |
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; |
92 | } |
93 | break; |
94 | default: ; |
95 | } |
96 | } |
97 | */ |