42cf5bc1 |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _TDF_Data_HeaderFile |
17 | #define _TDF_Data_HeaderFile |
18 | |
19 | #include <Standard.hxx> |
20 | #include <Standard_Type.hxx> |
21 | |
22 | #include <TDF_LabelNodePtr.hxx> |
23 | #include <Standard_Integer.hxx> |
24 | #include <Standard_Boolean.hxx> |
25 | #include <TColStd_ListOfInteger.hxx> |
26 | #include <TDF_HAllocator.hxx> |
27 | #include <MMgt_TShared.hxx> |
28 | #include <TDF_Label.hxx> |
29 | #include <Standard_OStream.hxx> |
30 | class Standard_NoMoreObject; |
31 | class TDF_Transaction; |
32 | class TDF_LabelNode; |
33 | class TDF_Delta; |
34 | class TDF_Label; |
35 | |
36 | |
37 | class TDF_Data; |
38 | DEFINE_STANDARD_HANDLE(TDF_Data, MMgt_TShared) |
39 | |
40 | //! This class is used to manipulate a complete |
41 | //! independant, self sufficient data structure and |
42 | //! its services: |
43 | //! |
44 | //! Access to the root label; |
45 | //! |
46 | //! Opens, aborts, commits a transaction; |
47 | //! |
48 | //! Generation and use of Delta, depending on the time. |
49 | //! This class uses a special allocator |
50 | //! (see LabelNodeAllocator() method) |
51 | //! for more efficient allocation of |
52 | //! objects in memory. |
53 | class TDF_Data : public MMgt_TShared |
54 | { |
55 | |
56 | public: |
57 | |
58 | |
59 | //! A new and empty Data structure. |
60 | Standard_EXPORT TDF_Data(); |
61 | |
62 | //! Returns the root label of the Data structure. |
63 | const TDF_Label Root() const; |
64 | |
65 | //! Returns the current transaction number. |
66 | Standard_EXPORT Standard_Integer Transaction() const; |
67 | |
68 | //! Returns the current tick. It is incremented each Commit. |
69 | Standard_Integer Time() const; |
70 | |
71 | //! Returns true if <aDelta> is applicable HERE and NOW. |
72 | Standard_EXPORT Standard_Boolean IsApplicable (const Handle(TDF_Delta)& aDelta) const; |
73 | |
74 | //! Apply <aDelta> to undo a set of attribute |
75 | //! modifications. |
76 | //! |
77 | //! Optionnal <withDelta> set to True indiquates a |
78 | //! Delta Set must be generated. (See above) |
79 | Standard_EXPORT Handle(TDF_Delta) Undo (const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta = Standard_False); |
80 | |
81 | Standard_EXPORT void Destroy(); |
82 | ~TDF_Data() |
83 | { |
84 | Destroy(); |
85 | } |
86 | |
87 | //! Returns the undo mode status. |
88 | Standard_Boolean NotUndoMode() const; |
89 | |
90 | //! Dumps the Data on <aStream>. |
91 | Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const; |
92 | Standard_OStream& operator<< (Standard_OStream& anOS) const |
93 | { |
94 | return Dump(anOS); |
95 | } |
96 | |
97 | //! Sets modification mode. |
98 | void AllowModification (const Standard_Boolean isAllowed); |
99 | |
100 | //! returns modification mode. |
101 | Standard_Boolean IsModificationAllowed() const; |
102 | |
103 | //! Returns TDF_HAllocator, which is an |
104 | //! incremental allocator used by |
105 | //! TDF_LabelNode. |
106 | //! This allocator is used to |
107 | //! manage TDF_LabelNode objects, |
108 | //! but it can also be used for |
109 | //! allocating memory to |
110 | //! application-specific data (be |
111 | //! careful because this |
112 | //! allocator does not release |
113 | //! the memory). |
114 | //! The benefits of this |
115 | //! allocation scheme are |
116 | //! noticeable when dealing with |
117 | //! large OCAF documents, due to: |
118 | //! 1. Very quick allocation of |
119 | //! objects (memory heap is not |
120 | //! used, the algorithm that |
121 | //! replaces it is very simple). |
122 | //! 2. Very quick destruction of |
123 | //! objects (memory is released not |
124 | //! by destructors of TDF_LabelNode, |
125 | //! but rather by the destructor of |
126 | //! TDF_Data). |
127 | //! 3. TDF_LabelNode objects do not |
128 | //! fragmentize the memory; they are |
129 | //! kept compactly in a number of |
130 | //! arrays of 16K each. |
131 | //! 4. Swapping is reduced on large |
132 | //! data, because each document now |
133 | //! occupies a smaller number of |
134 | //! memory pages. |
135 | const TDF_HAllocator& LabelNodeAllocator() const; |
136 | |
137 | friend class TDF_Transaction; |
138 | friend class TDF_LabelNode; |
139 | |
140 | |
141 | DEFINE_STANDARD_RTTI(TDF_Data,MMgt_TShared) |
142 | |
143 | protected: |
144 | |
145 | |
146 | |
147 | |
148 | private: |
149 | |
150 | |
151 | //! Increments the transaction number and returns it. |
152 | Standard_EXPORT Standard_Integer OpenTransaction(); |
153 | |
154 | //! Decrements the transaction number and commits the |
155 | //! modifications. |
156 | //! |
157 | //! Raises if there is no current transaction. |
158 | //! |
159 | //! Optionnal <withDelta> set to True indiquates a |
160 | //! Delta must be generated. |
161 | Standard_EXPORT Handle(TDF_Delta) CommitTransaction (const Standard_Boolean withDelta = Standard_False); |
162 | |
163 | //! Decrements the transaction number and commits the |
164 | //! modifications until AND including the transaction |
165 | //! <untilTransaction>. |
166 | Standard_EXPORT Handle(TDF_Delta) CommitUntilTransaction (const Standard_Integer untilTransaction, const Standard_Boolean withDelta = Standard_False); |
167 | |
168 | //! Decrements the transaction number and forgets the |
169 | //! modifications. |
170 | //! |
171 | //! Raises if there is no current transaction. |
172 | Standard_EXPORT void AbortTransaction(); |
173 | |
174 | //! Decrements the transaction number and forgets the |
175 | //! modifications until AND including the transaction |
176 | //! <untilTransaction>. |
177 | Standard_EXPORT void AbortUntilTransaction (const Standard_Integer untilTransaction); |
178 | |
179 | //! Decrements the transaction number and commits the |
180 | //! modifications. Used to implement the recursif |
181 | //! commit process. The returned boolean says how many |
182 | //! attributes (new, modified or deleted) has been |
183 | //! committed from the previous transaction into the |
184 | //! current one. |
185 | Standard_EXPORT Standard_Integer CommitTransaction (const TDF_Label& aLabel, const Handle(TDF_Delta)& aDelta, const Standard_Boolean withDelta); |
186 | |
187 | TDF_LabelNodePtr myRoot; |
188 | Standard_Integer myTransaction; |
189 | Standard_Integer myNbTouchedAtt; |
190 | Standard_Boolean myNotUndoMode; |
191 | Standard_Integer myTime; |
192 | TColStd_ListOfInteger myTimes; |
193 | TDF_HAllocator myLabelNodeAllocator; |
194 | Standard_Boolean myAllowModification; |
195 | |
196 | |
197 | }; |
198 | |
199 | |
200 | #include <TDF_Data.lxx> |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | #endif // _TDF_Data_HeaderFile |