Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:32

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) \
0027 ((strncmp (aa, bb, sizeof(bb)-1)) ? 0L : (aa += sizeof(bb)-1))
0028 
0029 struct VrmlData_InBuffer;
0030 class VrmlData_Scene;
0031 class TCollection_AsciiString;
0032 
0033 /**
0034  *  Abstract VRML Node
0035  */
0036 class VrmlData_Node : public Standard_Transient
0037 {
0038  public:
0039   // ---------- PUBLIC METHODS ----------
0040 
0041   /**
0042    * Empty constructor
0043    */
0044   Standard_EXPORT               VrmlData_Node   ();
0045 
0046   /**
0047    * Destructor
0048    */
0049   virtual                       ~VrmlData_Node  () {}
0050 
0051   /**
0052    * Query the Scene that contains this Node
0053    */
0054   inline const VrmlData_Scene&  Scene           () const
0055   { return * myScene; }
0056 
0057   /**
0058    * Query the name
0059    */
0060   inline const char *           Name            () const { return myName; } 
0061 
0062   /**
0063    * Read a complete node definition from VRML stream
0064    * @param theBuffer
0065    *   Buffer receiving the input data.
0066    * @param theNode
0067    *   <tt>[out]</tt> Node restored from the buffer data
0068    * @param Type
0069    *   Node type to be checked. If it is NULL(default) no type checking is done.
0070    *   Otherwise the created node is matched and an error is returned if
0071    *   no match detected.
0072    */
0073   Standard_EXPORT VrmlData_ErrorStatus
0074                                 ReadNode    (VrmlData_InBuffer&    theBuffer,
0075                                              Handle(VrmlData_Node)&theNode,
0076                                              const Handle(Standard_Type)& Type
0077                                                 = NULL);
0078 
0079   /**
0080    * Read the Node from input stream.
0081    */
0082   Standard_EXPORT virtual VrmlData_ErrorStatus
0083                                 Read        (VrmlData_InBuffer& theBuffer) = 0;
0084 
0085   /**
0086    * Write the Node to output stream.
0087    */
0088   Standard_EXPORT virtual VrmlData_ErrorStatus
0089                                 Write       (const char * thePrefix) const;
0090 
0091   /**
0092    * Returns True if the node is default, then it would not be written.
0093    */
0094   Standard_EXPORT virtual Standard_Boolean
0095                                 IsDefault   () const;
0096 
0097   /**
0098    * Write the closing brace in the end of a node output.
0099    */
0100   Standard_EXPORT VrmlData_ErrorStatus
0101                                 WriteClosing () const;
0102 
0103   /**
0104    * Create a copy of this node.
0105    * If the parameter is null, a new copied node is created. Otherwise new node
0106    * is not created, but rather the given one is modified.<p>
0107    * This method nullifies the argument node if its member myScene differs
0108    * from that one of the current instance.
0109    */
0110   Standard_EXPORT virtual Handle(VrmlData_Node)
0111                                 Clone       (const Handle(VrmlData_Node)&)const;
0112 
0113   /**
0114    * Read one boolean value (TRUE or FALSE).
0115    */
0116   Standard_EXPORT static VrmlData_ErrorStatus
0117                                 ReadBoolean (VrmlData_InBuffer& theBuffer,
0118                                              Standard_Boolean&  theResult);
0119 
0120   /**
0121    * Read one quoted string, the quotes are removed.
0122    */
0123   Standard_EXPORT static VrmlData_ErrorStatus
0124                                 ReadString  (VrmlData_InBuffer& theBuffer,
0125                                              TCollection_AsciiString& theRes);
0126 
0127   /**
0128    * Read one quoted string, the quotes are removed.
0129    */
0130   Standard_EXPORT static VrmlData_ErrorStatus
0131                                 ReadMultiString
0132                         (VrmlData_InBuffer& theBuffer,
0133                          NCollection_List<TCollection_AsciiString>& theRes);
0134 
0135   /**
0136    * Read one integer value.
0137    */
0138   Standard_EXPORT static VrmlData_ErrorStatus
0139                                 ReadInteger (VrmlData_InBuffer& theBuffer,
0140                                              long&              theResult);
0141 
0142   static inline Standard_Boolean OK (const VrmlData_ErrorStatus theStat)
0143   { return theStat == VrmlData_StatusOK; }
0144 
0145   static inline Standard_Boolean OK (VrmlData_ErrorStatus&      outStat,
0146                                      const VrmlData_ErrorStatus theStat)
0147   { return (outStat = theStat) == VrmlData_StatusOK; }
0148 
0149   /**
0150    * Define the common Indent in spaces, for writing all nodes.
0151    */ 
0152   static inline Standard_Integer GlobalIndent ()
0153   { return 2; }
0154 
0155  protected:
0156   // ---------- PROTECTED METHODS ----------
0157 
0158   /**
0159    * Constructor
0160    */
0161   Standard_EXPORT VrmlData_Node         (const VrmlData_Scene& theScene,
0162                                          const char            * theName);
0163 
0164   /**
0165    * Read the closing brace. If successful, theBufrfer is incremented.
0166    * If no brace is found, theBuffer stays in untouched and the method returns
0167    * VrmlFormatError.
0168    */
0169   Standard_EXPORT static VrmlData_ErrorStatus
0170                                 readBrace   (VrmlData_InBuffer& theBuffer);
0171 
0172  private:
0173   // ---------- PRIVATE METHODS ----------
0174 
0175   /**
0176    * Method called from VrmlData_Scene when a name should be assigned
0177    * automatically.
0178    */
0179   Standard_EXPORT void          setName (const char * theName,
0180                                          const char * theSuffix = 0L);
0181 
0182  private:
0183   // ---------- PRIVATE FIELDS ----------
0184 
0185   const VrmlData_Scene  * myScene; 
0186   const char            * myName;       ///< name of the node
0187 #ifdef OCCT_DEBUG
0188   Standard_Integer      myLineCount;
0189 #endif
0190 
0191   friend class VrmlData_Group;
0192   friend class VrmlData_Scene;
0193 
0194  public:
0195 // Declaration of CASCADE RTTI
0196   DEFINE_STANDARD_RTTIEXT(VrmlData_Node,Standard_Transient)
0197 };
0198 
0199 // Definition of HANDLE object using Standard_DefineHandle.hxx
0200 DEFINE_STANDARD_HANDLE (VrmlData_Node, Standard_Transient)
0201 
0202 
0203 Standard_EXPORT Standard_Boolean IsEqual(const Handle(VrmlData_Node)& theOne,
0204                                          const Handle(VrmlData_Node)& theTwo);
0205 
0206 namespace std
0207 {
0208   template <>
0209   struct hash<Handle(VrmlData_Node)>
0210   {
0211     size_t operator()(const Handle(VrmlData_Node)& theNode) const
0212     {
0213       if (!theNode->Name())
0214       {
0215         return 1;
0216       }
0217       return Standard_CStringHasher{}(theNode->Name());
0218     }
0219   };
0220 
0221   template<>
0222   struct equal_to<Handle(VrmlData_Node)>
0223   {
0224     bool operator()(const Handle(VrmlData_Node)& theNode1,
0225                     const Handle(VrmlData_Node)& theNode2) const noexcept
0226     {
0227       return IsEqual(theNode1, theNode2);
0228     }
0229   };
0230 }
0231 
0232 #endif