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