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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Dico_DictionaryOfTransient_HeaderFile
18 #define _Dico_DictionaryOfTransient_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
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;
36 class Dico_DictionaryOfTransient;
37 DEFINE_STANDARD_HANDLE(Dico_DictionaryOfTransient, MMgt_TShared)
40 class Dico_DictionaryOfTransient : public MMgt_TShared
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
52 Standard_EXPORT Dico_DictionaryOfTransient();
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
58 Standard_EXPORT Standard_Boolean HasItem (const Standard_CString name, const Standard_Boolean exact = Standard_False) const;
60 //! Works as above method but accepts a String from TCollection
61 Standard_EXPORT Standard_Boolean HasItem (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const;
63 //! Returns item bound to a name in the Dictionnary
64 //! <exact> : same as for HasItem
65 Standard_EXPORT const Handle(Standard_Transient)& Item (const Standard_CString name, const Standard_Boolean exact = Standard_True) const;
67 //! Works as above method but accepts a String from TCollection
68 Standard_EXPORT const Handle(Standard_Transient)& Item (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const;
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
73 Standard_EXPORT Standard_Boolean GetItem (const Standard_CString name, Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True) const;
75 //! Safe variant of GetItem() for arbitrary type of argument
77 Standard_Boolean GetItem (const Standard_CString theName, Handle(T)& theItem, const Standard_Boolean theExact = Standard_True) const
79 Handle(Standard_Transient) anItem = theItem;
80 return GetItem (theName, anItem, theExact) && ! (theItem = Handle(T)::DownCast(anItem)).IsNull();
83 //! Works as above method but accepts a String from TCollection
84 Standard_EXPORT Standard_Boolean GetItem (const TCollection_AsciiString& name, Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True) const;
86 //! Safe variant of GetItem() for arbitrary type of argument
88 Standard_Boolean GetItem (const TCollection_AsciiString& theName, Handle(T)& theItem, const Standard_Boolean theExact = Standard_True) const
90 Handle(Standard_Transient) anItem = theItem;
91 return GetItem (theName, anItem, theExact) && ! (theItem = Handle(T)::DownCast(anItem)).IsNull();
94 //! Binds an item to a dictionnary entry
95 //! If <name> is already known in the dictionary, its value
96 //! is changed. Else, the dictionary entry is created.
97 //! If <exact> is given False, completion is tried, it is accepted
98 //! If it gives a UNIQUE entry : hence this one will be modified
99 //! Else, new entry is created with the exact name given
100 Standard_EXPORT void SetItem (const Standard_CString name, const Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True);
102 //! Works as above method but accepts a String from TCollection
103 Standard_EXPORT void SetItem (const TCollection_AsciiString& name, const Handle(Standard_Transient)& anitem, const Standard_Boolean exact = Standard_True);
105 //! Returns the Item AS AN ADDRESS which corresponds to a Name,
106 //! in order to be changed or set.
107 //! If this name is not yet recorded, the Dictionary creates it.
108 //! <isvalued> is returned True if the Item is recorded in the
109 //! Dictionary, False else, in that case the Item is reserved and
110 //! the name is noted as beeing valued now.
111 Standard_EXPORT Handle(Standard_Transient)& NewItem (const Standard_CString name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True);
113 //! Works as above method but accepts a String from TCollection
114 Standard_EXPORT Handle(Standard_Transient)& NewItem (const TCollection_AsciiString& name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True);
116 //! Removes a dictionary entry given by its name then Returns True
117 //! If the entry does not exists, Does nothing then Returns False
118 //! <exact> : as for HasItem, if completion works, the found entry
119 //! is removed (else returned value is False)
120 //! <cln> commands cleaning dictionary (to recover memory space)
121 //! For an isolated call, it is recommanded to give it at True
122 //! For a sequence of calls, rather give False, then call Clean
123 Standard_EXPORT Standard_Boolean RemoveItem (const Standard_CString name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True);
125 //! Works as above method but accepts a String from TCollection
126 Standard_EXPORT Standard_Boolean RemoveItem (const TCollection_AsciiString& name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True);
128 //! Deletes physically in one step the entries which were removed
129 //! (can be used for a more efficient Memory Management : first
130 //! Remove several Items (<cln> = False), then Clean the Memory)
131 Standard_EXPORT void Clean();
133 //! Returns True if no Item is recorded
134 Standard_EXPORT Standard_Boolean IsEmpty() const;
136 //! Clears all the Dictionary : all recorded Items are removed
137 Standard_EXPORT void Clear();
139 //! Copies the Dictionary as a Tree, without Copying the Items
140 Standard_EXPORT Handle(Dico_DictionaryOfTransient) Copy() const;
142 //! Internal routine used for completion (returns True if success)
143 Standard_EXPORT Standard_Boolean Complete (Handle(Dico_DictionaryOfTransient)& acell) const;
146 friend class Dico_IteratorOfDictionaryOfTransient;
149 DEFINE_STANDARD_RTTI_INLINE(Dico_DictionaryOfTransient,MMgt_TShared)
159 //! Defines cell's character (internal use, to build dict. tree)
160 Standard_EXPORT void SetChar (const Standard_Character car);
162 //! Returns True if this cell has a subcell
163 Standard_EXPORT Standard_Boolean HasSub() const;
166 Standard_EXPORT Handle(Dico_DictionaryOfTransient) Sub() const;
168 //! Returns True if this cell has a next cell
169 Standard_EXPORT Standard_Boolean HasNext() const;
171 //! Returns next cell
172 Standard_EXPORT Handle(Dico_DictionaryOfTransient) Next() const;
175 Standard_EXPORT void SetSub (const Handle(Dico_DictionaryOfTransient)& acell);
177 //! Defines next cell
178 Standard_EXPORT void SetNext (const Handle(Dico_DictionaryOfTransient)& acell);
180 //! Internal method used to get an entry from a given name
181 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;
183 //! Internal method used to create a new entry for a name
184 Standard_EXPORT void NewCell (const Standard_CString name, const Standard_Size namlen, Handle(Dico_DictionaryOfTransient)& acell, const Standard_Size reslev, const Standard_Integer stat);
186 //! Returns True if a cell has an associated item value
187 Standard_EXPORT Standard_Boolean HasIt() const;
189 //! Returns item value associated to a cell
190 Standard_EXPORT const Handle(Standard_Transient)& It() const;
192 //! Returns item address associated to a cell
193 Standard_EXPORT Handle(Standard_Transient)& ItAdr();
195 //! Binds an item value to a cell
196 Standard_EXPORT void SetIt (const Handle(Standard_Transient)& anitem);
198 //! Declares a cell as Valued : used by NewItem (when an Item
199 //! is created if it did not exist and is returned)
200 Standard_EXPORT void DeclIt();
202 //! Removes item bound to a cell (cancels effect of DeclIt)
203 Standard_EXPORT void RemoveIt();
205 //! Returns cell's character as a node feature
206 Standard_EXPORT Standard_Character CellChar() const;
208 //! Performs Copy from an original <fromcell> to <me>
210 Standard_EXPORT void GetCopied (const Handle(Dico_DictionaryOfTransient)& fromcell);
212 Standard_Character thecars[4];
213 Handle(Dico_DictionaryOfTransient) thesub;
214 Handle(Dico_DictionaryOfTransient) thenext;
215 Handle(Standard_Transient) theitem;
226 #endif // _Dico_DictionaryOfTransient_HeaderFile