Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 09:05:02

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