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