42cf5bc1 |
1 | // Created on: 1994-11-04 |
2 | // Created by: Christian CAILLET |
3 | // Copyright (c) 1994-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 _Transfer_Finder_HeaderFile |
18 | #define _Transfer_Finder_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
997e128f |
22 | #include <Standard_Transient.hxx> |
42cf5bc1 |
23 | |
997e128f |
24 | #include <NCollection_DataMap.hxx> |
42cf5bc1 |
25 | #include <Standard_Integer.hxx> |
25e59720 |
26 | #include <Standard_Transient.hxx> |
42cf5bc1 |
27 | #include <Standard_Boolean.hxx> |
28 | #include <Standard_Type.hxx> |
29 | #include <Standard_CString.hxx> |
30 | #include <Interface_ParamType.hxx> |
31 | #include <Standard_Real.hxx> |
997e128f |
32 | #include <TCollection_AsciiString.hxx> |
33 | |
42cf5bc1 |
34 | |
35 | |
36 | class Transfer_Finder; |
25e59720 |
37 | DEFINE_STANDARD_HANDLE(Transfer_Finder, Standard_Transient) |
42cf5bc1 |
38 | |
39 | //! a Finder allows to map any kind of object as a Key for a Map. |
40 | //! This works by defining, for a Hash Code, that of the real Key, |
41 | //! not of the Finder which acts only as an intermediate. |
42 | //! When a Map asks for the HashCode of a Finder, this one returns |
43 | //! the code it has determined at creation time |
25e59720 |
44 | class Transfer_Finder : public Standard_Transient |
42cf5bc1 |
45 | { |
46 | |
47 | public: |
48 | |
49 | |
50 | //! Returns the HashCode which has been stored by SetHashCode |
51 | //! (remark that HashCode could be deferred then be defined by |
52 | //! sub-classes, the result is the same) |
53 | Standard_EXPORT Standard_Integer GetHashCode() const; |
54 | |
55 | //! Specific testof equallity : to be defined by each sub-class, |
56 | //! must be False if Finders have not the same true Type, else |
57 | //! their contents must be compared |
58 | Standard_EXPORT virtual Standard_Boolean Equates (const Handle(Transfer_Finder)& other) const = 0; |
59 | |
60 | //! Returns the Type of the Value. By default, returns the |
61 | //! DynamicType of <me>, but can be redefined |
62 | Standard_EXPORT virtual Handle(Standard_Type) ValueType() const; |
63 | |
64 | //! Returns the name of the Type of the Value. Default is name |
65 | //! of ValueType, unless it is for a non-handled object |
66 | Standard_EXPORT virtual Standard_CString ValueTypeName() const; |
67 | |
68 | //! Adds an attribute with a given name (replaces the former one |
69 | //! with the same name if already exists) |
70 | Standard_EXPORT void SetAttribute (const Standard_CString name, const Handle(Standard_Transient)& val); |
71 | |
72 | //! Removes an attribute |
73 | //! Returns True when done, False if this attribute did not exist |
74 | Standard_EXPORT Standard_Boolean RemoveAttribute (const Standard_CString name); |
75 | |
76 | //! Returns an attribute from its name, filtered by a type |
77 | //! If no attribute has this name, or if it is not kind of this |
78 | //! type, <val> is Null and returned value is False |
79 | //! Else, it is True |
80 | Standard_EXPORT Standard_Boolean GetAttribute (const Standard_CString name, const Handle(Standard_Type)& type, Handle(Standard_Transient)& val) const; |
81 | |
82 | //! Returns an attribute from its name. Null Handle if not recorded |
83 | //! (whatever Transient, Integer, Real ...) |
84 | Standard_EXPORT Handle(Standard_Transient) Attribute (const Standard_CString name) const; |
85 | |
86 | //! Returns the type of an attribute : |
87 | //! ParamInt , ParamReal , ParamText (String) , ParamIdent (any) |
88 | //! or ParamVoid (not recorded) |
89 | Standard_EXPORT Interface_ParamType AttributeType (const Standard_CString name) const; |
90 | |
91 | //! Adds an integer value for an attribute |
92 | Standard_EXPORT void SetIntegerAttribute (const Standard_CString name, const Standard_Integer val); |
93 | |
94 | //! Returns an attribute from its name, as integer |
95 | //! If no attribute has this name, or not an integer, |
96 | //! <val> is 0 and returned value is False |
97 | //! Else, it is True |
98 | Standard_EXPORT Standard_Boolean GetIntegerAttribute (const Standard_CString name, Standard_Integer& val) const; |
99 | |
100 | //! Returns an integer attribute from its name. 0 if not recorded |
101 | Standard_EXPORT Standard_Integer IntegerAttribute (const Standard_CString name) const; |
102 | |
103 | //! Adds a real value for an attribute |
104 | Standard_EXPORT void SetRealAttribute (const Standard_CString name, const Standard_Real val); |
105 | |
106 | //! Returns an attribute from its name, as real |
107 | //! If no attribute has this name, or not a real |
108 | //! <val> is 0.0 and returned value is False |
109 | //! Else, it is True |
110 | Standard_EXPORT Standard_Boolean GetRealAttribute (const Standard_CString name, Standard_Real& val) const; |
111 | |
112 | //! Returns a real attribute from its name. 0.0 if not recorded |
113 | Standard_EXPORT Standard_Real RealAttribute (const Standard_CString name) const; |
114 | |
115 | //! Adds a String value for an attribute |
116 | Standard_EXPORT void SetStringAttribute (const Standard_CString name, const Standard_CString val); |
117 | |
118 | //! Returns an attribute from its name, as String |
119 | //! If no attribute has this name, or not a String |
120 | //! <val> is 0.0 and returned value is False |
121 | //! Else, it is True |
122 | Standard_EXPORT Standard_Boolean GetStringAttribute (const Standard_CString name, Standard_CString& val) const; |
123 | |
124 | //! Returns a String attribute from its name. "" if not recorded |
125 | Standard_EXPORT Standard_CString StringAttribute (const Standard_CString name) const; |
126 | |
127 | //! Returns the exhaustive list of attributes |
997e128f |
128 | Standard_EXPORT NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& AttrList(); |
42cf5bc1 |
129 | |
130 | //! Gets the list of attributes from <other>, as such, i.e. |
131 | //! not copied : attributes are shared, any attribute edited, |
132 | //! added, or removed in <other> is also in <me> and vice versa |
133 | //! The former list of attributes of <me> is dropped |
134 | Standard_EXPORT void SameAttributes (const Handle(Transfer_Finder)& other); |
135 | |
136 | //! Gets the list of attributes from <other>, by copying it |
137 | //! By default, considers all the attributes from <other> |
138 | //! If <fromname> is given, considers only the attributes with |
139 | //! name beginning by <fromname> |
140 | //! |
141 | //! For each attribute, if <copied> is True (D), its value is also |
142 | //! copied if it is a basic type (Integer,Real,String), else it |
143 | //! remains shared between <other> and <me> |
144 | //! |
145 | //! These new attributes are added to the existing ones in <me>, |
146 | //! in case of same name, they replace the existing ones |
147 | Standard_EXPORT void GetAttributes (const Handle(Transfer_Finder)& other, const Standard_CString fromname = "", const Standard_Boolean copied = Standard_True); |
148 | |
149 | |
150 | |
151 | |
25e59720 |
152 | DEFINE_STANDARD_RTTIEXT(Transfer_Finder,Standard_Transient) |
42cf5bc1 |
153 | |
154 | protected: |
155 | |
156 | |
157 | //! Stores the HashCode which corresponds to the Value given to |
158 | //! create the Mapper |
159 | Standard_EXPORT void SetHashCode (const Standard_Integer code); |
160 | |
161 | |
162 | |
163 | private: |
164 | |
165 | |
166 | Standard_Integer thecode; |
997e128f |
167 | NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> theattrib; |
42cf5bc1 |
168 | |
169 | |
170 | }; |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | #endif // _Transfer_Finder_HeaderFile |