0023326: The 'aSibling' pointer was utilized before it was verified against nullptr...
[occt.git] / src / LDOM / LDOMBasicString.hxx
1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21
22 #ifndef LDOMBasicString_HeaderFile
23 #define LDOMBasicString_HeaderFile
24
25 #include <Standard_Type.hxx>
26 #include <Standard_Macro.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29
30 class Handle(LDOM_MemManager);
31 class LDOM_NullPtr;
32 class TCollection_AsciiString;
33 class TCollection_ExtendedString;
34
35 //  Block of comments describing class LDOMBasicString
36 //
37
38 class LDOMBasicString 
39 {
40   friend class LDOM_MemManager;
41   friend class LDOM_Node;
42  public:
43   enum StringType {
44     LDOM_NULL = 0,
45     LDOM_Integer,
46 //    LDOM_Real,
47     LDOM_AsciiFree,             // String not connected to any container
48     LDOM_AsciiDoc,              // String connected to LDOM_Document (container)
49     LDOM_AsciiDocClear,         // --"--"--, consists of only XML-valid chars
50     LDOM_AsciiHashed            // String connected to hash table
51   };
52
53   Standard_EXPORT ~LDOMBasicString ();
54
55   StringType Type       () const              { return myType; }
56
57   Standard_EXPORT Standard_Boolean
58         GetInteger      (Standard_Integer& aResult) const;
59   //    Conversion to Integer (only for LDOM_Integer)
60
61   const char *
62         GetString       () const        { return myType == LDOM_Integer ||
63                                                  myType == LDOM_NULL ?
64                                             "" : (const char *) myVal.ptr; }
65   //    Conversion to char * (only for LDOM_Ascii*)
66
67   Standard_EXPORT Standard_Boolean
68         equals          (const LDOMBasicString& anOther) const;
69   //    Compare two strings by content
70
71   Standard_EXPORT LDOMBasicString&
72         operator =      (const LDOM_NullPtr *);
73
74   Standard_EXPORT LDOMBasicString&
75         operator =      (const LDOMBasicString& anOther);
76
77   Standard_Boolean
78         operator ==     (const LDOM_NullPtr *) const
79                                                 { return myType==LDOM_NULL; }
80   Standard_Boolean
81         operator !=     (const LDOM_NullPtr *) const
82                                                 { return myType!=LDOM_NULL; }
83
84   Standard_Boolean
85         operator ==     (const LDOMBasicString& anOther) const
86         {
87           return myType==anOther.myType && myVal.i==anOther.myVal.i;
88         }
89
90   Standard_Boolean
91         operator !=     (const LDOMBasicString& anOther) const
92         {
93           return myType!=anOther.myType || myVal.i!=anOther.myVal.i;
94         }
95
96 //      AGV auxiliary API
97   Standard_EXPORT operator TCollection_AsciiString      () const;
98
99   Standard_EXPORT operator TCollection_ExtendedString   () const;
100
101   LDOMBasicString                 ()
102     : myType (LDOM_NULL)             { myVal.ptr = NULL; }
103   // Empty constructor
104
105   Standard_EXPORT LDOMBasicString (const LDOMBasicString& anOther);
106   // Copy constructor
107
108   LDOMBasicString                 (const Standard_Integer aValue)
109     : myType (LDOM_Integer)             { myVal.i = aValue; }
110
111   Standard_EXPORT LDOMBasicString (const char           * aValue);
112   //    Create LDOM_AsciiFree
113
114   Standard_EXPORT LDOMBasicString (const char           * aValue,
115                                    const Handle(LDOM_MemManager)& aDoc);
116   //    Create LDOM_AsciiDoc
117
118   Standard_EXPORT LDOMBasicString (const char             * aValue,
119                                    const Standard_Integer aLen,
120                                    const Handle(LDOM_MemManager)&   aDoc);
121   //    Create LDOM_AsciiDoc
122
123  protected:
124   // ---------- PROTECTED METHODS ----------
125   void            SetDirect       (const StringType aType, const char * aValue)
126     { myType = aType; myVal.ptr = (void *) aValue; }
127     
128
129  protected:
130   // ---------- PROTECTED FIELDS ----------
131
132   StringType            myType;
133   union {
134     int         i;
135     void        * ptr;
136   }                     myVal;
137   friend char * db_pretty_print (const LDOMBasicString *, int, char *);
138 };
139
140 #endif