|
|
|||
File indexing completed on 2026-09-27 09:18:25
0001 // Created on: 1998-02-23 0002 // Created by: Christian CAILLET 0003 // Copyright (c) 1998-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _MoniTool_TypedValue_HeaderFile 0018 #define _MoniTool_TypedValue_HeaderFile 0019 0020 #include <Standard.hxx> 0021 0022 #include <MoniTool_ValueType.hxx> 0023 #include <NCollection_DataMap.hxx> 0024 #include <Standard_Type.hxx> 0025 #include <Standard_Integer.hxx> 0026 #include <Standard_Real.hxx> 0027 #include <TCollection_AsciiString.hxx> 0028 #include <NCollection_Array1.hxx> 0029 #include <NCollection_HArray1.hxx> 0030 #include <MoniTool_ValueInterpret.hxx> 0031 #include <MoniTool_ValueSatisfies.hxx> 0032 #include <Standard_Transient.hxx> 0033 #include <NCollection_Sequence.hxx> 0034 #include <NCollection_HSequence.hxx> 0035 class TCollection_HAsciiString; 0036 0037 //! This class allows to dynamically manage .. typed values, i.e. 0038 //! values which have an alphanumeric expression, but with 0039 //! controls. Such as "must be an Integer" or "Enumerative Text" 0040 //! etc 0041 //! 0042 //! Hence, a TypedValue brings a specification (type + constraints 0043 //! if any) and a value. Its basic form is a string, it can be 0044 //! specified as integer or real or enumerative string, then 0045 //! queried as such. 0046 //! Its string content, which is a occ::handle<HAsciiString> can be 0047 //! shared by other data structures, hence gives a direct on line 0048 //! access to its value. 0049 class MoniTool_TypedValue : public Standard_Transient 0050 { 0051 0052 public: 0053 //! Creates a TypedValue, with a name 0054 //! 0055 //! type gives the type of the parameter, default is free text 0056 //! Also available : Integer, Real, Enum, Entity (i.e. Object) 0057 //! More precise specifications, titles, can be given to the 0058 //! TypedValue once created 0059 //! 0060 //! init gives an initial value. If it is not given, the 0061 //! TypedValue begins as "not set", its value is empty 0062 Standard_EXPORT MoniTool_TypedValue(const char* const name, 0063 const MoniTool_ValueType type = MoniTool_ValueText, 0064 const char* const init = ""); 0065 0066 //! Creates a TypedValue from another one, by duplication 0067 Standard_EXPORT MoniTool_TypedValue(const occ::handle<MoniTool_TypedValue>& other); 0068 0069 //! Access to internal data which have no other access 0070 Standard_EXPORT void Internals(MoniTool_ValueInterpret& interp, 0071 MoniTool_ValueSatisfies& satisf, 0072 const char*& satisname, 0073 NCollection_DataMap<TCollection_AsciiString, int>& enums) const; 0074 0075 //! Returns the name 0076 Standard_EXPORT const char* Name() const; 0077 0078 //! Returns the type of the value 0079 Standard_EXPORT MoniTool_ValueType ValueType() const; 0080 0081 //! Returns the Definition 0082 //! By priority, the enforced one, else an automatic one, computed 0083 //! from the specification 0084 Standard_EXPORT TCollection_AsciiString Definition() const; 0085 0086 //! Enforces a Definition 0087 Standard_EXPORT void SetDefinition(const char* const deftext); 0088 0089 //! Prints definition, specification, and actual status and value 0090 Standard_EXPORT virtual void Print(Standard_OStream& S) const; 0091 0092 //! Prints only the Value 0093 Standard_EXPORT void PrintValue(Standard_OStream& S) const; 0094 0095 //! Completes the definition of a TypedValue by command <initext>, 0096 //! once created with its type 0097 //! Returns True if done, False if could not be interpreted 0098 //! <initext> may be : 0099 //! imin ival : minimum value for an integer 0100 //! imax ival : maximum value for an integer 0101 //! rmin rval : minimum value for a real 0102 //! rmax rval : maximum value for a real 0103 //! unit name : name of unit 0104 //! ematch i : enum from integer value i, match required 0105 //! enum i : enum from integer value i, match not required 0106 //! eval text : add an enumerative value (increments max by 1) 0107 //! eval ?? : add a non-authorised enum value (to be skipped) 0108 //! tmax l : maximum length for a text 0109 Standard_EXPORT bool AddDef(const char* const initext); 0110 0111 //! Sets a label, which can then be displayed 0112 Standard_EXPORT void SetLabel(const char* const label); 0113 0114 //! Returns the label, if set; else returns an empty string 0115 Standard_EXPORT const char* Label() const; 0116 0117 //! Sets a maximum length for a text (active only for a free text) 0118 Standard_EXPORT void SetMaxLength(const int max); 0119 0120 //! Returns the maximum length, 0 if not set 0121 Standard_EXPORT int MaxLength() const; 0122 0123 //! Sets an Integer limit (included) to <val>, the upper limit 0124 //! if <max> is True, the lower limit if <max> is False 0125 Standard_EXPORT void SetIntegerLimit(const bool max, const int val); 0126 0127 //! Gives an Integer Limit (upper if <max> True, lower if <max> 0128 //! False). Returns True if this limit is defined, False else 0129 //! (in that case, gives the natural limit for Integer) 0130 Standard_EXPORT bool IntegerLimit(const bool max, int& val) const; 0131 0132 //! Sets a Real limit (included) to <val>, the upper limit 0133 //! if <max> is True, the lower limit if <max> is False 0134 Standard_EXPORT void SetRealLimit(const bool max, const double val); 0135 0136 //! Gives an Real Limit (upper if <max> True, lower if <max> 0137 //! False). Returns True if this limit is defined, False else 0138 //! (in that case, gives the natural limit for Real) 0139 Standard_EXPORT bool RealLimit(const bool max, double& val) const; 0140 0141 //! Sets (Clears if <def> empty) a unit definition, as an equation 0142 //! of dimensions. TypedValue just records this definition, does 0143 //! not exploit it, to be done as required by user applications 0144 Standard_EXPORT void SetUnitDef(const char* const def); 0145 0146 //! Returns the recorded unit definition, empty if not set 0147 Standard_EXPORT const char* UnitDef() const; 0148 0149 //! For an enumeration, precises the starting value (default 0) 0150 //! and the match condition : if True (D), the string value must 0151 //! match the definition, else it may take another value : in that 0152 //! case, the Integer Value will be Start - 1. 0153 //! (empty value remains allowed) 0154 Standard_EXPORT void StartEnum(const int start = 0, const bool match = true); 0155 0156 //! Adds enumerative definitions. For more than 10, several calls 0157 Standard_EXPORT void AddEnum(const char* const v1 = "", 0158 const char* const v2 = "", 0159 const char* const v3 = "", 0160 const char* const v4 = "", 0161 const char* const v5 = "", 0162 const char* const v6 = "", 0163 const char* const v7 = "", 0164 const char* const v8 = "", 0165 const char* const v9 = "", 0166 const char* const v10 = ""); 0167 0168 //! Adds an enumeration definition, by its string and numeric 0169 //! values. If it is the first setting for this value, it is 0170 //! recorded as main value. Else, it is recognized as alternate 0171 //! string for this numeric value 0172 Standard_EXPORT void AddEnumValue(const char* const val, const int num); 0173 0174 //! Gives the Enum definitions : start value, end value, match 0175 //! status. Returns True for an Enum, False else. 0176 Standard_EXPORT bool EnumDef(int& startcase, int& endcase, bool& match) const; 0177 0178 //! Returns the value of an enumerative definition, from its rank 0179 //! Empty string if out of range or not an Enum 0180 Standard_EXPORT const char* EnumVal(const int num) const; 0181 0182 //! Returns the case number which corresponds to a string value 0183 //! Works with main and additional values 0184 //! Returns (StartEnum - 1) if not OK, -1 if not an Enum 0185 Standard_EXPORT int EnumCase(const char* const val) const; 0186 0187 //! Sets type of which an Object TypedValue must be kind of 0188 //! Error for a TypedValue not an Object (Entity) 0189 Standard_EXPORT void SetObjectType(const occ::handle<Standard_Type>& typ); 0190 0191 //! Returns the type of which an Object TypedValue must be kind of 0192 //! Default is Standard_Transient 0193 //! Null for a TypedValue not an Object 0194 Standard_EXPORT occ::handle<Standard_Type> ObjectType() const; 0195 0196 //! Sets a specific Interpret function 0197 Standard_EXPORT void SetInterpret(const MoniTool_ValueInterpret func); 0198 0199 //! Tells if a TypedValue has an Interpret 0200 Standard_EXPORT virtual bool HasInterpret() const; 0201 0202 //! Sets a specific Satisfies function : it is added to the 0203 //! already defined criteria 0204 //! It must match the form : 0205 //! satisfies (val : HAsciiString) returns Boolean 0206 Standard_EXPORT void SetSatisfies(const MoniTool_ValueSatisfies func, const char* const name); 0207 0208 //! Returns name of specific satisfy, empty string if none 0209 Standard_EXPORT const char* SatisfiesName() const; 0210 0211 //! Returns True if the value is set (not empty/not null object) 0212 Standard_EXPORT bool IsSetValue() const; 0213 0214 //! Returns the value, as a cstring. Empty if not set. 0215 Standard_EXPORT const char* CStringValue() const; 0216 0217 //! Returns the value, as a Handle (can then be shared) 0218 //! Null if not defined 0219 Standard_EXPORT occ::handle<TCollection_HAsciiString> HStringValue() const; 0220 0221 //! Interprets a value. 0222 //! <native> True : returns a native value 0223 //! <native> False : returns a coded value 0224 //! If the Interpret function is set, calls it 0225 //! Else, for an Enum, Native returns the Text, Coded returns 0226 //! the number 0227 //! STANDARD RETURNS : = hval means no specific interpretation 0228 //! Null means senseless 0229 //! Can also be redefined 0230 Standard_EXPORT virtual occ::handle<TCollection_HAsciiString> Interpret( 0231 const occ::handle<TCollection_HAsciiString>& hval, 0232 const bool native) const; 0233 0234 //! Returns True if a value statifies the specification 0235 //! (remark : does not apply to Entity : see ObjectType, for this 0236 //! type, the string is just a comment) 0237 Standard_EXPORT virtual bool Satisfies(const occ::handle<TCollection_HAsciiString>& hval) const; 0238 0239 //! Clears the recorded Value : it is now unset 0240 Standard_EXPORT void ClearValue(); 0241 0242 //! Changes the value. The new one must satisfy the specification 0243 //! Returns False (and did not set) if the new value 0244 //! does not satisfy the specification 0245 //! Can be redefined to be managed (in a subclass) 0246 Standard_EXPORT virtual bool SetCStringValue(const char* const val); 0247 0248 //! Forces a new Handle for the Value 0249 //! It can be empty, else (if Type is not free Text), it must 0250 //! satisfy the specification. 0251 //! Not only the value is changed, but also the way it is shared 0252 //! Remark : for Type=Object, this value is not controlled, it can 0253 //! be set as a comment 0254 //! Returns False (and did not set) if the new value 0255 //! does not satisfy the specification 0256 //! Can be redefined to be managed (in a subclass) 0257 Standard_EXPORT virtual bool SetHStringValue(const occ::handle<TCollection_HAsciiString>& hval); 0258 0259 //! Returns the value as integer, i.e. : 0260 //! For type = Integer, the integer itself; 0 if not set 0261 //! For type = Enum, the designated rank (see Enum definition) 0262 //! StartEnum - 1 if not set or not in the definition 0263 //! Else, returns 0 0264 Standard_EXPORT int IntegerValue() const; 0265 0266 //! Changes the value as an integer, only for Integer or Enum 0267 Standard_EXPORT virtual bool SetIntegerValue(const int ival); 0268 0269 //! Returns the value as real, for a Real type TypedValue 0270 //! Else, returns 0. 0271 Standard_EXPORT double RealValue() const; 0272 0273 //! Changes the value as a real, only for Real 0274 Standard_EXPORT virtual bool SetRealValue(const double rval); 0275 0276 //! Returns the value as Transient Object, only for Object/Entity 0277 //! Remark that the "HString value" is IGNORED here 0278 //! Null if not set; remains to be casted 0279 Standard_EXPORT occ::handle<Standard_Transient> ObjectValue() const; 0280 0281 //! Same as ObjectValue, but avoids DownCast : the receiving 0282 //! variable is directly loaded. It is assumed that it complies 0283 //! with the definition of ObjectType ! Otherwise, big trouble 0284 Standard_EXPORT void GetObjectValue(occ::handle<Standard_Transient>& val) const; 0285 0286 //! Changes the value as Transient Object, only for Object/Entity 0287 //! Returns False if DynamicType does not satisfy ObjectType 0288 //! Can be redefined to be managed (in a subclass) 0289 Standard_EXPORT virtual bool SetObjectValue(const occ::handle<Standard_Transient>& obj); 0290 0291 //! Returns the type name of the ObjectValue, or an empty string 0292 //! if not set 0293 Standard_EXPORT const char* ObjectTypeName() const; 0294 0295 //! Adds a TypedValue in the library. 0296 //! It is recorded then will be accessed by its Name 0297 //! Its Definition may be imposed, else it is computed as usual 0298 //! By default it will be accessed by its Definition (string) 0299 //! Returns True if done, False if tv is Null or brings no 0300 //! Definition or <def> not defined 0301 //! 0302 //! If a TypedValue was already recorded under this name, it is 0303 //! replaced 0304 Standard_EXPORT static bool AddLib(const occ::handle<MoniTool_TypedValue>& tv, 0305 const char* const def = ""); 0306 0307 //! Returns the TypedValue bound with a given Name 0308 //! Null Handle if none recorded 0309 //! Warning: it is the original, not duplicated 0310 Standard_EXPORT static occ::handle<MoniTool_TypedValue> Lib(const char* const def); 0311 0312 //! Returns a COPY of the TypedValue bound with a given Name 0313 //! Null Handle if none recorded 0314 Standard_EXPORT static occ::handle<MoniTool_TypedValue> FromLib(const char* const def); 0315 0316 //! Returns the list of names of items of the Library of Types 0317 //! Library of TypedValue as Valued Parameters, accessed by 0318 //! parameter name for use by management of Static Parameters 0319 Standard_EXPORT static occ::handle<NCollection_HSequence<TCollection_AsciiString>> LibList(); 0320 0321 //! Returns a static value from its name, null if unknown 0322 Standard_EXPORT static occ::handle<MoniTool_TypedValue> StaticValue(const char* const name); 0323 0324 DEFINE_STANDARD_RTTIEXT(MoniTool_TypedValue, Standard_Transient) 0325 0326 protected: 0327 //! Gives the internal library of static values 0328 Standard_EXPORT static NCollection_DataMap<TCollection_AsciiString, 0329 occ::handle<Standard_Transient>>& 0330 Stats(); 0331 0332 private: 0333 TCollection_AsciiString thename; 0334 TCollection_AsciiString thedef; 0335 TCollection_AsciiString thelabel; 0336 MoniTool_ValueType thetype; 0337 occ::handle<Standard_Type> theotyp; 0338 int thelims; 0339 int themaxlen; 0340 int theintlow; 0341 int theintup; 0342 double therealow; 0343 double therealup; 0344 TCollection_AsciiString theunidef; 0345 occ::handle<NCollection_HArray1<TCollection_AsciiString>> theenums; 0346 NCollection_DataMap<TCollection_AsciiString, int> theeadds; 0347 MoniTool_ValueInterpret theinterp; 0348 MoniTool_ValueSatisfies thesatisf; 0349 TCollection_AsciiString thesatisn; 0350 int theival; 0351 occ::handle<TCollection_HAsciiString> thehval; 0352 occ::handle<Standard_Transient> theoval; 0353 }; 0354 0355 #endif // _MoniTool_TypedValue_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|