Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:17

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 <TColStd_HArray1OfAsciiString.hxx>
0028 #include <MoniTool_ValueInterpret.hxx>
0029 #include <MoniTool_ValueSatisfies.hxx>
0030 #include <Standard_Transient.hxx>
0031 #include <TColStd_HSequenceOfAsciiString.hxx>
0032 class TCollection_HAsciiString;
0033 
0034 class MoniTool_TypedValue;
0035 DEFINE_STANDARD_HANDLE(MoniTool_TypedValue, Standard_Transient)
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 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 
0054   
0055   //! Creates a TypedValue, with a name
0056   //!
0057   //! type gives the type of the parameter, default is free text
0058   //! Also available : Integer, Real, Enum, Entity (i.e. Object)
0059   //! More precise specifications, titles, can be given to the
0060   //! TypedValue once created
0061   //!
0062   //! init gives an initial value. If it is not given, the
0063   //! TypedValue begins as "not set", its value is empty
0064   Standard_EXPORT MoniTool_TypedValue(const Standard_CString name, const MoniTool_ValueType type = MoniTool_ValueText, const Standard_CString init = "");
0065   
0066   //! Creates a TypedValue from another one, by duplication
0067   Standard_EXPORT MoniTool_TypedValue(const Handle(MoniTool_TypedValue)& other);
0068   
0069   //! Access to internal data which have no other access
0070   Standard_EXPORT void Internals (MoniTool_ValueInterpret& interp, MoniTool_ValueSatisfies& satisf, Standard_CString& satisname, NCollection_DataMap<TCollection_AsciiString, Standard_Integer>& enums) const;
0071   
0072   //! Returns the name
0073   Standard_EXPORT Standard_CString Name() const;
0074   
0075   //! Returns the type of the value
0076   Standard_EXPORT MoniTool_ValueType ValueType() const;
0077   
0078   //! Returns the Definition
0079   //! By priority, the enforced one, else an automatic one, computed
0080   //! from the specification
0081   Standard_EXPORT TCollection_AsciiString Definition() const;
0082   
0083   //! Enforces a Definition
0084   Standard_EXPORT void SetDefinition (const Standard_CString deftext);
0085   
0086   //! Prints definition, specification, and actual status and value
0087   Standard_EXPORT virtual void Print (Standard_OStream& S) const;
0088   
0089   //! Prints only the Value
0090   Standard_EXPORT void PrintValue (Standard_OStream& S) const;
0091   
0092   //! Completes the definition of a TypedValue by command <initext>,
0093   //! once created with its type
0094   //! Returns True if done, False if could not be interpreted
0095   //! <initext> may be :
0096   //! imin ival : minimum value for an integer
0097   //! imax ival : maximum value for an integer
0098   //! rmin rval : minimum value for a real
0099   //! rmax rval : maximum value for a real
0100   //! unit name : name of unit
0101   //! ematch i  : enum from integer value i, match required
0102   //! enum   i  : enum from integer value i, match not required
0103   //! eval text : add an enumerative value (increments max by 1)
0104   //! eval ??   : add a non-authorised enum value (to be skipped)
0105   //! tmax   l  : maximum length for a text
0106   Standard_EXPORT Standard_Boolean AddDef (const Standard_CString initext);
0107   
0108   //! Sets a label, which can then be displayed
0109   Standard_EXPORT void SetLabel (const Standard_CString label);
0110   
0111   //! Returns the label, if set; else returns an empty string
0112   Standard_EXPORT Standard_CString Label() const;
0113   
0114   //! Sets a maximum length for a text (active only for a free text)
0115   Standard_EXPORT void SetMaxLength (const Standard_Integer max);
0116   
0117   //! Returns the maximum length, 0 if not set
0118   Standard_EXPORT Standard_Integer MaxLength() const;
0119   
0120   //! Sets an Integer limit (included) to <val>, the upper limit
0121   //! if <max> is True, the lower limit if <max> is False
0122   Standard_EXPORT void SetIntegerLimit (const Standard_Boolean max, const Standard_Integer val);
0123   
0124   //! Gives an Integer Limit (upper if <max> True, lower if <max>
0125   //! False). Returns True if this limit is defined, False else
0126   //! (in that case, gives the natural limit for Integer)
0127   Standard_EXPORT Standard_Boolean IntegerLimit (const Standard_Boolean max, Standard_Integer& val) const;
0128   
0129   //! Sets a Real limit (included) to <val>, the upper limit
0130   //! if <max> is True, the lower limit if <max> is False
0131   Standard_EXPORT void SetRealLimit (const Standard_Boolean max, const Standard_Real val);
0132   
0133   //! Gives an Real Limit (upper if <max> True, lower if <max>
0134   //! False). Returns True if this limit is defined, False else
0135   //! (in that case, gives the natural limit for Real)
0136   Standard_EXPORT Standard_Boolean RealLimit (const Standard_Boolean max, Standard_Real& val) const;
0137   
0138   //! Sets (Clears if <def> empty) a unit definition, as an equation
0139   //! of dimensions. TypedValue just records this definition, does
0140   //! not exploit it, to be done as required by user applications
0141   Standard_EXPORT void SetUnitDef (const Standard_CString def);
0142   
0143   //! Returns the recorded unit definition, empty if not set
0144   Standard_EXPORT Standard_CString UnitDef() const;
0145   
0146   //! For an enumeration, precises the starting value (default 0)
0147   //! and the match condition : if True (D), the string value must
0148   //! match the definition, else it may take another value : in that
0149   //! case, the Integer Value will be  Start - 1.
0150   //! (empty value remains allowed)
0151   Standard_EXPORT void StartEnum (const Standard_Integer start = 0, const Standard_Boolean match = Standard_True);
0152   
0153   //! Adds enumerative definitions. For more than 10, several calls
0154   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 = "");
0155   
0156   //! Adds an enumeration definition, by its string and numeric
0157   //! values. If it is the first setting for this value, it is
0158   //! recorded as main value. Else, it is recognized as alternate
0159   //! string for this numeric value
0160   Standard_EXPORT void AddEnumValue (const Standard_CString val, const Standard_Integer num);
0161   
0162   //! Gives the Enum definitions : start value, end value, match
0163   //! status. Returns True for an Enum, False else.
0164   Standard_EXPORT Standard_Boolean EnumDef (Standard_Integer& startcase, Standard_Integer& endcase, Standard_Boolean& match) const;
0165   
0166   //! Returns the value of an enumerative definition, from its rank
0167   //! Empty string if out of range or not an Enum
0168   Standard_EXPORT Standard_CString EnumVal (const Standard_Integer num) const;
0169   
0170   //! Returns the case number which corresponds to a string value
0171   //! Works with main and additional values
0172   //! Returns (StartEnum - 1) if not OK, -1 if not an Enum
0173   Standard_EXPORT Standard_Integer EnumCase (const Standard_CString val) const;
0174   
0175   //! Sets type of which an Object TypedValue must be kind of
0176   //! Error for a TypedValue not an Object (Entity)
0177   Standard_EXPORT void SetObjectType (const Handle(Standard_Type)& typ);
0178   
0179   //! Returns the type of which an Object TypedValue must be kind of
0180   //! Default is Standard_Transient
0181   //! Null for a TypedValue not an Object
0182   Standard_EXPORT Handle(Standard_Type) ObjectType() const;
0183   
0184   //! Sets a specific Interpret function
0185   Standard_EXPORT void SetInterpret (const MoniTool_ValueInterpret func);
0186   
0187   //! Tells if a TypedValue has an Interpret
0188   Standard_EXPORT virtual Standard_Boolean HasInterpret() const;
0189   
0190   //! Sets a specific Satisfies function : it is added to the
0191   //! already defined criteria
0192   //! It must match the form :
0193   //! satisfies (val : HAsciiString) returns Boolean
0194   Standard_EXPORT void SetSatisfies (const MoniTool_ValueSatisfies func, const Standard_CString name);
0195   
0196   //! Returns name of specific satisfy, empty string if none
0197   Standard_EXPORT Standard_CString SatisfiesName() const;
0198   
0199   //! Returns True if the value is set (not empty/not null object)
0200   Standard_EXPORT Standard_Boolean IsSetValue() const;
0201   
0202   //! Returns the value, as a cstring. Empty if not set.
0203   Standard_EXPORT Standard_CString CStringValue() const;
0204   
0205   //! Returns the value, as a Handle (can then be shared)
0206   //! Null if not defined
0207   Standard_EXPORT Handle(TCollection_HAsciiString) HStringValue() const;
0208   
0209   //! Interprets a value.
0210   //! <native> True  : returns a native value
0211   //! <native> False : returns a coded  value
0212   //! If the Interpret function is set, calls it
0213   //! Else, for an Enum, Native returns the Text, Coded returns
0214   //! the number
0215   //! STANDARD RETURNS : = hval means no specific interpretation
0216   //! Null means senseless
0217   //! Can also be redefined
0218   Standard_EXPORT virtual Handle(TCollection_HAsciiString) Interpret (const Handle(TCollection_HAsciiString)& hval, const Standard_Boolean native) const;
0219   
0220   //! Returns True if a value statifies the specification
0221   //! (remark : does not apply to Entity : see ObjectType, for this
0222   //! type, the string is just a comment)
0223   Standard_EXPORT virtual Standard_Boolean Satisfies (const Handle(TCollection_HAsciiString)& hval) const;
0224   
0225   //! Clears the recorded Value : it is now unset
0226   Standard_EXPORT void ClearValue();
0227   
0228   //! Changes the value. The new one must satisfy the specification
0229   //! Returns False (and did not set) if the new value
0230   //! does not satisfy the specification
0231   //! Can be redefined to be managed (in a subclass)
0232   Standard_EXPORT virtual Standard_Boolean SetCStringValue (const Standard_CString val);
0233   
0234   //! Forces a new Handle for the Value
0235   //! It can be empty, else (if Type is not free Text), it must
0236   //! satisfy the specification.
0237   //! Not only the value is changed, but also the way it is shared
0238   //! Remark : for Type=Object, this value is not controlled, it can
0239   //! be set as a comment
0240   //! Returns False (and did not set) if the new value
0241   //! does not satisfy the specification
0242   //! Can be redefined to be managed (in a subclass)
0243   Standard_EXPORT virtual Standard_Boolean SetHStringValue (const Handle(TCollection_HAsciiString)& hval);
0244   
0245   //! Returns the value as integer, i.e. :
0246   //! For type = Integer, the integer itself; 0 if not set
0247   //! For type = Enum, the designated rank (see Enum definition)
0248   //! StartEnum - 1 if not set or not in the definition
0249   //! Else, returns 0
0250   Standard_EXPORT Standard_Integer IntegerValue() const;
0251   
0252   //! Changes the value as an integer, only for Integer or Enum
0253   Standard_EXPORT virtual Standard_Boolean SetIntegerValue (const Standard_Integer ival);
0254   
0255   //! Returns the value as real,  for a Real type TypedValue
0256   //! Else, returns 0.
0257   Standard_EXPORT Standard_Real RealValue() const;
0258   
0259   //! Changes the value as a real, only for Real
0260   Standard_EXPORT virtual Standard_Boolean SetRealValue (const Standard_Real rval);
0261   
0262   //! Returns the value as Transient Object, only for Object/Entity
0263   //! Remark that the "HString value" is IGNORED here
0264   //! Null if not set; remains to be casted
0265   Standard_EXPORT Handle(Standard_Transient) ObjectValue() const;
0266   
0267   //! Same as ObjectValue, but avoids DownCast : the receiving
0268   //! variable is directly loaded. It is assumed that it complies
0269   //! with the definition of ObjectType ! Otherwise, big trouble
0270   Standard_EXPORT void GetObjectValue (Handle(Standard_Transient)& val) const;
0271   
0272   //! Changes the value as Transient Object, only for Object/Entity
0273   //! Returns False if DynamicType does not satisfy ObjectType
0274   //! Can be redefined to be managed (in a subclass)
0275   Standard_EXPORT virtual Standard_Boolean SetObjectValue (const Handle(Standard_Transient)& obj);
0276   
0277   //! Returns the type name of the ObjectValue, or an empty string
0278   //! if not set
0279   Standard_EXPORT Standard_CString ObjectTypeName() const;
0280   
0281   //! Adds a TypedValue in the library.
0282   //! It is recorded then will be accessed by its Name
0283   //! Its Definition may be imposed, else it is computed as usual
0284   //! By default it will be accessed by its Definition (string)
0285   //! Returns True if done, False if tv is Null or brings no
0286   //! Definition or <def> not defined
0287   //!
0288   //! If a TypedValue was already recorded under this name, it is
0289   //! replaced
0290   Standard_EXPORT static Standard_Boolean AddLib (const Handle(MoniTool_TypedValue)& tv, const Standard_CString def = "");
0291   
0292   //! Returns the TypedValue bound with a given Name
0293   //! Null Handle if none recorded
0294   //! Warning : it is the original, not duplicated
0295   Standard_EXPORT static Handle(MoniTool_TypedValue) Lib (const Standard_CString def);
0296   
0297   //! Returns a COPY of the TypedValue bound with a given Name
0298   //! Null Handle if none recorded
0299   Standard_EXPORT static Handle(MoniTool_TypedValue) FromLib (const Standard_CString def);
0300   
0301   //! Returns the list of names of items of the Library of Types
0302   //! --    Library of TypedValue as Valued Parameters,    -- --
0303   //! accessed by parameter name
0304   //! for use by management of Static Parameters
0305   Standard_EXPORT static Handle(TColStd_HSequenceOfAsciiString) LibList();
0306   
0307   //! Returns a static value from its name, null if unknown
0308   Standard_EXPORT static Handle(MoniTool_TypedValue) StaticValue (const Standard_CString name);
0309 
0310 
0311 
0312 
0313   DEFINE_STANDARD_RTTIEXT(MoniTool_TypedValue,Standard_Transient)
0314 
0315 protected:
0316 
0317   
0318   //! Gives the internal library of static values
0319   Standard_EXPORT static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& Stats();
0320 
0321 
0322 
0323 private:
0324 
0325 
0326   TCollection_AsciiString thename;
0327   TCollection_AsciiString thedef;
0328   TCollection_AsciiString thelabel;
0329   MoniTool_ValueType thetype;
0330   Handle(Standard_Type) theotyp;
0331   Standard_Integer thelims;
0332   Standard_Integer themaxlen;
0333   Standard_Integer theintlow;
0334   Standard_Integer theintup;
0335   Standard_Real therealow;
0336   Standard_Real therealup;
0337   TCollection_AsciiString theunidef;
0338   Handle(TColStd_HArray1OfAsciiString) theenums;
0339   NCollection_DataMap<TCollection_AsciiString, Standard_Integer> theeadds;
0340   MoniTool_ValueInterpret theinterp;
0341   MoniTool_ValueSatisfies thesatisf;
0342   TCollection_AsciiString thesatisn;
0343   Standard_Integer theival;
0344   Handle(TCollection_HAsciiString) thehval;
0345   Handle(Standard_Transient) theoval;
0346 
0347 
0348 };
0349 
0350 
0351 
0352 
0353 
0354 
0355 
0356 #endif // _MoniTool_TypedValue_HeaderFile