b311480e |
1 | // Created on: 2001-06-26 |
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 | #ifndef LDOMBasicString_HeaderFile |
17 | #define LDOMBasicString_HeaderFile |
18 | |
19 | #include <Standard_Type.hxx> |
20 | #include <Standard_Macro.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
22 | #include <TCollection_ExtendedString.hxx> |
23 | |
5b111128 |
24 | class LDOM_MemManager; |
7fd59977 |
25 | class LDOM_NullPtr; |
26 | class TCollection_AsciiString; |
27 | class TCollection_ExtendedString; |
28 | |
29 | // Block of comments describing class LDOMBasicString |
30 | // |
31 | |
32 | class LDOMBasicString |
33 | { |
34 | friend class LDOM_MemManager; |
35 | friend class LDOM_Node; |
36 | public: |
37 | enum StringType { |
38 | LDOM_NULL = 0, |
39 | LDOM_Integer, |
40 | // LDOM_Real, |
41 | LDOM_AsciiFree, // String not connected to any container |
42 | LDOM_AsciiDoc, // String connected to LDOM_Document (container) |
43 | LDOM_AsciiDocClear, // --"--"--, consists of only XML-valid chars |
44 | LDOM_AsciiHashed // String connected to hash table |
45 | }; |
46 | |
47 | Standard_EXPORT ~LDOMBasicString (); |
48 | |
49 | StringType Type () const { return myType; } |
50 | |
51 | Standard_EXPORT Standard_Boolean |
52 | GetInteger (Standard_Integer& aResult) const; |
53 | // Conversion to Integer (only for LDOM_Integer) |
54 | |
55 | const char * |
56 | GetString () const { return myType == LDOM_Integer || |
57 | myType == LDOM_NULL ? |
58 | "" : (const char *) myVal.ptr; } |
59 | // Conversion to char * (only for LDOM_Ascii*) |
60 | |
61 | Standard_EXPORT Standard_Boolean |
62 | equals (const LDOMBasicString& anOther) const; |
63 | // Compare two strings by content |
64 | |
65 | Standard_EXPORT LDOMBasicString& |
66 | operator = (const LDOM_NullPtr *); |
67 | |
68 | Standard_EXPORT LDOMBasicString& |
69 | operator = (const LDOMBasicString& anOther); |
70 | |
71 | Standard_Boolean |
72 | operator == (const LDOM_NullPtr *) const |
73 | { return myType==LDOM_NULL; } |
74 | Standard_Boolean |
75 | operator != (const LDOM_NullPtr *) const |
76 | { return myType!=LDOM_NULL; } |
77 | |
78 | Standard_Boolean |
79 | operator == (const LDOMBasicString& anOther) const |
80 | { |
81 | return myType==anOther.myType && myVal.i==anOther.myVal.i; |
82 | } |
83 | |
84 | Standard_Boolean |
85 | operator != (const LDOMBasicString& anOther) const |
86 | { |
87 | return myType!=anOther.myType || myVal.i!=anOther.myVal.i; |
88 | } |
89 | |
90 | // AGV auxiliary API |
91 | Standard_EXPORT operator TCollection_AsciiString () const; |
92 | |
93 | Standard_EXPORT operator TCollection_ExtendedString () const; |
94 | |
95 | LDOMBasicString () |
96 | : myType (LDOM_NULL) { myVal.ptr = NULL; } |
97 | // Empty constructor |
98 | |
99 | Standard_EXPORT LDOMBasicString (const LDOMBasicString& anOther); |
100 | // Copy constructor |
101 | |
102 | LDOMBasicString (const Standard_Integer aValue) |
103 | : myType (LDOM_Integer) { myVal.i = aValue; } |
104 | |
105 | Standard_EXPORT LDOMBasicString (const char * aValue); |
106 | // Create LDOM_AsciiFree |
107 | |
108 | Standard_EXPORT LDOMBasicString (const char * aValue, |
109 | const Handle(LDOM_MemManager)& aDoc); |
110 | // Create LDOM_AsciiDoc |
111 | |
112 | Standard_EXPORT LDOMBasicString (const char * aValue, |
113 | const Standard_Integer aLen, |
114 | const Handle(LDOM_MemManager)& aDoc); |
115 | // Create LDOM_AsciiDoc |
116 | |
117 | protected: |
118 | // ---------- PROTECTED METHODS ---------- |
119 | void SetDirect (const StringType aType, const char * aValue) |
120 | { myType = aType; myVal.ptr = (void *) aValue; } |
121 | |
122 | |
123 | protected: |
124 | // ---------- PROTECTED FIELDS ---------- |
125 | |
126 | StringType myType; |
127 | union { |
128 | int i; |
129 | void * ptr; |
130 | } myVal; |
131 | friend char * db_pretty_print (const LDOMBasicString *, int, char *); |
132 | }; |
133 | |
134 | #endif |