Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-07 08:37:05

0001 // Created on: 2006-05-25
0002 // Created by: Alexander GRIGORIEV
0003 // Copyright (c) 2006-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef VrmlData_Node_HeaderFile
0017 #define VrmlData_Node_HeaderFile
0018 
0019 #include <NCollection_List.hxx>
0020 #include <Standard_Type.hxx>
0021 #include <Standard_TypeDef.hxx>
0022 #include <TCollection_AsciiString.hxx>
0023 #include <Standard_CStringHasher.hxx>
0024 #include <VrmlData_ErrorStatus.hxx>
0025 
0026 #define VRMLDATA_LCOMPARE(aa, bb) ((strncmp(aa, bb, sizeof(bb) - 1)) ? 0L : (aa += sizeof(bb) - 1))
0027 
0028 struct VrmlData_InBuffer;
0029 class VrmlData_Scene;
0030 class TCollection_AsciiString;
0031 
0032 /**
0033  *  Abstract VRML Node
0034  */
0035 class VrmlData_Node : public Standard_Transient
0036 {
0037 public:
0038   // ---------- PUBLIC METHODS ----------
0039 
0040   /**
0041    * Empty constructor
0042    */
0043   Standard_EXPORT VrmlData_Node();
0044 
0045   /**
0046    * Destructor
0047    */
0048   virtual ~VrmlData_Node() {}
0049 
0050   /**
0051    * Query the Scene that contains this Node
0052    */
0053   inline const VrmlData_Scene& Scene() const { return *myScene; }
0054 
0055   /**
0056    * Query the name
0057    */
0058   inline const char* Name() const { return myName; }
0059 
0060   /**
0061    * Read a complete node definition from VRML stream
0062    * @param theBuffer
0063    *   Buffer receiving the input data.
0064    * @param theNode
0065    *   <tt>[out]</tt> Node restored from the buffer data
0066    * @param Type
0067    *   Node type to be checked. If it is NULL(default) no type checking is done.
0068    *   Otherwise the created node is matched and an error is returned if
0069    *   no match detected.
0070    */
0071   Standard_EXPORT VrmlData_ErrorStatus ReadNode(VrmlData_InBuffer&           theBuffer,
0072                                                 Handle(VrmlData_Node)&       theNode,
0073                                                 const Handle(Standard_Type)& Type = NULL);
0074 
0075   /**
0076    * Read the Node from input stream.
0077    */
0078   Standard_EXPORT virtual VrmlData_ErrorStatus Read(VrmlData_InBuffer& theBuffer) = 0;
0079 
0080   /**
0081    * Write the Node to output stream.
0082    */
0083   Standard_EXPORT virtual VrmlData_ErrorStatus Write(const char* thePrefix) const;
0084 
0085   /**
0086    * Returns True if the node is default, then it would not be written.
0087    */
0088   Standard_EXPORT virtual Standard_Boolean IsDefault() const;
0089 
0090   /**
0091    * Write the closing brace in the end of a node output.
0092    */
0093   Standard_EXPORT VrmlData_ErrorStatus WriteClosing() const;
0094 
0095   /**
0096    * Create a copy of this node.
0097    * If the parameter is null, a new copied node is created. Otherwise new node
0098    * is not created, but rather the given one is modified.<p>
0099    * This method nullifies the argument node if its member myScene differs
0100    * from that one of the current instance.
0101    */
0102   Standard_EXPORT virtual Handle(VrmlData_Node) Clone(const Handle(VrmlData_Node)&) const;
0103 
0104   /**
0105    * Read one boolean value (TRUE or FALSE).
0106    */
0107   Standard_EXPORT static VrmlData_ErrorStatus ReadBoolean(VrmlData_InBuffer& theBuffer,
0108                                                           Standard_Boolean&  theResult);
0109 
0110   /**
0111    * Read one quoted string, the quotes are removed.
0112    */
0113   Standard_EXPORT static VrmlData_ErrorStatus ReadString(VrmlData_InBuffer&       theBuffer,
0114                                                          TCollection_AsciiString& theRes);
0115 
0116   /**
0117    * Read one quoted string, the quotes are removed.
0118    */
0119   Standard_EXPORT static VrmlData_ErrorStatus ReadMultiString(
0120     VrmlData_InBuffer&                         theBuffer,
0121     NCollection_List<TCollection_AsciiString>& theRes);
0122 
0123   /**
0124    * Read one integer value.
0125    */
0126   Standard_EXPORT static VrmlData_ErrorStatus ReadInteger(VrmlData_InBuffer& theBuffer,
0127                                                           long&              theResult);
0128 
0129   static inline Standard_Boolean OK(const VrmlData_ErrorStatus theStat)
0130   {
0131     return theStat == VrmlData_StatusOK;
0132   }
0133 
0134   static inline Standard_Boolean OK(VrmlData_ErrorStatus&      outStat,
0135                                     const VrmlData_ErrorStatus theStat)
0136   {
0137     return (outStat = theStat) == VrmlData_StatusOK;
0138   }
0139 
0140   /**
0141    * Define the common Indent in spaces, for writing all nodes.
0142    */
0143   static inline Standard_Integer GlobalIndent() { return 2; }
0144 
0145 protected:
0146   // ---------- PROTECTED METHODS ----------
0147 
0148   /**
0149    * Constructor
0150    */
0151   Standard_EXPORT VrmlData_Node(const VrmlData_Scene& theScene, const char* theName);
0152 
0153   /**
0154    * Read the closing brace. If successful, theBufrfer is incremented.
0155    * If no brace is found, theBuffer stays in untouched and the method returns
0156    * VrmlFormatError.
0157    */
0158   Standard_EXPORT static VrmlData_ErrorStatus readBrace(VrmlData_InBuffer& theBuffer);
0159 
0160 private:
0161   // ---------- PRIVATE METHODS ----------
0162 
0163   /**
0164    * Method called from VrmlData_Scene when a name should be assigned
0165    * automatically.
0166    */
0167   Standard_EXPORT void setName(const char* theName, const char* theSuffix = 0L);
0168 
0169 private:
0170   // ---------- PRIVATE FIELDS ----------
0171 
0172   const VrmlData_Scene* myScene;
0173   const char*           myName; ///< name of the node
0174 #ifdef OCCT_DEBUG
0175   Standard_Integer myLineCount;
0176 #endif
0177 
0178   friend class VrmlData_Group;
0179   friend class VrmlData_Scene;
0180 
0181 public:
0182   // Declaration of CASCADE RTTI
0183   DEFINE_STANDARD_RTTIEXT(VrmlData_Node, Standard_Transient)
0184 };
0185 
0186 // Definition of HANDLE object using Standard_DefineHandle.hxx
0187 DEFINE_STANDARD_HANDLE(VrmlData_Node, Standard_Transient)
0188 
0189 Standard_EXPORT Standard_Boolean IsEqual(const Handle(VrmlData_Node)& theOne,
0190                                          const Handle(VrmlData_Node)& theTwo);
0191 
0192 namespace std
0193 {
0194 template <>
0195 struct hash<Handle(VrmlData_Node)>
0196 {
0197   size_t operator()(const Handle(VrmlData_Node)& theNode) const
0198   {
0199     if (!theNode->Name())
0200     {
0201       return 1;
0202     }
0203     return Standard_CStringHasher{}(theNode->Name());
0204   }
0205 };
0206 
0207 template <>
0208 struct equal_to<Handle(VrmlData_Node)>
0209 {
0210   bool operator()(const Handle(VrmlData_Node)& theNode1,
0211                   const Handle(VrmlData_Node)& theNode2) const noexcept
0212   {
0213     return IsEqual(theNode1, theNode2);
0214   }
0215 };
0216 } // namespace std
0217 
0218 #endif