1 // Created on: 2007-03-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
18 #ifndef TObj_TIntSparseArray_HeaderFile
19 #define TObj_TIntSparseArray_HeaderFile
21 #include <TObj_Common.hxx>
23 #include <NCollection_SparseArray.hxx>
24 #include <TDF_Attribute.hxx>
25 #include <TDF_Label.hxx>
27 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
28 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
33 * OCAF Attribute to store a set of positive integer values in the OCAF tree.
34 * Each value is identified by ID (positive integer).
35 * The supporting underlying data structure is NCollection_SparseArray of integers.
38 class TObj_TIntSparseArray : public TDF_Attribute
43 Standard_EXPORT TObj_TIntSparseArray();
45 //! This method is used in implementation of ID()
46 static Standard_EXPORT const Standard_GUID& GetID();
48 //! Returns the ID of this attribute.
49 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
51 //! Creates TObj_TIntSparseArray attribute on given label.
52 static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
53 (const TDF_Label& theLabel);
56 //! Methods for access to data
58 //! Returns the number of stored values in the set
59 Standard_Size Size() const
60 { return myVector.Size(); }
62 typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
64 //! Returns iterator on objects contained in the set
65 Iterator GetIterator() const { return Iterator(myVector); }
67 //! Returns true if the value with the given ID is present.
68 Standard_Boolean HasValue (const Standard_Size theId) const
69 { return myVector.HasValue(theId); }
71 //! Returns the value by its ID.
72 //! Raises an exception if no value is stored with this ID
73 Standard_Integer Value (const Standard_Size theId) const
74 { return myVector.Value(theId); }
76 //! Sets the value with the given ID.
77 //! Raises an exception if theId is not positive
78 Standard_EXPORT void SetValue (const Standard_Size theId,
79 const Standard_Integer theValue);
81 //! Unsets the value with the given ID.
82 //! Raises an exception if theId is not positive
83 Standard_EXPORT void UnsetValue(const Standard_Size theId);
86 Standard_EXPORT void Clear ();
89 //! Redefined OCAF abstract methods
91 //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
93 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
95 //! Moves this delta into a new other attribute.
96 Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const Standard_OVERRIDE;
98 //! Restores the set using info saved in backup attribute theDelta.
99 Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta) Standard_OVERRIDE;
101 //! This method is used when copying an attribute from a source structure
102 //! into a target structure.
103 Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
104 const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
106 //! It is called just before Commit or Abort transaction
107 //! and does Backup() to create a delta
108 Standard_EXPORT void BeforeCommitTransaction() Standard_OVERRIDE;
110 //! Applies theDelta to this.
111 Standard_EXPORT void DeltaOnModification
112 (const Handle(TDF_DeltaOnModification)& theDelta) Standard_OVERRIDE;
114 //! Clears my modification delta; called after application of theDelta
115 Standard_EXPORT Standard_Boolean AfterUndo
116 (const Handle(TDF_AttributeDelta)& theDelta,
117 const Standard_Boolean toForce) Standard_OVERRIDE;
120 //! Methods to handle the modification delta
122 //! Sets the flag pointing to the necessity to maintain a modification delta.
123 //! It is called by the retrieval driver
124 void SetDoBackup (const Standard_Boolean toDo)
125 { myDoBackup = toDo; }
128 { myOldMap.Clear(); }
131 //! Internal constant to recognize items in the backup array
132 //! correspondent to absent values
139 void backupValue (const Standard_Size theId,
140 const Standard_Integer theCurrValue,
141 const Standard_Integer theNewValue);
143 TObj_TIntSparseArray_VecOfData myVector;
144 TObj_TIntSparseArray_MapOfData myOldMap;
145 Standard_Boolean myDoBackup;
149 DEFINE_STANDARD_RTTIEXT(TObj_TIntSparseArray,TDF_Attribute)
152 //! Define handle class for TObj_TIntSparseArray
153 DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)