0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TObj / TObj_TIntSparseArray.hxx
CommitLineData
b311480e 1// Created on: 2007-03-16
2// Created by: Michael SAZONOV
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#ifndef TObj_TIntSparseArray_HeaderFile
19#define TObj_TIntSparseArray_HeaderFile
20
21#include <TObj_Common.hxx>
22
23#include <NCollection_SparseArray.hxx>
24#include <TDF_Attribute.hxx>
25#include <TDF_Label.hxx>
26
27typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
28typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
29
7fd59977 30class Standard_GUID;
7fd59977 31
32/**
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.
36 */
37
38class TObj_TIntSparseArray : public TDF_Attribute
39{
40 public:
41
42 //! Empty constructor
43 Standard_EXPORT TObj_TIntSparseArray();
44
45 //! This method is used in implementation of ID()
46 static Standard_EXPORT const Standard_GUID& GetID();
47
48 //! Returns the ID of this attribute.
79104795 49 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
7fd59977 50
51 //! Creates TObj_TIntSparseArray attribute on given label.
52 static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
53 (const TDF_Label& theLabel);
54
55 public:
56 //! Methods for access to data
57
58 //! Returns the number of stored values in the set
0f57ab75 59 Standard_Size Size() const
7fd59977 60 { return myVector.Size(); }
61
62 typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
63
64 //! Returns iterator on objects contained in the set
65 Iterator GetIterator() const { return Iterator(myVector); }
66
67 //! Returns true if the value with the given ID is present.
d93f7683 68 Standard_Boolean HasValue (const Standard_Size theId) const
7fd59977 69 { return myVector.HasValue(theId); }
70
71 //! Returns the value by its ID.
72 //! Raises an exception if no value is stored with this ID
d93f7683 73 Standard_Integer Value (const Standard_Size theId) const
7fd59977 74 { return myVector.Value(theId); }
75
76 //! Sets the value with the given ID.
77 //! Raises an exception if theId is not positive
d93f7683 78 Standard_EXPORT void SetValue (const Standard_Size theId,
7fd59977 79 const Standard_Integer theValue);
80
81 //! Unsets the value with the given ID.
82 //! Raises an exception if theId is not positive
d93f7683 83 Standard_EXPORT void UnsetValue(const Standard_Size theId);
7fd59977 84
85 //! Clears the set
86 Standard_EXPORT void Clear ();
87
88 public:
89 //! Redefined OCAF abstract methods
90
91 //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
92 //! copy algorithm.
79104795 93 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
7fd59977 94
95 //! Moves this delta into a new other attribute.
79104795 96 Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const Standard_OVERRIDE;
7fd59977 97
98 //! Restores the set using info saved in backup attribute theDelta.
79104795 99 Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta) Standard_OVERRIDE;
7fd59977 100
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,
79104795 104 const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
7fd59977 105
106 //! It is called just before Commit or Abort transaction
107 //! and does Backup() to create a delta
79104795 108 Standard_EXPORT void BeforeCommitTransaction() Standard_OVERRIDE;
7fd59977 109
110 //! Applies theDelta to this.
111 Standard_EXPORT void DeltaOnModification
79104795 112 (const Handle(TDF_DeltaOnModification)& theDelta) Standard_OVERRIDE;
7fd59977 113
114 //! Clears my modification delta; called after application of theDelta
115 Standard_EXPORT Standard_Boolean AfterUndo
116 (const Handle(TDF_AttributeDelta)& theDelta,
79104795 117 const Standard_Boolean toForce) Standard_OVERRIDE;
7fd59977 118
119 public:
120 //! Methods to handle the modification delta
121
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; }
126
127 void ClearDelta ()
128 { myOldMap.Clear(); }
129
130 private:
131 //! Internal constant to recognize items in the backup array
132 //! correspondent to absent values
133 enum
134 {
135 AbsentValue = -1
136 };
137
138 //! backup one value
d93f7683 139 void backupValue (const Standard_Size theId,
7fd59977 140 const Standard_Integer theCurrValue,
141 const Standard_Integer theNewValue);
142
143 TObj_TIntSparseArray_VecOfData myVector;
144 TObj_TIntSparseArray_MapOfData myOldMap;
145 Standard_Boolean myDoBackup;
146
147 public:
148 //! CASCADE RTTI
92efcf78 149 DEFINE_STANDARD_RTTIEXT(TObj_TIntSparseArray,TDF_Attribute)
7fd59977 150};
151
152//! Define handle class for TObj_TIntSparseArray
153DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
154
155#endif
156
157#ifdef _MSC_VER
158#pragma once
159#endif