Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:23

0001 // Copyright (c) 2022 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _DE_ConfigurationContext_HeaderFile
0015 #define _DE_ConfigurationContext_HeaderFile
0016 
0017 #include <NCollection_DataMap.hxx>
0018 #include <TColStd_ListOfAsciiString.hxx>
0019 
0020 typedef NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> DE_ResourceMap;
0021 
0022 //! Provides convenient interface to resource file
0023 //! Allows loading of the resource file and getting attributes' 
0024 //! values starting from some scope, for example
0025 //! if scope is defined as "ToV4" and requested parameter
0026 //! is "exec.op", value of "ToV4.exec.op" parameter from
0027 //! the resource file will be returned
0028 class DE_ConfigurationContext : public Standard_Transient
0029 {
0030 public:
0031   DEFINE_STANDARD_RTTIEXT(DE_ConfigurationContext, Standard_Transient)
0032 
0033   //! Creates an empty tool
0034   Standard_EXPORT DE_ConfigurationContext();
0035 
0036   //! Import the custom configuration
0037   //! Save all parameters with their values.
0038   //! @param[in] theConfiguration path to configuration file or string value
0039   //! @return true in case of success, false otherwise
0040   Standard_EXPORT Standard_Boolean Load(const TCollection_AsciiString& theConfiguration);
0041 
0042   //! Import the resource file.
0043   //! Save all parameters with their values.
0044   //! @param[in] theFile path to the resource file
0045   //! @return true in case of success, false otherwise
0046   Standard_EXPORT Standard_Boolean LoadFile(const TCollection_AsciiString& theFile);
0047 
0048   //! Import the resource string.
0049   //! Save all parameters with their values.
0050   //! @param[in] theResource string with resource content
0051   //! @return true in case of success, false otherwise
0052   Standard_EXPORT Standard_Boolean LoadStr(const TCollection_AsciiString& theResource);
0053 
0054   //! Checks for existing the parameter name
0055   //! @param[in] theParam complex parameter name
0056   //! @param[in] theScope base parameter name
0057   //! @return Standard_True if parameter is defined in the resource file
0058   Standard_EXPORT Standard_Boolean IsParamSet(const TCollection_AsciiString& theParam,
0059                                               const TCollection_AsciiString& theScope = "") const;
0060 
0061   //! Gets value of parameter as being of specific type
0062   //! @param[in] theParam complex parameter name
0063   //! @param[out] theValue value to get by parameter
0064   //! @param[in] theScope base parameter name
0065   //! @return Standard_False if parameter is not defined or has a wrong type
0066   Standard_EXPORT Standard_Boolean GetReal(const TCollection_AsciiString& theParam,
0067                                            Standard_Real& theValue,
0068                                            const TCollection_AsciiString& theScope = "") const;
0069 
0070   //! Gets value of parameter as being of specific type
0071   //! @param[in] theParam complex parameter name
0072   //! @param[out] theValue value to get by parameter
0073   //! @param[in] theScope base parameter name
0074   //! @return Standard_False if parameter is not defined or has a wrong type
0075   Standard_EXPORT Standard_Boolean GetInteger(const TCollection_AsciiString& theParam,
0076                                               Standard_Integer& theValue,
0077                                               const TCollection_AsciiString& theScope = "") const;
0078 
0079   //! Gets value of parameter as being of specific type
0080   //! @param[in] theParam complex parameter name
0081   //! @param[out] theValue value to get by parameter
0082   //! @param[in] theScope base parameter name
0083   //! @return Standard_False if parameter is not defined or has a wrong type
0084   Standard_EXPORT Standard_Boolean GetBoolean(const TCollection_AsciiString& theParam,
0085                                               Standard_Boolean& theValue,
0086                                               const TCollection_AsciiString& theScope = "") const;
0087 
0088   //! Gets value of parameter as being of specific type
0089   //! @param[in] theParam complex parameter name
0090   //! @param[out] theValue value to get by parameter
0091   //! @param[in] theScope base parameter name
0092   //! @return Standard_False if parameter is not defined or has a wrong type
0093   Standard_EXPORT Standard_Boolean GetString(const TCollection_AsciiString& theParam,
0094                                              TCollection_AsciiString& theValue,
0095                                              const TCollection_AsciiString& theScope = "") const;
0096 
0097   //! Gets value of parameter as being of specific type
0098   //! @param[in] theParam complex parameter name
0099   //! @param[out] theValue value to get by parameter
0100   //! @param[in] theScope base parameter name
0101   //! @return Standard_False if parameter is not defined or has a wrong type
0102   Standard_EXPORT Standard_Boolean GetStringSeq(const TCollection_AsciiString& theParam,
0103                                                 TColStd_ListOfAsciiString& theValue,
0104                                                 const TCollection_AsciiString& theScope = "") const;
0105 
0106   //! Gets value of parameter as being of specific type
0107   //! @param[in] theParam complex parameter name
0108   //! @param[in] theDefValue value by default if param is not found or has wrong type
0109   //! @param[in] theScope base parameter name
0110   //! @return specific type value
0111   Standard_EXPORT Standard_Real RealVal(const TCollection_AsciiString& theParam,
0112                                         const Standard_Real theDefValue,
0113                                         const TCollection_AsciiString& theScope = "") const;
0114 
0115   //! Gets value of parameter as being of specific type
0116   //! @param[in] theParam complex parameter name
0117   //! @param[in] theDefValue value by default if param is not found or has wrong type
0118   //! @param[in] theScope base parameter name
0119   //! @return specific type value
0120   Standard_EXPORT Standard_Integer IntegerVal(const TCollection_AsciiString& theParam,
0121                                               const Standard_Integer theDefValue,
0122                                               const TCollection_AsciiString& theScope = "") const;
0123 
0124   //! Gets value of parameter as being of specific type
0125   //! @param[in] theParam complex parameter name
0126   //! @param[in] theDefValue value by default if param is not found or has wrong type
0127   //! @param[in] theScope base parameter name
0128   //! @return specific type value
0129   Standard_EXPORT Standard_Boolean BooleanVal(const TCollection_AsciiString& theParam,
0130                                               const Standard_Boolean theDefValue,
0131                                               const TCollection_AsciiString& theScope = "") const;
0132 
0133   //! Gets value of parameter as being of specific type
0134   //! @param[in] theParam complex parameter name
0135   //! @param[in] theDefValue value by default if param is not found or has wrong type
0136   //! @param[in] theScope base parameter name
0137   //! @return specific type value
0138   Standard_EXPORT TCollection_AsciiString StringVal(const TCollection_AsciiString& theParam,
0139                                                     const TCollection_AsciiString& theDefValue,
0140                                                     const TCollection_AsciiString& theScope = "") const;
0141 
0142   //! Gets internal resource map
0143   //! @return map with resource value
0144   Standard_EXPORT const DE_ResourceMap& GetInternalMap() const { return myResource; }
0145 
0146 protected:
0147 
0148   //! Update the resource with param value from the line
0149   //! @paramp[in] theResourceLine line contains the parameter
0150   //! @return true if theResourceLine has loaded correctly
0151   Standard_Boolean load(const TCollection_AsciiString& theResourceLine);
0152 
0153 private:
0154 
0155   DE_ResourceMap myResource; //!< Internal parameters map
0156 
0157 };
0158 
0159 #endif // _DE_ConfigurationContext_HeaderFile