42cf5bc1 |
1 | // Created on: 1995-05-12 |
2 | // Created by: Christian CAILLET |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Interface_IntList_HeaderFile |
18 | #define _Interface_IntList_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <Standard_Integer.hxx> |
25 | #include <TColStd_HArray1OfInteger.hxx> |
26 | #include <Standard_Boolean.hxx> |
27 | |
28 | |
29 | //! This class detains the data which describe a Graph. A Graph |
30 | //! has two lists, one for shared refs, one for sharing refs |
31 | //! (the reverses). Each list comprises, for each Entity of the |
32 | //! Model of the Graph, a list of Entities (shared or sharing). |
33 | //! In fact, entities are identified by their numbers in the Model |
34 | //! or Graph : this gives better performances. |
35 | //! |
36 | //! A simple way to implement this is to instantiate a HArray1 |
37 | //! with a HSequenceOfInteger : each Entity Number designates a |
38 | //! value, which is a Sequence (if it is null, it is considered as |
39 | //! empty : this is a little optimisation). |
40 | //! |
41 | //! This class gives a more efficient way to implement this. |
42 | //! It has two lists (two arrays of integers), one to describe |
43 | //! list (empty, one value given immediately, or negated index in |
44 | //! the second list), one to store refs (pointed from the first |
45 | //! list). This is much more efficient than a list of sequences, |
46 | //! in terms of speed (especially for read) and of memory |
47 | //! |
48 | //! An IntList can also be set to access data for a given entity |
49 | //! number, it then acts as a single sequence |
50 | //! |
51 | //! Remark that if an IntList is created from another one, it can |
52 | //! be read, but if it is created without copying, it may not be |
53 | //! edited |
54 | class Interface_IntList |
55 | { |
56 | public: |
57 | |
58 | DEFINE_STANDARD_ALLOC |
59 | |
60 | |
61 | //! Creates empty IntList. |
62 | Standard_EXPORT Interface_IntList(); |
63 | |
64 | //! Creates an IntList for <nbe> entities |
65 | Standard_EXPORT Interface_IntList(const Standard_Integer nbe); |
66 | |
67 | //! Creates an IntList from another one. |
68 | //! if <copied> is True, copies data |
69 | //! else, data are not copied, only the header object is |
70 | Standard_EXPORT Interface_IntList(const Interface_IntList& other, const Standard_Boolean copied); |
71 | |
72 | //! Initialize IntList by number of entities. |
73 | Standard_EXPORT void Initialize (const Standard_Integer nbe); |
74 | |
75 | //! Returns internal values, used for copying |
76 | Standard_EXPORT void Internals (Standard_Integer& nbrefs, Handle(TColStd_HArray1OfInteger)& ents, Handle(TColStd_HArray1OfInteger)& refs) const; |
77 | |
78 | //! Returns count of entities to be aknowledged |
79 | Standard_EXPORT Standard_Integer NbEntities() const; |
80 | |
81 | //! Changes the count of entities (ignored if decreased) |
82 | Standard_EXPORT void SetNbEntities (const Standard_Integer nbe); |
83 | |
84 | //! Sets an entity number as current (for read and fill) |
85 | Standard_EXPORT void SetNumber (const Standard_Integer number); |
86 | |
87 | //! Returns the current entity number |
88 | Standard_EXPORT Standard_Integer Number() const; |
89 | |
90 | //! Returns an IntList, identical to <me> but set to a specified |
91 | //! entity Number |
92 | //! By default, not copied (in order to be read) |
93 | //! Specified <copied> to produce another list and edit it |
94 | Standard_EXPORT Interface_IntList List (const Standard_Integer number, const Standard_Boolean copied = Standard_False) const; |
95 | |
96 | //! Sets current entity list to be redefined or not |
97 | //! This is used in a Graph for redefinition list : it can be |
98 | //! disable (no redefinition, i.e. list is cleared), or enabled |
99 | //! (starts as empty). The original list has not to be "redefined" |
100 | Standard_EXPORT void SetRedefined (const Standard_Boolean mode); |
101 | |
102 | //! Makes a reservation for <count> references to be later |
103 | //! attached to the current entity. If required, it increases |
104 | //! the size of array used to store refs. Remark that if count is |
105 | //! less than two, it does nothing (because immediate storing) |
106 | Standard_EXPORT void Reservate (const Standard_Integer count); |
107 | |
108 | //! Adds a reference (as an integer value, an entity number) to |
109 | //! the current entity number. Zero is ignored |
110 | Standard_EXPORT void Add (const Standard_Integer ref); |
111 | |
112 | //! Returns the count of refs attached to current entity number |
113 | Standard_EXPORT Standard_Integer Length() const; |
114 | |
115 | //! Returns True if the list for a number (default is taken as |
116 | //! current) is "redefined" (usefull for empty list) |
117 | Standard_EXPORT Standard_Boolean IsRedefined (const Standard_Integer num = 0) const; |
118 | |
119 | //! Returns a reference number in the list for current number, |
120 | //! according to its rank |
121 | Standard_EXPORT Standard_Integer Value (const Standard_Integer num) const; |
122 | |
123 | //! Removes an item in the list for current number, given its rank |
124 | //! Returns True if done, False else |
125 | Standard_EXPORT Standard_Boolean Remove (const Standard_Integer num); |
126 | |
127 | //! Clears all data, hence each entity number has an empty list |
128 | Standard_EXPORT void Clear(); |
129 | |
130 | //! Resizes lists to exact sizes. For list of refs, a positive |
131 | //! margin can be added. |
132 | Standard_EXPORT void AdjustSize (const Standard_Integer margin = 0); |
133 | |
134 | |
135 | |
136 | |
137 | protected: |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | private: |
144 | |
145 | |
146 | |
147 | Standard_Integer thenbe; |
148 | Standard_Integer thenbr; |
149 | Standard_Integer thenum; |
150 | Standard_Integer thecount; |
151 | Standard_Integer therank; |
152 | Handle(TColStd_HArray1OfInteger) theents; |
153 | Handle(TColStd_HArray1OfInteger) therefs; |
154 | |
155 | |
156 | }; |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | #endif // _Interface_IntList_HeaderFile |