1 // Created on: 1998-02-23
2 // Created by: Christian CAILLET
3 // Copyright (c) 1998-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 _MoniTool_TypedValue_HeaderFile
18 #define _MoniTool_TypedValue_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <MoniTool_ValueType.hxx>
25 #include <NCollection_DataMap.hxx>
26 #include <Standard_Type.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_Real.hxx>
29 #include <TColStd_HArray1OfAsciiString.hxx>
30 #include <MoniTool_ValueInterpret.hxx>
31 #include <MoniTool_ValueSatisfies.hxx>
32 #include <Standard_Transient.hxx>
33 #include <Standard_CString.hxx>
34 #include <Standard_Boolean.hxx>
35 #include <TColStd_HSequenceOfAsciiString.hxx>
36 class TCollection_HAsciiString;
37 class Standard_Transient;
38 class Standard_ConstructionError;
39 class TCollection_AsciiString;
40 class Message_Messenger;
43 class MoniTool_TypedValue;
44 DEFINE_STANDARD_HANDLE(MoniTool_TypedValue, Standard_Transient)
46 //! This class allows to dynamically manage .. typed values, i.e.
47 //! values which have an alphanumeric expression, but with
48 //! controls. Such as "must be an Integer" or "Enumerative Text"
51 //! Hence, a TypedValue brings a specification (type + constraints
52 //! if any) and a value. Its basic form is a string, it can be
53 //! specified as integer or real or enumerative string, then
55 //! Its string content, which is a Handle(HAsciiString) can be
56 //! shared by other data structures, hence gives a direct on line
57 //! access to its value.
58 class MoniTool_TypedValue : public Standard_Transient
64 //! Creates a TypedValue, with a name
66 //! type gives the type of the parameter, default is free text
67 //! Also available : Integer, Real, Enum, Entity (i.e. Object)
68 //! More precise specifications, titles, can be given to the
69 //! TypedValue once created
71 //! init gives an initial value. If it is not given, the
72 //! TypedValue begins as "not set", its value is empty
73 Standard_EXPORT MoniTool_TypedValue(const Standard_CString name, const MoniTool_ValueType type = MoniTool_ValueText, const Standard_CString init = "");
75 //! Creates a TypedValue from another one, by duplication
76 Standard_EXPORT MoniTool_TypedValue(const Handle(MoniTool_TypedValue)& other);
78 //! Access to internal data which have no other access
79 Standard_EXPORT void Internals (MoniTool_ValueInterpret& interp, MoniTool_ValueSatisfies& satisf, Standard_CString& satisname, NCollection_DataMap<TCollection_AsciiString, Standard_Integer>& enums) const;
82 Standard_EXPORT Standard_CString Name() const;
84 //! Returns the type of the value
85 Standard_EXPORT MoniTool_ValueType ValueType() const;
87 //! Returns the Definition
88 //! By priority, the enforced one, else an automatic one, computed
89 //! from the specification
90 Standard_EXPORT TCollection_AsciiString Definition() const;
92 //! Enforces a Definition
93 Standard_EXPORT void SetDefinition (const Standard_CString deftext);
95 //! Prints definition, specification, and actual status and value
96 Standard_EXPORT virtual void Print (const Handle(Message_Messenger)& S) const;
98 //! Prints only the Value
99 Standard_EXPORT void PrintValue (const Handle(Message_Messenger)& S) const;
101 //! Completes the definition of a TypedValue by command <initext>,
102 //! once created with its type
103 //! Returns True if done, False if could not be interpreted
104 //! <initext> may be :
105 //! imin ival : minimum value for an integer
106 //! imax ival : maximum value for an integer
107 //! rmin rval : minimum value for a real
108 //! rmax rval : maximum value for a real
109 //! unit name : name of unit
110 //! ematch i : enum from integer value i, match required
111 //! enum i : enum from integer value i, match not required
112 //! eval text : add an enumerative value (increments max by 1)
113 //! eval ?? : add a non-authorised enum value (to be skipped)
114 //! tmax l : maximum length for a text
115 Standard_EXPORT Standard_Boolean AddDef (const Standard_CString initext);
117 //! Sets a label, which can then be displayed
118 Standard_EXPORT void SetLabel (const Standard_CString label);
120 //! Returns the label, if set; else returns an empty string
121 Standard_EXPORT Standard_CString Label() const;
123 //! Sets a maximum length for a text (active only for a free text)
124 Standard_EXPORT void SetMaxLength (const Standard_Integer max);
126 //! Returns the maximum length, 0 if not set
127 Standard_EXPORT Standard_Integer MaxLength() const;
129 //! Sets an Integer limit (included) to <val>, the upper limit
130 //! if <max> is True, the lower limit if <max> is False
131 Standard_EXPORT void SetIntegerLimit (const Standard_Boolean max, const Standard_Integer val);
133 //! Gives an Integer Limit (upper if <max> True, lower if <max>
134 //! False). Returns True if this limit is defined, False else
135 //! (in that case, gives the natural limit for Integer)
136 Standard_EXPORT Standard_Boolean IntegerLimit (const Standard_Boolean max, Standard_Integer& val) const;
138 //! Sets a Real limit (included) to <val>, the upper limit
139 //! if <max> is True, the lower limit if <max> is False
140 Standard_EXPORT void SetRealLimit (const Standard_Boolean max, const Standard_Real val);
142 //! Gives an Real Limit (upper if <max> True, lower if <max>
143 //! False). Returns True if this limit is defined, False else
144 //! (in that case, gives the natural limit for Real)
145 Standard_EXPORT Standard_Boolean RealLimit (const Standard_Boolean max, Standard_Real& val) const;
147 //! Sets (Clears if <def> empty) a unit definition, as an equation
148 //! of dimensions. TypedValue just records this definition, does
149 //! not exploit it, to be done as required by user applications
150 Standard_EXPORT void SetUnitDef (const Standard_CString def);
152 //! Returns the recorded unit definition, empty if not set
153 Standard_EXPORT Standard_CString UnitDef() const;
155 //! For an enumeration, precises the starting value (default 0)
156 //! and the match condition : if True (D), the string value must
157 //! match the definition, else it may take another value : in that
158 //! case, the Integer Value will be Start - 1.
159 //! (empty value remains allowed)
160 Standard_EXPORT void StartEnum (const Standard_Integer start = 0, const Standard_Boolean match = Standard_True);
162 //! Adds enumerative definitions. For more than 10, several calls
163 Standard_EXPORT void AddEnum (const Standard_CString v1 = "", const Standard_CString v2 = "", const Standard_CString v3 = "", const Standard_CString v4 = "", const Standard_CString v5 = "", const Standard_CString v6 = "", const Standard_CString v7 = "", const Standard_CString v8 = "", const Standard_CString v9 = "", const Standard_CString v10 = "");
165 //! Adds an enumeration definition, by its string and numeric
166 //! values. If it is the first setting for this value, it is
167 //! recorded as main value. Else, it is recognized as alternate
168 //! string for this numeric value
169 Standard_EXPORT void AddEnumValue (const Standard_CString val, const Standard_Integer num);
171 //! Gives the Enum definitions : start value, end value, match
172 //! status. Returns True for an Enum, False else.
173 Standard_EXPORT Standard_Boolean EnumDef (Standard_Integer& startcase, Standard_Integer& endcase, Standard_Boolean& match) const;
175 //! Returns the value of an enumerative definition, from its rank
176 //! Empty string if out of range or not an Enum
177 Standard_EXPORT Standard_CString EnumVal (const Standard_Integer num) const;
179 //! Returns the case number which cooresponds to a string value
180 //! Works with main and additionnal values
181 //! Returns (StartEnum - 1) if not OK, -1 if not an Enum
182 Standard_EXPORT Standard_Integer EnumCase (const Standard_CString val) const;
184 //! Sets type of which an Object TypedValue must be kind of
185 //! Error for a TypedValue not an Object (Entity)
186 Standard_EXPORT void SetObjectType (const Handle(Standard_Type)& typ);
188 //! Returns the type of which an Object TypedValue must be kind of
189 //! Default is Standard_Transient
190 //! Null for a TypedValue not an Object
191 Standard_EXPORT Handle(Standard_Type) ObjectType() const;
193 //! Sets a specific Interpret function
194 Standard_EXPORT void SetInterpret (const MoniTool_ValueInterpret func);
196 //! Tells if a TypedValue has an Interpret
197 Standard_EXPORT virtual Standard_Boolean HasInterpret() const;
199 //! Sets a specific Satisfies function : it is added to the
200 //! already defined criteria
201 //! It must match the form :
202 //! statisfies (val : HAsciiString) returns Boolean
203 Standard_EXPORT void SetSatisfies (const MoniTool_ValueSatisfies func, const Standard_CString name);
205 //! Returns name of specific satisfy, empty string if none
206 Standard_EXPORT Standard_CString SatisfiesName() const;
208 //! Returns True if the value is set (not empty/not null object)
209 Standard_EXPORT Standard_Boolean IsSetValue() const;
211 //! Returns the value, as a cstring. Empty if not set.
212 Standard_EXPORT Standard_CString CStringValue() const;
214 //! Returns the value, as a Handle (can then be shared)
215 //! Null if not defined
216 Standard_EXPORT Handle(TCollection_HAsciiString) HStringValue() const;
218 //! Interprets a value.
219 //! <native> True : returns a native value
220 //! <native> False : returns a coded value
221 //! If the Interpret function is set, calls it
222 //! Else, for an Enum, Native returns the Text, Coded returns
224 //! STANDARD RETURNS : = hval means no specific interpretation
225 //! Null means senseless
226 //! Can also be redefined
227 Standard_EXPORT virtual Handle(TCollection_HAsciiString) Interpret (const Handle(TCollection_HAsciiString)& hval, const Standard_Boolean native) const;
229 //! Returns True if a value statifies the specification
230 //! (remark : does not apply to Entity : see ObjectType, for this
231 //! type, the string is just a comment)
232 Standard_EXPORT virtual Standard_Boolean Satisfies (const Handle(TCollection_HAsciiString)& hval) const;
234 //! Clears the recorded Value : it is now unset
235 Standard_EXPORT void ClearValue();
237 //! Changes the value. The new one must satisfy the specification
238 //! Returns False (and did not set) if the new value
239 //! does not satisfy the specification
240 //! Can be redefined to be managed (in a subclass)
241 Standard_EXPORT virtual Standard_Boolean SetCStringValue (const Standard_CString val);
243 //! Forces a new Handle for the Value
244 //! It can be empty, else (if Type is not free Text), it must
245 //! satisfy the specification.
246 //! Not only the value is changed, but also the way it is shared
247 //! Remark : for Type=Object, this value is not controlled, it can
248 //! be set as a comment
249 //! Returns False (and did not set) if the new value
250 //! does not satisfy the specification
251 //! Can be redefined to be managed (in a subclass)
252 Standard_EXPORT virtual Standard_Boolean SetHStringValue (const Handle(TCollection_HAsciiString)& hval);
254 //! Returns the value as integer, i.e. :
255 //! For type = Integer, the integer itself; 0 if not set
256 //! For type = Enum, the designated rank (see Enum definition)
257 //! StartEnum - 1 if not set or not in the definition
259 Standard_EXPORT Standard_Integer IntegerValue() const;
261 //! Changes the value as an integer, only for Integer or Enum
262 Standard_EXPORT virtual Standard_Boolean SetIntegerValue (const Standard_Integer ival);
264 //! Returns the value as real, for a Real type TypedValue
266 Standard_EXPORT Standard_Real RealValue() const;
268 //! Changes the value as a real, only for Real
269 Standard_EXPORT virtual Standard_Boolean SetRealValue (const Standard_Real rval);
271 //! Returns the value as Transient Object, only for Object/Entity
272 //! Remark that the "HString value" is IGNORED here
273 //! Null if not set; remains to be casted
274 Standard_EXPORT Handle(Standard_Transient) ObjectValue() const;
276 //! Same as ObjectValue, but avoids DownCast : the receiving
277 //! variable is directly loaded. It is assumed that it complies
278 //! with the definition of ObjectType ! Otherwise, big trouble
279 Standard_EXPORT void GetObjectValue (Handle(Standard_Transient)& val) const;
281 //! Changes the value as Transient Object, only for Object/Entity
282 //! Returns False if DynamicType does not satisfy ObjectType
283 //! Can be redefined to be managed (in a subclass)
284 Standard_EXPORT virtual Standard_Boolean SetObjectValue (const Handle(Standard_Transient)& obj);
286 //! Returns the type name of the ObjectValue, or an empty string
288 Standard_EXPORT Standard_CString ObjectTypeName() const;
290 //! Adds a TypedValue in the library.
291 //! It is recorded then will be accessed by its Name
292 //! Its Definition may be imposed, else it is computed as usual
293 //! By default it will be accessed by its Definition (string)
294 //! Returns True if done, False if tv is Null or brings no
295 //! Definition or <def> not defined
297 //! If a TypedValue was already recorded under this name, it is
299 Standard_EXPORT static Standard_Boolean AddLib (const Handle(MoniTool_TypedValue)& tv, const Standard_CString def = "");
301 //! Returns the TypedValue bound with a given Name
302 //! Null Handle if none recorded
303 //! Warning : it is the original, not duplicated
304 Standard_EXPORT static Handle(MoniTool_TypedValue) Lib (const Standard_CString def);
306 //! Returns a COPY of the TypedValue bound with a given Name
307 //! Null Handle if none recorded
308 Standard_EXPORT static Handle(MoniTool_TypedValue) FromLib (const Standard_CString def);
310 //! Returns the list of names of items of the Library of Types
311 //! -- Library of TypedValue as Valued Parameters, -- --
312 //! accessed by parameter name
313 //! for use by management of Static Parameters
314 Standard_EXPORT static Handle(TColStd_HSequenceOfAsciiString) LibList();
316 //! Returns a static value from its name, null if unknown
317 Standard_EXPORT static Handle(MoniTool_TypedValue) StaticValue (const Standard_CString name);
322 DEFINE_STANDARD_RTTIEXT(MoniTool_TypedValue,Standard_Transient)
327 //! Gives the internal library of static values
328 Standard_EXPORT static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& Stats();
335 TCollection_AsciiString thename;
336 TCollection_AsciiString thedef;
337 TCollection_AsciiString thelabel;
338 MoniTool_ValueType thetype;
339 Handle(Standard_Type) theotyp;
340 Standard_Integer thelims;
341 Standard_Integer themaxlen;
342 Standard_Integer theintlow;
343 Standard_Integer theintup;
344 Standard_Real therealow;
345 Standard_Real therealup;
346 TCollection_AsciiString theunidef;
347 Handle(TColStd_HArray1OfAsciiString) theenums;
348 NCollection_DataMap<TCollection_AsciiString, Standard_Integer> theeadds;
349 MoniTool_ValueInterpret theinterp;
350 MoniTool_ValueSatisfies thesatisf;
351 TCollection_AsciiString thesatisn;
352 Standard_Integer theival;
353 Handle(TCollection_HAsciiString) thehval;
354 Handle(Standard_Transient) theoval;
365 #endif // _MoniTool_TypedValue_HeaderFile