Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:18:12

0001 // Created on: 2007-03-16
0002 // Created by: Michael SAZONOV
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 // The original implementation Copyright: (C) RINA S.p.A
0017 
0018 #ifndef TObj_TIntSparseArray_HeaderFile
0019 #define TObj_TIntSparseArray_HeaderFile
0020 
0021 #include <NCollection_SparseArray.hxx>
0022 #include <TDF_Label.hxx>
0023 
0024 class Standard_GUID;
0025 
0026 /**
0027  * OCAF Attribute to store a set of positive integer values in the OCAF tree.
0028  * Each value is identified by ID (positive integer).
0029  * The supporting underlying data structure is NCollection_SparseArray of integers.
0030  */
0031 
0032 class TObj_TIntSparseArray : public TDF_Attribute
0033 {
0034 public:
0035   //! Empty constructor
0036   Standard_EXPORT TObj_TIntSparseArray();
0037 
0038   //! This method is used in implementation of ID()
0039   static Standard_EXPORT const Standard_GUID& GetID();
0040 
0041   //! Returns the ID of this attribute.
0042   Standard_EXPORT const Standard_GUID& ID() const override;
0043 
0044   //! Creates TObj_TIntSparseArray attribute on given label.
0045   static Standard_EXPORT occ::handle<TObj_TIntSparseArray> Set(const TDF_Label& theLabel);
0046 
0047 public:
0048   //! Methods for access to data
0049 
0050   //! Returns the number of stored values in the set
0051   size_t Size() const { return myVector.Size(); }
0052 
0053   typedef NCollection_SparseArray<int>::ConstIterator Iterator;
0054 
0055   //! Returns iterator on objects contained in the set
0056   Iterator GetIterator() const { return Iterator(myVector); }
0057 
0058   //! Returns true if the value with the given ID is present.
0059   bool HasValue(const size_t theId) const { return myVector.HasValue(theId); }
0060 
0061   //! Returns the value by its ID.
0062   //! Raises an exception if no value is stored with this ID
0063   int Value(const size_t theId) const { return myVector.Value(theId); }
0064 
0065   //! Sets the value with the given ID.
0066   //! Raises an exception if theId is not positive
0067   Standard_EXPORT void SetValue(const size_t theId, const int theValue);
0068 
0069   //! Unsets the value with the given ID.
0070   //! Raises an exception if theId is not positive
0071   Standard_EXPORT void UnsetValue(const size_t theId);
0072 
0073   //! Clears the set
0074   Standard_EXPORT void Clear();
0075 
0076 public:
0077   //! Redefined OCAF abstract methods
0078 
0079   //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
0080   //! copy algorithm.
0081   Standard_EXPORT occ::handle<TDF_Attribute> NewEmpty() const override;
0082 
0083   //! Moves this delta into a new other attribute.
0084   Standard_EXPORT occ::handle<TDF_Attribute> BackupCopy() const override;
0085 
0086   //! Restores the set using info saved in backup attribute theDelta.
0087   Standard_EXPORT void Restore(const occ::handle<TDF_Attribute>& theDelta) override;
0088 
0089   //! This method is used when copying an attribute from a source structure
0090   //! into a target structure.
0091   Standard_EXPORT void Paste(const occ::handle<TDF_Attribute>&       theInto,
0092                              const occ::handle<TDF_RelocationTable>& theRT) const override;
0093 
0094   //! It is called just before Commit or Abort transaction
0095   //! and does Backup() to create a delta
0096   Standard_EXPORT void BeforeCommitTransaction() override;
0097 
0098   //! Applies theDelta to this.
0099   Standard_EXPORT void DeltaOnModification(
0100     const occ::handle<TDF_DeltaOnModification>& theDelta) override;
0101 
0102   //! Clears my modification delta; called after application of theDelta
0103   Standard_EXPORT bool AfterUndo(const occ::handle<TDF_AttributeDelta>& theDelta,
0104                                  const bool                             toForce) override;
0105 
0106 public:
0107   //! Methods to handle the modification delta
0108 
0109   //! Sets the flag pointing to the necessity to maintain a modification delta.
0110   //! It is called by the retrieval driver
0111   void SetDoBackup(const bool toDo) { myDoBackup = toDo; }
0112 
0113   void ClearDelta() { myOldMap.Clear(); }
0114 
0115 private:
0116   //! Internal constant to recognize items in the backup array
0117   //! correspondent to absent values
0118   enum
0119   {
0120     AbsentValue = -1
0121   };
0122 
0123   //! backup one value
0124   void backupValue(const size_t theId, const int theCurrValue, const int theNewValue);
0125 
0126   NCollection_SparseArray<int> myVector;
0127   NCollection_SparseArray<int> myOldMap;
0128   bool                         myDoBackup;
0129 
0130 public:
0131   //! CASCADE RTTI
0132   DEFINE_STANDARD_RTTIEXT(TObj_TIntSparseArray, TDF_Attribute)
0133 };
0134 
0135 //! Define handle class for TObj_TIntSparseArray
0136 #endif
0137 
0138 #ifdef _MSC_VER
0139 #pragma once
0140 #endif