Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:21:49

0001 // Created on: 1995-04-20
0002 // Created by: Tony GEORGIADES
0003 // Copyright (c) 1995-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 _Resource_Manager_HeaderFile
0018 #define _Resource_Manager_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 #include <TCollection_AsciiString.hxx>
0024 #include <NCollection_DataMap.hxx>
0025 #include <TCollection_ExtendedString.hxx>
0026 #include <Standard_Boolean.hxx>
0027 #include <Standard_Transient.hxx>
0028 #include <Standard_CString.hxx>
0029 #include <Standard_Integer.hxx>
0030 #include <Standard_Real.hxx>
0031 
0032 //! Defines a resource structure and its management methods.
0033 class Resource_Manager : public Standard_Transient
0034 {
0035   DEFINE_STANDARD_RTTIEXT(Resource_Manager, Standard_Transient)
0036 public:
0037   //! Create a Resource manager.
0038   //! Attempts to find the two following files:
0039   //! $CSF_`aName`Defaults/aName
0040   //! $CSF_`aName`UserDefaults/aName
0041   //! and load them respectively into a reference and a user resource structure.
0042   //!
0043   //! If CSF_ResourceVerbose defined, seeked files will be printed.
0044   //!
0045   //! FILE SYNTAX
0046   //! The syntax of a resource file is a sequence of resource
0047   //! lines terminated by newline characters or end of file. The
0048   //! syntax of an individual resource line is:
0049   Standard_EXPORT Resource_Manager(const char* const aName, const bool Verbose = false);
0050 
0051   //! Create an empty Resource manager
0052   Standard_EXPORT Resource_Manager();
0053 
0054   //! Create a Resource manager.
0055   //! @param[in] theName  description file name
0056   //! @param[in] theDefaultsDirectory   default folder for looking description file
0057   //! @param[in] theUserDefaultsDirectory  user folder for looking description file
0058   //! @param[in] theIsVerbose  print verbose messages
0059   Standard_EXPORT Resource_Manager(const TCollection_AsciiString& theName,
0060                                    const TCollection_AsciiString& theDefaultsDirectory,
0061                                    const TCollection_AsciiString& theUserDefaultsDirectory,
0062                                    const bool                     theIsVerbose = false);
0063 
0064   //! Save the user resource structure in the specified file.
0065   //! Creates the file if it does not exist.
0066   Standard_EXPORT bool Save() const;
0067 
0068   //! returns True if the Resource does exist.
0069   Standard_EXPORT bool Find(const char* const aResource) const;
0070 
0071   //! returns True if the Resource does exist.
0072   Standard_EXPORT bool Find(const TCollection_AsciiString& theResource,
0073                             TCollection_AsciiString&       theValue) const;
0074 
0075   //! Gets the value of an integer resource according to its
0076   //! instance and its type.
0077   Standard_EXPORT virtual int Integer(const char* const aResourceName) const;
0078 
0079   //! Gets the value of a real resource according to its instance
0080   //! and its type.
0081   Standard_EXPORT virtual double Real(const char* const aResourceName) const;
0082 
0083   //! Gets the value of a CString resource according to its instance
0084   //! and its type.
0085   Standard_EXPORT virtual const char* Value(const char* const aResourceName) const;
0086 
0087   //! Gets the value of an ExtString resource according to its instance
0088   //! and its type.
0089   Standard_EXPORT virtual const char16_t* ExtValue(const char* const aResourceName);
0090 
0091   //! Sets the new value of an integer resource.
0092   //! If the resource does not exist, it is created.
0093   Standard_EXPORT virtual void SetResource(const char* const aResourceName, const int aValue);
0094 
0095   //! Sets the new value of a real resource.
0096   //! If the resource does not exist, it is created.
0097   Standard_EXPORT virtual void SetResource(const char* const aResourceName, const double aValue);
0098 
0099   //! Sets the new value of an CString resource.
0100   //! If the resource does not exist, it is created.
0101   Standard_EXPORT virtual void SetResource(const char* const aResourceName,
0102                                            const char* const aValue);
0103 
0104   //! Sets the new value of an ExtString resource.
0105   //! If the resource does not exist, it is created.
0106   Standard_EXPORT virtual void SetResource(const char* const     aResourceName,
0107                                            const char16_t* const aValue);
0108 
0109   //! Gets the resource file full path by its name.
0110   //! If corresponding environment variable is not set
0111   //! or file doesn't exist returns empty string.
0112   Standard_EXPORT static void GetResourcePath(TCollection_AsciiString& aPath,
0113                                               const char* const        aName,
0114                                               const bool               isUserDefaults);
0115 
0116   //! Returns internal Ref or User map with parameters
0117   Standard_EXPORT NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>& GetMap(
0118     bool theRefMap = true);
0119 
0120   //! Returns true if Resource have been found
0121   bool IsInitialized() const { return myInitialized; }
0122 
0123 private:
0124   Standard_EXPORT void Load(
0125     const TCollection_AsciiString&                                         thePath,
0126     NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>& aMap);
0127 
0128 private:
0129   TCollection_AsciiString                                                  myName;
0130   NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>    myRefMap;
0131   NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>    myUserMap;
0132   NCollection_DataMap<TCollection_AsciiString, TCollection_ExtendedString> myExtStrMap;
0133   bool                                                                     myVerbose;
0134   bool                                                                     myInitialized;
0135 };
0136 
0137 #endif // _Resource_Manager_HeaderFile