1 // Created on: 2000-08-21
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _ShapeProcess_DictionaryOfOperator_HeaderFile
17 #define _ShapeProcess_DictionaryOfOperator_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <Standard_Character.hxx>
23 #include <MMgt_TShared.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_CString.hxx>
26 #include <Standard_Size.hxx>
27 #include <Standard_Integer.hxx>
28 class ShapeProcess_Operator;
29 class Standard_NoSuchObject;
30 class ShapeProcess_IteratorOfDictionaryOfOperator;
31 class ShapeProcess_StackItemOfDictionaryOfOperator;
32 class TCollection_AsciiString;
35 class ShapeProcess_DictionaryOfOperator;
36 DEFINE_STANDARD_HANDLE(ShapeProcess_DictionaryOfOperator, MMgt_TShared)
39 class ShapeProcess_DictionaryOfOperator : public MMgt_TShared
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
51 Standard_EXPORT ShapeProcess_DictionaryOfOperator();
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
57 Standard_EXPORT Standard_Boolean HasItem (const Standard_CString name, const Standard_Boolean exact = Standard_False) const;
59 //! Works as above method but accepts a String from TCollection
60 Standard_EXPORT Standard_Boolean HasItem (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const;
62 //! Returns item bound to a name in the Dictionnary
63 //! <exact> : same as for HasItem
64 Standard_EXPORT const Handle(ShapeProcess_Operator)& Item (const Standard_CString name, const Standard_Boolean exact = Standard_True) const;
66 //! Works as above method but accepts a String from TCollection
67 Standard_EXPORT const Handle(ShapeProcess_Operator)& Item (const TCollection_AsciiString& name, const Standard_Boolean exact = Standard_True) const;
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
72 Standard_EXPORT Standard_Boolean GetItem (const Standard_CString name, Handle(ShapeProcess_Operator)& anitem, const Standard_Boolean exact = Standard_True) const;
74 //! Works as above method but accepts a String from TCollection
75 Standard_EXPORT Standard_Boolean GetItem (const TCollection_AsciiString& name, Handle(ShapeProcess_Operator)& anitem, const Standard_Boolean exact = Standard_True) const;
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
83 Standard_EXPORT void SetItem (const Standard_CString name, const Handle(ShapeProcess_Operator)& anitem, const Standard_Boolean exact = Standard_True);
85 //! Works as above method but accepts a String from TCollection
86 Standard_EXPORT void SetItem (const TCollection_AsciiString& name, const Handle(ShapeProcess_Operator)& anitem, const Standard_Boolean exact = Standard_True);
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.
94 Standard_EXPORT Handle(ShapeProcess_Operator)& NewItem (const Standard_CString name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True);
96 //! Works as above method but accepts a String from TCollection
97 Standard_EXPORT Handle(ShapeProcess_Operator)& NewItem (const TCollection_AsciiString& name, Standard_Boolean& isvalued, const Standard_Boolean exact = Standard_True);
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
106 Standard_EXPORT Standard_Boolean RemoveItem (const Standard_CString name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True);
108 //! Works as above method but accepts a String from TCollection
109 Standard_EXPORT Standard_Boolean RemoveItem (const TCollection_AsciiString& name, const Standard_Boolean cln = Standard_True, const Standard_Boolean exact = Standard_True);
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)
114 Standard_EXPORT void Clean();
116 //! Returns True if no Item is recorded
117 Standard_EXPORT Standard_Boolean IsEmpty() const;
119 //! Clears all the Dictionary : all recorded Items are removed
120 Standard_EXPORT void Clear();
122 //! Copies the Dictionary as a Tree, without Copying the Items
123 Standard_EXPORT Handle(ShapeProcess_DictionaryOfOperator) Copy() const;
125 //! Internal routine used for completion (returns True if success)
126 Standard_EXPORT Standard_Boolean Complete (Handle(ShapeProcess_DictionaryOfOperator)& acell) const;
129 friend class ShapeProcess_IteratorOfDictionaryOfOperator;
132 DEFINE_STANDARD_RTTI_INLINE(ShapeProcess_DictionaryOfOperator,MMgt_TShared)
142 //! Defines cell's character (internal use, to build dict. tree)
143 Standard_EXPORT void SetChar (const Standard_Character car);
145 //! Returns True if this cell has a subcell
146 Standard_EXPORT Standard_Boolean HasSub() const;
149 Standard_EXPORT Handle(ShapeProcess_DictionaryOfOperator) Sub() const;
151 //! Returns True if this cell has a next cell
152 Standard_EXPORT Standard_Boolean HasNext() const;
154 //! Returns next cell
155 Standard_EXPORT Handle(ShapeProcess_DictionaryOfOperator) Next() const;
158 Standard_EXPORT void SetSub (const Handle(ShapeProcess_DictionaryOfOperator)& acell);
160 //! Defines next cell
161 Standard_EXPORT void SetNext (const Handle(ShapeProcess_DictionaryOfOperator)& acell);
163 //! Internal method used to get an entry from a given name
164 Standard_EXPORT void SearchCell (const Standard_CString name, const Standard_Size lmax, const Standard_Character car, const Standard_Size level, Handle(ShapeProcess_DictionaryOfOperator)& acell, Standard_Size& reslev, Standard_Integer& stat) const;
166 //! Internal method used to create a new entry for a name
167 Standard_EXPORT void NewCell (const Standard_CString name, const Standard_Size namlen, Handle(ShapeProcess_DictionaryOfOperator)& acell, const Standard_Size reslev, const Standard_Integer stat);
169 //! Returns True if a cell has an associated item value
170 Standard_EXPORT Standard_Boolean HasIt() const;
172 //! Returns item value associated to a cell
173 Standard_EXPORT const Handle(ShapeProcess_Operator)& It() const;
175 //! Returns item address associated to a cell
176 Standard_EXPORT Handle(ShapeProcess_Operator)& ItAdr();
178 //! Binds an item value to a cell
179 Standard_EXPORT void SetIt (const Handle(ShapeProcess_Operator)& anitem);
181 //! Declares a cell as Valued : used by NewItem (when an Item
182 //! is created if it did not exist and is returned)
183 Standard_EXPORT void DeclIt();
185 //! Removes item bound to a cell (cancels effect of DeclIt)
186 Standard_EXPORT void RemoveIt();
188 //! Returns cell's character as a node feature
189 Standard_EXPORT Standard_Character CellChar() const;
191 //! Performs Copy from an original <fromcell> to <me>
193 Standard_EXPORT void GetCopied (const Handle(ShapeProcess_DictionaryOfOperator)& fromcell);
195 Standard_Character thecars[4];
196 Handle(ShapeProcess_DictionaryOfOperator) thesub;
197 Handle(ShapeProcess_DictionaryOfOperator) thenext;
198 Handle(ShapeProcess_Operator) theitem;
209 #endif // _ShapeProcess_DictionaryOfOperator_HeaderFile