42cf5bc1 |
1 | // Created on: 1992-07-28 |
2 | // Created by: Christian CAILLET |
3 | // Copyright (c) 1992-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 _Dico_DictionaryOfInteger_HeaderFile |
18 | #define _Dico_DictionaryOfInteger_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
22 | |
23 | #include <Standard_Character.hxx> |
24 | #include <Standard_Integer.hxx> |
25 | #include <MMgt_TShared.hxx> |
26 | #include <Standard_Boolean.hxx> |
27 | #include <Standard_CString.hxx> |
28 | #include <Standard_Size.hxx> |
29 | class Standard_NoSuchObject; |
30 | class Dico_IteratorOfDictionaryOfInteger; |
31 | class Dico_StackItemOfDictionaryOfInteger; |
32 | class TCollection_AsciiString; |
33 | |
34 | |
35 | class Dico_DictionaryOfInteger; |
36 | DEFINE_STANDARD_HANDLE(Dico_DictionaryOfInteger, MMgt_TShared) |
37 | |
38 | |
39 | class Dico_DictionaryOfInteger : public MMgt_TShared |
40 | { |
41 | |
42 | public: |
43 | |
44 | |
36b9ff75 |
45 | //! Creates a Dictionary cell. |
46 | //! A Dictionary is always created then handled by its first cell |
47 | //! After creating a Dictionary, user can call methods HasItem, |
48 | //! Item, SetItem ... (internal cells and entries are also |
49 | //! defined as objects from the same class) |
50 | //! Also iteration can be made, by an Iterator on this Dictionary |
42cf5bc1 |
51 | Standard_EXPORT Dico_DictionaryOfInteger(); |
52 | |
36b9ff75 |
53 | //! Returns True if an Item is bound to a Name in the Dictionnary |
54 | //! <exact> : if True, commands exact matching |
55 | //! if False, accept completion, only if ONE AND ONLY ONE |
56 | //! Dictionnary Entry has <name> as beginning of its name |
42cf5bc1 |
57 | Standard_EXPORT Standard_Boolean HasItem (const Standard_CString name, const Standard_Boolean exact = Standard_False) const; |
58 | |
36b9ff75 |
59 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
60 | Standard_EXPORT Standard_Boolean HasItem (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const; |
61 | |
36b9ff75 |
62 | //! Returns item bound to a name in the Dictionnary |
63 | //! <exact> : same as for HasItem |
42cf5bc1 |
64 | Standard_EXPORT const Standard_Integer& Item (const Standard_CString name, const Standard_Boolean exact = Standard_True) const; |
65 | |
36b9ff75 |
66 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
67 | Standard_EXPORT const Standard_Integer& Item (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const; |
68 | |
36b9ff75 |
69 | //! Gathers HasItem and Item, in a less regular but faster way |
70 | //! If return is True, <anitem> is returned too, else it is not |
71 | //! <exact> : same as for HasItem |
42cf5bc1 |
72 | Standard_EXPORT Standard_Boolean GetItem (const Standard_CString name, Standard_Integer& anitem, const Standard_Boolean exact = Standard_True) const; |
73 | |
36b9ff75 |
74 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
75 | Standard_EXPORT Standard_Boolean GetItem (const TCollection_AsciiString& name, Standard_Integer& anitem, const Standard_Boolean exact = Standard_True) const; |
76 | |
36b9ff75 |
77 | //! Binds an item to a dictionnary entry |
78 | //! If <name> is already known in the dictionary, its value |
79 | //! is changed. Else, the dictionary entry is created. |
80 | //! If <exact> is given False, completion is tried, it is accepted |
81 | //! If it gives a UNIQUE entry : hence this one will be modified |
82 | //! Else, new entry is created with the exact name given |
42cf5bc1 |
83 | Standard_EXPORT void SetItem (const Standard_CString name, const Standard_Integer& anitem, const Standard_Boolean exact = Standard_True); |
84 | |
36b9ff75 |
85 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
86 | Standard_EXPORT void SetItem (const TCollection_AsciiString& name, const Standard_Integer& anitem, const Standard_Boolean exact = Standard_True); |
87 | |
36b9ff75 |
88 | //! Returns the Item AS AN ADDRESS which corresponds to a Name, |
89 | //! in order to be changed or set. |
90 | //! If this name is not yet recorded, the Dictionary creates it. |
91 | //! <isvalued> is returned True if the Item is recorded in the |
92 | //! Dictionary, False else, in that case the Item is reserved and |
93 | //! the name is noted as beeing valued now. |
42cf5bc1 |
94 | Standard_EXPORT Standard_Integer& NewItem (const Standard_CString name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True); |
95 | |
36b9ff75 |
96 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
97 | Standard_EXPORT Standard_Integer& NewItem (const TCollection_AsciiString& name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True); |
98 | |
36b9ff75 |
99 | //! Removes a dictionary entry given by its name then Returns True |
100 | //! If the entry does not exists, Does nothing then Returns False |
101 | //! <exact> : as for HasItem, if completion works, the found entry |
102 | //! is removed (else returned value is False) |
103 | //! <cln> commands cleaning dictionary (to recover memory space) |
104 | //! For an isolated call, it is recommanded to give it at True |
105 | //! For a sequence of calls, rather give False, then call Clean |
42cf5bc1 |
106 | Standard_EXPORT Standard_Boolean RemoveItem (const Standard_CString name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True); |
107 | |
36b9ff75 |
108 | //! Works as above method but accepts a String from TCollection |
42cf5bc1 |
109 | Standard_EXPORT Standard_Boolean RemoveItem (const TCollection_AsciiString& name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True); |
110 | |
36b9ff75 |
111 | //! Deletes physically in one step the entries which were removed |
112 | //! (can be used for a more efficient Memory Management : first |
113 | //! Remove several Items (<cln> = False), then Clean the Memory) |
42cf5bc1 |
114 | Standard_EXPORT void Clean(); |
115 | |
36b9ff75 |
116 | //! Returns True if no Item is recorded |
42cf5bc1 |
117 | Standard_EXPORT Standard_Boolean IsEmpty() const; |
118 | |
36b9ff75 |
119 | //! Clears all the Dictionary : all recorded Items are removed |
42cf5bc1 |
120 | Standard_EXPORT void Clear(); |
121 | |
36b9ff75 |
122 | //! Copies the Dictionary as a Tree, without Copying the Items |
42cf5bc1 |
123 | Standard_EXPORT Handle(Dico_DictionaryOfInteger) Copy() const; |
124 | |
36b9ff75 |
125 | //! Internal routine used for completion (returns True if success) |
42cf5bc1 |
126 | Standard_EXPORT Standard_Boolean Complete (Handle(Dico_DictionaryOfInteger)& acell) const; |
127 | |
128 | |
129 | friend class Dico_IteratorOfDictionaryOfInteger; |
130 | |
131 | |
132 | DEFINE_STANDARD_RTTI(Dico_DictionaryOfInteger,MMgt_TShared) |
133 | |
134 | protected: |
135 | |
136 | |
137 | |
138 | |
139 | private: |
140 | |
141 | |
36b9ff75 |
142 | //! Defines cell's character (internal use, to build dict. tree) |
42cf5bc1 |
143 | Standard_EXPORT void SetChar (const Standard_Character car); |
144 | |
36b9ff75 |
145 | //! Returns True if this cell has a subcell |
42cf5bc1 |
146 | Standard_EXPORT Standard_Boolean HasSub() const; |
147 | |
36b9ff75 |
148 | //! Returns subcell |
42cf5bc1 |
149 | Standard_EXPORT Handle(Dico_DictionaryOfInteger) Sub() const; |
150 | |
36b9ff75 |
151 | //! Returns True if this cell has a next cell |
42cf5bc1 |
152 | Standard_EXPORT Standard_Boolean HasNext() const; |
153 | |
36b9ff75 |
154 | //! Returns next cell |
42cf5bc1 |
155 | Standard_EXPORT Handle(Dico_DictionaryOfInteger) Next() const; |
156 | |
36b9ff75 |
157 | //! Defines subcell |
42cf5bc1 |
158 | Standard_EXPORT void SetSub (const Handle(Dico_DictionaryOfInteger)& acell); |
159 | |
36b9ff75 |
160 | //! Defines next cell |
42cf5bc1 |
161 | Standard_EXPORT void SetNext (const Handle(Dico_DictionaryOfInteger)& acell); |
162 | |
36b9ff75 |
163 | //! Internal method used to get an entry from a given name |
42cf5bc1 |
164 | Standard_EXPORT void SearchCell (const Standard_CString name, const Standard_Size lmax, const Standard_Character car, const Standard_Size level, Handle(Dico_DictionaryOfInteger)& acell, Standard_Size& reslev, Standard_Integer& stat) const; |
165 | |
36b9ff75 |
166 | //! Internal method used to create a new entry for a name |
42cf5bc1 |
167 | Standard_EXPORT void NewCell (const Standard_CString name, const Standard_Size namlen, Handle(Dico_DictionaryOfInteger)& acell, const Standard_Size reslev, const Standard_Integer stat); |
168 | |
36b9ff75 |
169 | //! Returns True if a cell has an associated item value |
42cf5bc1 |
170 | Standard_EXPORT Standard_Boolean HasIt() const; |
171 | |
36b9ff75 |
172 | //! Returns item value associated to a cell |
42cf5bc1 |
173 | Standard_EXPORT const Standard_Integer& It() const; |
174 | |
36b9ff75 |
175 | //! Returns item address associated to a cell |
42cf5bc1 |
176 | Standard_EXPORT Standard_Integer& ItAdr(); |
177 | |
36b9ff75 |
178 | //! Binds an item value to a cell |
42cf5bc1 |
179 | Standard_EXPORT void SetIt (const Standard_Integer& anitem); |
180 | |
36b9ff75 |
181 | //! Declares a cell as Valued : used by NewItem (when an Item |
182 | //! is created if it did not exist and is returned) |
42cf5bc1 |
183 | Standard_EXPORT void DeclIt(); |
184 | |
36b9ff75 |
185 | //! Removes item bound to a cell (cancels effect of DeclIt) |
42cf5bc1 |
186 | Standard_EXPORT void RemoveIt(); |
187 | |
36b9ff75 |
188 | //! Returns cell's character as a node feature |
42cf5bc1 |
189 | Standard_EXPORT Standard_Character CellChar() const; |
190 | |
36b9ff75 |
191 | //! Performs Copy from an original <fromcell> to <me> |
192 | //! Called by Copy |
42cf5bc1 |
193 | Standard_EXPORT void GetCopied (const Handle(Dico_DictionaryOfInteger)& fromcell); |
194 | |
195 | Standard_Character thecars[4]; |
196 | Handle(Dico_DictionaryOfInteger) thesub; |
197 | Handle(Dico_DictionaryOfInteger) thenext; |
198 | Standard_Integer theitem; |
199 | |
200 | |
201 | }; |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | #endif // _Dico_DictionaryOfInteger_HeaderFile |