0023373: MSVC++ warnings issued during compilation for 64bits, 'Sparse Arrays'
[occt.git] / src / TObj / TObj_TIntSparseArray.hxx
1 // Created on: 2007-03-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20 // The original implementation Copyright: (C) RINA S.p.A
21
22 #ifndef TObj_TIntSparseArray_HeaderFile
23 #define TObj_TIntSparseArray_HeaderFile
24
25 #include <TObj_Common.hxx>
26
27 #include <NCollection_SparseArray.hxx>
28 #include <TDF_Attribute.hxx>
29 #include <TDF_Label.hxx>
30
31 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
32 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
33
34 class Handle(TObj_TIntSparseArray);
35 class Standard_GUID;
36 class Handle(TDF_RelocationTable);
37
38 /**
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.
42  */
43
44 class TObj_TIntSparseArray : public TDF_Attribute
45 {
46  public:
47
48   //! Empty constructor
49   Standard_EXPORT TObj_TIntSparseArray();
50
51   //! This method is used in implementation of ID()
52   static Standard_EXPORT const Standard_GUID& GetID();
53
54   //! Returns the ID of this attribute.
55   Standard_EXPORT const Standard_GUID& ID() const;
56
57   //! Creates TObj_TIntSparseArray attribute on given label.
58   static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
59                             (const TDF_Label& theLabel);
60
61  public:
62   //! Methods for access to data
63
64   //! Returns the number of stored values in the set
65   Standard_EXPORT Standard_Size Size() const
66   { return myVector.Size(); }
67
68   typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
69
70   //! Returns iterator on objects contained in the set
71   Iterator GetIterator() const { return Iterator(myVector); }
72
73   //! Returns true if the value with the given ID is present.
74   Standard_Boolean HasValue (const Standard_Size theId) const
75   { return myVector.HasValue(theId); }
76
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_Size theId) const
80   { return myVector.Value(theId); }
81
82   //! Sets the value with the given ID.
83   //! Raises an exception if theId is not positive
84   Standard_EXPORT void SetValue (const Standard_Size theId,
85                                  const Standard_Integer theValue);
86
87   //! Unsets the value with the given ID.
88   //! Raises an exception if theId is not positive
89   Standard_EXPORT void UnsetValue(const Standard_Size theId);
90
91   //! Clears the set
92   Standard_EXPORT void Clear ();
93
94  public:
95   //! Redefined OCAF abstract methods
96
97   //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
98   //! copy algorithm.
99   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
100
101   //! Moves this delta into a new other attribute.
102   Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const;
103
104   //! Restores the set using info saved in backup attribute theDelta.
105   Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta);
106
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;
111
112   //! It is called just before Commit or Abort transaction
113   //! and does Backup() to create a delta
114   Standard_EXPORT void BeforeCommitTransaction();
115
116   //! Applies theDelta to this.
117   Standard_EXPORT void DeltaOnModification
118                         (const Handle(TDF_DeltaOnModification)& theDelta);
119
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);
124
125  public:
126   //! Methods to handle the modification delta
127
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; }
132
133   void ClearDelta ()
134   { myOldMap.Clear(); }
135
136  private:
137   //! Internal constant to recognize items in the backup array
138   //! correspondent to absent values
139   enum
140   {
141     AbsentValue = -1
142   };
143
144   //! backup one value
145   void backupValue (const Standard_Size theId,
146                     const Standard_Integer theCurrValue,
147                     const Standard_Integer theNewValue);
148
149   TObj_TIntSparseArray_VecOfData myVector;
150   TObj_TIntSparseArray_MapOfData myOldMap;
151   Standard_Boolean               myDoBackup;
152
153  public:
154   //! CASCADE RTTI
155   DEFINE_STANDARD_RTTI(TObj_TIntSparseArray)
156 };
157
158 //! Define handle class for TObj_TIntSparseArray
159 DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
160
161 #endif
162
163 #ifdef _MSC_VER
164 #pragma once
165 #endif