Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2007-05-29
0002 // Created by: Vlad Romashko
0003 // Copyright (c) 2007-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 _TDataStd_NamedData_HeaderFile
0017 #define _TDataStd_NamedData_HeaderFile
0018 
0019 #include <TDF_Attribute.hxx>
0020 #include <TColStd_DataMapOfStringInteger.hxx>
0021 #include <TDataStd_DataMapOfStringReal.hxx>
0022 #include <TDataStd_DataMapOfStringString.hxx>
0023 #include <TDataStd_DataMapOfStringByte.hxx>
0024 #include <TDataStd_DataMapOfStringHArray1OfInteger.hxx>
0025 #include <TDataStd_DataMapOfStringHArray1OfReal.hxx>
0026 
0027 class TDataStd_HDataMapOfStringInteger;
0028 class TDataStd_HDataMapOfStringReal;
0029 class TDataStd_HDataMapOfStringString;
0030 class TDataStd_HDataMapOfStringByte;
0031 class TDataStd_HDataMapOfStringHArray1OfInteger;
0032 class TDataStd_HDataMapOfStringHArray1OfReal;
0033 class TCollection_ExtendedString;
0034 
0035 class TDataStd_NamedData;
0036 DEFINE_STANDARD_HANDLE(TDataStd_NamedData, TDF_Attribute)
0037 
0038 //! Contains a named data.
0039 class TDataStd_NamedData : public TDF_Attribute
0040 {
0041 public:
0042 
0043   //! Returns the ID of the named data attribute.
0044   Standard_EXPORT static const Standard_GUID& GetID();
0045 
0046   //! Finds or creates a named data attribute.
0047   Standard_EXPORT static Handle(TDataStd_NamedData) Set (const TDF_Label& label);
0048 
0049 public:
0050 
0051   //! Empty constructor.
0052   Standard_EXPORT TDataStd_NamedData();
0053 
0054   //! Returns true if at least one named integer value is kept in the attribute.
0055   Standard_EXPORT Standard_Boolean HasIntegers() const;
0056 
0057   //! Returns true if the attribute contains specified by Name
0058   //! integer value.
0059   Standard_EXPORT Standard_Boolean HasInteger (const TCollection_ExtendedString& theName) const;
0060 
0061   //! Returns the integer value specified by the Name.
0062   //! It returns 0 if internal map doesn't contain the specified
0063   //! integer (use HasInteger() to check before).
0064   Standard_EXPORT Standard_Integer GetInteger (const TCollection_ExtendedString& theName);
0065 
0066   //! Defines a named integer.
0067   //! If the integer already exists, it changes its value to <theInteger>.
0068   Standard_EXPORT void SetInteger (const TCollection_ExtendedString& theName, const Standard_Integer theInteger);
0069 
0070   //! Returns the internal container of named integers.
0071   Standard_EXPORT const TColStd_DataMapOfStringInteger& GetIntegersContainer();
0072 
0073   //! Replace the container content by new content of the <theIntegers>.
0074   Standard_EXPORT void ChangeIntegers (const TColStd_DataMapOfStringInteger& theIntegers);
0075 
0076   //! Returns true if at least one named real value is kept in the attribute.
0077   Standard_EXPORT Standard_Boolean HasReals() const;
0078 
0079   //! Returns true if the attribute contains a real specified by Name.
0080   Standard_EXPORT Standard_Boolean HasReal (const TCollection_ExtendedString& theName) const;
0081 
0082   //! Returns the named real.
0083   //! It returns 0.0 if there is no such a named real
0084   //! (use HasReal()).
0085   Standard_EXPORT Standard_Real GetReal (const TCollection_ExtendedString& theName);
0086 
0087   //! Defines a named real.
0088   //! If the real already exists, it changes its value to <theReal>.
0089   Standard_EXPORT void SetReal (const TCollection_ExtendedString& theName, const Standard_Real theReal);
0090 
0091   //! Returns the internal container of named reals.
0092   Standard_EXPORT const TDataStd_DataMapOfStringReal& GetRealsContainer();
0093 
0094   //! Replace the container content by new content of the <theReals>.
0095   Standard_EXPORT void ChangeReals (const TDataStd_DataMapOfStringReal& theReals);
0096 
0097   //! Returns true if there are some named strings in the attribute.
0098   Standard_EXPORT Standard_Boolean HasStrings() const;
0099 
0100   //! Returns true if the attribute contains this named string.
0101   Standard_EXPORT Standard_Boolean HasString (const TCollection_ExtendedString& theName) const;
0102 
0103   //! Returns the named string.
0104   //! It returns an empty string if there is no such a named string
0105   //! (use HasString()).
0106   Standard_EXPORT const TCollection_ExtendedString& GetString (const TCollection_ExtendedString& theName);
0107 
0108   //! Defines a named string.
0109   //! If the string already exists, it changes its value to <theString>.
0110   Standard_EXPORT void SetString (const TCollection_ExtendedString& theName, const TCollection_ExtendedString& theString);
0111 
0112   //! Returns the internal container of named strings.
0113   Standard_EXPORT const TDataStd_DataMapOfStringString& GetStringsContainer();
0114 
0115   //! Replace the container content by new content of the <theStrings>.
0116   Standard_EXPORT void ChangeStrings (const TDataStd_DataMapOfStringString& theStrings);
0117 
0118   //! Returns true if there are some named bytes in the attribute.
0119   Standard_EXPORT Standard_Boolean HasBytes() const;
0120 
0121   //! Returns true if the attribute contains this named byte.
0122   Standard_EXPORT Standard_Boolean HasByte (const TCollection_ExtendedString& theName) const;
0123 
0124   //! Returns the named byte.
0125   //! It returns 0 if there is no such a named byte
0126   //! (use HasByte()).
0127   Standard_EXPORT Standard_Byte GetByte (const TCollection_ExtendedString& theName);
0128 
0129   //! Defines a named byte.
0130   //! If the byte already exists, it changes its value to <theByte>.
0131   Standard_EXPORT void SetByte (const TCollection_ExtendedString& theName, const Standard_Byte theByte);
0132 
0133   //! Returns the internal container of named bytes.
0134   Standard_EXPORT const TDataStd_DataMapOfStringByte& GetBytesContainer();
0135 
0136   //! Replace the container content by new content of the <theBytes>.
0137   Standard_EXPORT void ChangeBytes (const TDataStd_DataMapOfStringByte& theBytes);
0138 
0139   //! Returns true if there are some named arrays of integer values in the attribute.
0140   Standard_EXPORT Standard_Boolean HasArraysOfIntegers() const;
0141 
0142   //! Returns true if the attribute contains this named array of integer values.
0143   Standard_EXPORT Standard_Boolean HasArrayOfIntegers (const TCollection_ExtendedString& theName) const;
0144 
0145   //! Returns the named array of integer values.
0146   //! It returns a NULL Handle if there is no such a named array of integers
0147   //! (use HasArrayOfIntegers()).
0148   Standard_EXPORT const Handle(TColStd_HArray1OfInteger)& GetArrayOfIntegers (const TCollection_ExtendedString& theName);
0149 
0150   //! Defines a named array of integer values.
0151   //! @param theName [in] key
0152   //! @param theArrayOfIntegers [in] new value, overrides existing (passed array will be copied by value!)
0153   void SetArrayOfIntegers (const TCollection_ExtendedString& theName,
0154                            const Handle(TColStd_HArray1OfInteger)& theArrayOfIntegers)
0155   {
0156     Backup();
0157     setArrayOfIntegers (theName, theArrayOfIntegers);
0158   }
0159 
0160   //! Returns the internal container of named arrays of integer values.
0161   Standard_EXPORT const TDataStd_DataMapOfStringHArray1OfInteger& GetArraysOfIntegersContainer();
0162 
0163   //! Replace the container content by new content of the <theArraysOfIntegers>.
0164   Standard_EXPORT void ChangeArraysOfIntegers (const TDataStd_DataMapOfStringHArray1OfInteger& theArraysOfIntegers);
0165 
0166   //! Returns true if there are some named arrays of real values in the attribute.
0167   Standard_EXPORT Standard_Boolean HasArraysOfReals() const;
0168 
0169   //! Returns true if the attribute contains this named array of real values.
0170   Standard_EXPORT Standard_Boolean HasArrayOfReals (const TCollection_ExtendedString& theName) const;
0171 
0172   //! Returns the named array of real values.
0173   //! It returns a NULL Handle if there is no such a named array of reals
0174   //! (use HasArrayOfReals()).
0175   Standard_EXPORT const Handle(TColStd_HArray1OfReal)& GetArrayOfReals (const TCollection_ExtendedString& theName);
0176 
0177   //! Defines a named array of real values.
0178   //! @param[in] theName key
0179   //! @param[in] theArrayOfReals new value, overrides existing (passed array will be copied by value!)
0180   void SetArrayOfReals (const TCollection_ExtendedString& theName,
0181                         const Handle(TColStd_HArray1OfReal)& theArrayOfReals)
0182   {
0183     Backup();
0184     setArrayOfReals (theName, theArrayOfReals);
0185   }
0186 
0187   //! Returns the internal container of named arrays of real values.
0188   Standard_EXPORT const TDataStd_DataMapOfStringHArray1OfReal& GetArraysOfRealsContainer();
0189 
0190   //! Replace the container content by new content of the <theArraysOfReals>.
0191   Standard_EXPORT void ChangeArraysOfReals (const TDataStd_DataMapOfStringHArray1OfReal& theArraysOfReals);
0192 
0193   //! Clear data.
0194   void Clear()
0195   {
0196     Backup();
0197     clear();
0198   }
0199 
0200 public: //! @name late-load deferred data interface
0201 
0202   //! Returns TRUE if some data is not loaded from deferred storage and can be loaded using LoadDeferredData().
0203   //!
0204   //! Late-load interface allows to avoid loading auxiliary data into memory until it is needed by application
0205   //! and also speed up reader by skipping data chunks in file.
0206   //! This feature requires file format having special structure, and usually implies read-only access,
0207   //! therefore default implementation will return FALSE here.
0208   //!
0209   //! Late-load elements require special attention to ensure data consistency,
0210   //! as such elements are created in undefined state (no data) and Undo/Redo mechanism will not work until deferred data being loaded.
0211   //!
0212   //! Usage scenarios:
0213   //! - Application displays model in read-only way.
0214   //!   Late-load elements are loaded temporarily on demand and immediately unloaded.
0215   //!     theNamedData->LoadDeferredData (true);
0216   //!     TCollection_AsciiString aValue = theNamedData->GetString (theKey);
0217   //!     theNamedData->UnloadDeferredData();
0218   //! - Application saves the model into another format.
0219   //!   All late-load elements should be loaded (at least temporary during operation).
0220   //! - Application modifies the model.
0221   //!   Late-load element should be loaded with removed link to deferred storage,
0222   //!   so that Undo()/Redo() will work as expected since loading.
0223   //!     theNamedData->LoadDeferredData (false);
0224   //!     theNamedData->SetString (theKey, theNewValue);
0225   virtual Standard_Boolean HasDeferredData() const { return false; }
0226 
0227   //! Load data from deferred storage, without calling Backup().
0228   //! As result, the content of the object will be overridden by data from deferred storage (which is normally read-only).
0229   //! @param theToKeepDeferred [in] when TRUE, the link to deferred storage will be preserved
0230   //!                               so that it will be possible calling UnloadDeferredData() afterwards for releasing memory
0231   //! @return FALSE if deferred storage is unavailable or deferred data has been already loaded
0232   virtual Standard_Boolean LoadDeferredData (Standard_Boolean theToKeepDeferred = false)
0233   {
0234     (void )theToKeepDeferred;
0235     return false;
0236   }
0237 
0238   //! Releases data if object has connected deferred storage, without calling Backup().
0239   //! WARNING! This operation does not unload modifications to deferred storage (normally it is read-only),
0240   //! so that modifications will be discarded (if any).
0241   //! @return FALSE if object has no deferred data
0242   virtual Standard_Boolean UnloadDeferredData() { return false; }
0243 
0244 public:
0245 
0246   //! Clear data without calling Backup().
0247   Standard_EXPORT void clear();
0248 
0249   //! Defines a named integer (without calling Backup).
0250   Standard_EXPORT void setInteger (const TCollection_ExtendedString& theName,
0251                                    const Standard_Integer theInteger);
0252 
0253   //! Defines a named real (without calling Backup).
0254   Standard_EXPORT void setReal (const TCollection_ExtendedString& theName,
0255                                 const Standard_Real theReal);
0256 
0257   //! Defines a named string (without calling Backup).
0258   Standard_EXPORT void setString (const TCollection_ExtendedString& theName,
0259                                   const TCollection_ExtendedString& theString);
0260 
0261   //! Defines a named byte (without calling Backup).
0262   Standard_EXPORT void setByte (const TCollection_ExtendedString& theName,
0263                                 const Standard_Byte theByte);
0264 
0265   //! Defines a named array of integer values (without calling Backup).
0266   Standard_EXPORT void setArrayOfIntegers (const TCollection_ExtendedString& theName,
0267                                            const Handle(TColStd_HArray1OfInteger)& theArrayOfIntegers);
0268 
0269   //! Defines a named array of real values (without calling Backup).
0270   Standard_EXPORT void setArrayOfReals (const TCollection_ExtendedString& theName,
0271                                         const Handle(TColStd_HArray1OfReal)& theArrayOfReals);
0272 
0273 public: //! @name TDF_Attribute interface
0274 
0275   Standard_EXPORT virtual const Standard_GUID& ID() const Standard_OVERRIDE;
0276 
0277   Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
0278 
0279   Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
0280 
0281   Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
0282 
0283   Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
0284 
0285   //! Dumps the content of me into the stream
0286   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0287 
0288   DEFINE_STANDARD_RTTIEXT(TDataStd_NamedData,TDF_Attribute)
0289 
0290 protected:
0291 
0292   Handle(TDataStd_HDataMapOfStringInteger) myIntegers;
0293   Handle(TDataStd_HDataMapOfStringReal) myReals;
0294   Handle(TDataStd_HDataMapOfStringString) myStrings;
0295   Handle(TDataStd_HDataMapOfStringByte) myBytes;
0296   Handle(TDataStd_HDataMapOfStringHArray1OfInteger) myArraysOfIntegers;
0297   Handle(TDataStd_HDataMapOfStringHArray1OfReal) myArraysOfReals;
0298 
0299 };
0300 
0301 #endif // _TDataStd_NamedData_HeaderFile