1 // Created on: 2007-03-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // The original implementation Copyright: (C) RINA S.p.A
22 #ifndef TObj_TIntSparseArray_HeaderFile
23 #define TObj_TIntSparseArray_HeaderFile
25 #include <TObj_Common.hxx>
27 #include <NCollection_SparseArray.hxx>
28 #include <TDF_Attribute.hxx>
29 #include <TDF_Label.hxx>
31 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
32 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
34 class Handle(TObj_TIntSparseArray);
36 class Handle(TDF_RelocationTable);
39 * OCAF Attribute to store a set of positive integer values in the OCAF tree.
40 * Each value is identified by ID (positive integer).
41 * The supporting underlying data structure is NCollection_SparseArray of integers.
44 class TObj_TIntSparseArray : public TDF_Attribute
49 Standard_EXPORT TObj_TIntSparseArray();
51 //! This method is used in implementation of ID()
52 static Standard_EXPORT const Standard_GUID& GetID();
54 //! Returns the ID of this attribute.
55 Standard_EXPORT const Standard_GUID& ID() const;
57 //! Creates TObj_TIntSparseArray attribute on given label.
58 static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
59 (const TDF_Label& theLabel);
62 //! Methods for access to data
64 //! Returns the number of stored values in the set
65 Standard_EXPORT Standard_Integer Size() const
66 { return myVector.Size(); }
68 typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
70 //! Returns iterator on objects contained in the set
71 Iterator GetIterator() const { return Iterator(myVector); }
73 //! Returns true if the value with the given ID is present.
74 Standard_Boolean HasValue (const Standard_Integer theId) const
75 { return myVector.HasValue(theId); }
77 //! Returns the value by its ID.
78 //! Raises an exception if no value is stored with this ID
79 Standard_Integer Value (const Standard_Integer theId) const
80 { return myVector.Value(theId); }
82 //! Sets the value with the given ID.
83 //! Raises an exception if theId is not positive
84 Standard_EXPORT void SetValue (const Standard_Integer theId,
85 const Standard_Integer theValue);
87 //! Unsets the value with the given ID.
88 //! Raises an exception if theId is not positive
89 Standard_EXPORT void UnsetValue(const Standard_Integer theId);
92 Standard_EXPORT void Clear ();
95 //! Redefined OCAF abstract methods
97 //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
99 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
101 //! Moves this delta into a new other attribute.
102 Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const;
104 //! Restores the set using info saved in backup attribute theDelta.
105 Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta);
107 //! This method is used when copying an attribute from a source structure
108 //! into a target structure.
109 Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
110 const Handle(TDF_RelocationTable)& theRT) const;
112 //! It is called just before Commit or Abort transaction
113 //! and does Backup() to create a delta
114 Standard_EXPORT void BeforeCommitTransaction();
116 //! Applies theDelta to this.
117 Standard_EXPORT void DeltaOnModification
118 (const Handle(TDF_DeltaOnModification)& theDelta);
120 //! Clears my modification delta; called after application of theDelta
121 Standard_EXPORT Standard_Boolean AfterUndo
122 (const Handle(TDF_AttributeDelta)& theDelta,
123 const Standard_Boolean toForce);
126 //! Methods to handle the modification delta
128 //! Sets the flag pointing to the necessity to maintain a modification delta.
129 //! It is called by the retrieval driver
130 void SetDoBackup (const Standard_Boolean toDo)
131 { myDoBackup = toDo; }
134 { myOldMap.Clear(); }
137 //! Internal constant to recognize items in the backup array
138 //! correspondent to absent values
145 void backupValue (const Standard_Integer theId,
146 const Standard_Integer theCurrValue,
147 const Standard_Integer theNewValue);
149 TObj_TIntSparseArray_VecOfData myVector;
150 TObj_TIntSparseArray_MapOfData myOldMap;
151 Standard_Boolean myDoBackup;
155 DEFINE_STANDARD_RTTI(TObj_TIntSparseArray)
158 //! Define handle class for TObj_TIntSparseArray
159 DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)