0022092: Crash of application on attempt to load a VRML file with all degenerated...
[occt.git] / src / VrmlData / VrmlData_Node.hxx
CommitLineData
7fd59977 1// File: VrmlData_Node.hxx
2// Created: 25.05.06 14:58:45
3// Author: Alexander GRIGORIEV
4// Copyright: Open Cascade 2006
5
6
7#ifndef VrmlData_Node_HeaderFile
8#define VrmlData_Node_HeaderFile
9
10#include <Handle_Standard_Type.hxx>
11#include <NCollection_List.hxx>
12#include <Standard_DefineHandle.hxx>
13#include <Standard_TypeDef.hxx>
14#include <TCollection_AsciiString.hxx>
15#include <VrmlData_ErrorStatus.hxx>
16
17#define VRMLDATA_LCOMPARE(aa, bb) \
18 ((strncmp (aa, bb, sizeof(bb)-1)) ? 0L : (aa += sizeof(bb)-1))
19
20struct VrmlData_InBuffer;
21class VrmlData_Scene;
22class gp_XY;
23class gp_XYZ;
24class Handle_VrmlData_Node;
25class TCollection_AsciiString;
26
27/**
28 * Abstract VRML Node
29 */
30class VrmlData_Node : public Standard_Transient
31{
32 public:
33 // ---------- PUBLIC METHODS ----------
34
35 /**
36 * Empty constructor
37 */
38 Standard_EXPORT VrmlData_Node ();
39
40 /**
41 * Destructor
42 */
43 virtual ~VrmlData_Node () {}
44
45 /**
46 * Query the Scene that contains this Node
47 */
48 inline const VrmlData_Scene& Scene () const
49 { return * myScene; }
50
51 /**
52 * Query the name
53 */
54 inline const char * Name () const { return myName; }
55
56 /**
57 * Read a complete node definition from VRML stream
58 * @param theBuffer
59 * Buffer receiving the input data.
60 * @param theNode
61 * <tt>[out]</tt> Node restored from the buffer data
62 * @param Type
63 * Node type to be checked. If it is NULL(default) no type checking is done.
64 * Otherwise the created node is matched and an error is returned if
65 * no match detected.
66 */
67 Standard_EXPORT VrmlData_ErrorStatus
68 ReadNode (VrmlData_InBuffer& theBuffer,
69 Handle(VrmlData_Node)&theNode,
70 const Handle(Standard_Type)& Type
71 = NULL);
72
73 /**
74 * Read the Node from input stream.
75 */
76 Standard_EXPORT virtual VrmlData_ErrorStatus
77 Read (VrmlData_InBuffer& theBuffer) = 0;
78
79 /**
80 * Write the Node to output stream.
81 */
82 Standard_EXPORT virtual VrmlData_ErrorStatus
83 Write (const char * thePrefix) const;
84
85 /**
86 * Returns True if the node is default, then it would not be written.
87 */
88 Standard_EXPORT virtual Standard_Boolean
89 IsDefault () const;
90
91 /**
92 * Write the closing brace in the end of a node output.
93 */
94 Standard_EXPORT VrmlData_ErrorStatus
95 WriteClosing () const;
96
97 /**
98 * Create a copy of this node.
99 * If the parameter is null, a new copied node is created. Otherwise new node
100 * is not created, but rather the given one is modified.<p>
101 * This method nullifies the argument node if its member myScene differs
102 * from that one of the current instance.
103 */
104 Standard_EXPORT virtual Handle(VrmlData_Node)
105 Clone (const Handle(VrmlData_Node)&)const;
106
107 /**
108 * Read one boolean value (TRUE or FALSE).
109 */
110 Standard_EXPORT static VrmlData_ErrorStatus
111 ReadBoolean (VrmlData_InBuffer& theBuffer,
112 Standard_Boolean& theResult);
113
114 /**
115 * Read one quoted string, the quotes are removed.
116 */
117 Standard_EXPORT static VrmlData_ErrorStatus
118 ReadString (VrmlData_InBuffer& theBuffer,
119 TCollection_AsciiString& theRes);
120
121 /**
122 * Read one quoted string, the quotes are removed.
123 */
124 Standard_EXPORT static VrmlData_ErrorStatus
125 ReadMultiString
126 (VrmlData_InBuffer& theBuffer,
127 NCollection_List<TCollection_AsciiString>& theRes);
128
129 /**
130 * Read one integer value.
131 */
132 Standard_EXPORT static VrmlData_ErrorStatus
133 ReadInteger (VrmlData_InBuffer& theBuffer,
134 long& theResult);
135
136 static inline Standard_Boolean OK (const VrmlData_ErrorStatus theStat)
137 { return theStat == VrmlData_StatusOK; }
138
139 static inline Standard_Boolean OK (VrmlData_ErrorStatus& outStat,
140 const VrmlData_ErrorStatus theStat)
141 { return (outStat = theStat) == VrmlData_StatusOK; }
142
143 /**
144 * Define the common Indent in spaces, for writing all nodes.
145 */
146 static inline Standard_Integer GlobalIndent ()
147 { return 2; }
148
149 protected:
150 // ---------- PROTECTED METHODS ----------
151
152 /**
153 * Constructor
154 */
155 Standard_EXPORT VrmlData_Node (const VrmlData_Scene& theScene,
156 const char * theName);
157
158 /**
159 * Read the closing brace. If successful, theBufrfer is incremented.
160 * If no brace is found, theBuffer stays in untouched and the method returns
161 * VrmlFormatError.
162 */
163 Standard_EXPORT static VrmlData_ErrorStatus
164 readBrace (VrmlData_InBuffer& theBuffer);
165
166 private:
167 // ---------- PRIVATE METHODS ----------
168
169 /**
170 * Method called from VrmlData_Scene when a name should be assigned
171 * automatically.
172 */
173 Standard_EXPORT void setName (const char * theName,
174 const char * theSuffix = 0L);
175
176 private:
177 // ---------- PRIVATE FIELDS ----------
178
179 const VrmlData_Scene * myScene;
180 const char * myName; ///< name of the node
181#ifdef _DEBUG
182 Standard_Integer myLineCount;
183#endif
184
185 friend class VrmlData_Group;
186 friend class VrmlData_Scene;
187
188 public:
189// Declaration of CASCADE RTTI
190 DEFINE_STANDARD_RTTI (VrmlData_Node)
191};
192
193// Definition of HANDLE object using Standard_DefineHandle.hxx
194DEFINE_STANDARD_HANDLE (VrmlData_Node, Standard_Transient)
195
196Standard_EXPORT Standard_Integer HashCode(const Handle_VrmlData_Node& theNode,
197 const Standard_Integer theUpper);
198Standard_EXPORT Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne,
199 const Handle(VrmlData_Node)& theTwo);
200
201#endif