1 // Created on: 1995-04-20
2 // Created by: Tony GEORGIADES
3 // Copyright (c) 1995-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 _Resource_Manager_HeaderFile
18 #define _Resource_Manager_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
25 #include <Resource_DataMapOfAsciiStringExtendedString.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Transient.hxx>
28 #include <Standard_CString.hxx>
29 #include <Standard_Integer.hxx>
30 #include <Standard_Real.hxx>
31 #include <Standard_ExtString.hxx>
32 class Standard_TypeMismatch;
33 class Resource_NoSuchResource;
34 class Standard_OutOfRange;
35 class TCollection_AsciiString;
38 class Resource_Manager;
39 DEFINE_STANDARD_HANDLE(Resource_Manager, Standard_Transient)
41 //! Defines a resource structure and its management methods.
42 class Resource_Manager : public Standard_Transient
48 //! Create a Resource manager.
49 //! Attempts to find the two following files:
50 //! $CSF_`aName`Defaults/aName
51 //! $CSF_`aName`UserDefaults/aName
52 //! and load them respectively into a reference and a user resource structure.
54 //! If CSF_ResourceVerbose defined, seeked files will be printed.
57 //! The syntax of a resource file is a sequence of resource
58 //! lines terminated by newline characters or end of file. The
59 //! syntax of an individual resource line is:
60 Standard_EXPORT Resource_Manager(const Standard_CString aName, const Standard_Boolean Verbose = Standard_False);
62 Standard_EXPORT Resource_Manager(const Standard_CString aName, TCollection_AsciiString& aDefaultsDirectory, TCollection_AsciiString& anUserDefaultsDirectory, const Standard_Boolean Verbose = Standard_False);
64 //! Save the user resource structure in the specified file.
65 //! Creates the file if it does not exist.
66 Standard_EXPORT Standard_Boolean Save() const;
68 //! returns True if the Resource does exist.
69 Standard_EXPORT Standard_Boolean Find (const Standard_CString aResource) const;
71 //! Gets the value of an integer resource according to its
72 //! instance and its type.
73 Standard_EXPORT virtual Standard_Integer Integer (const Standard_CString aResourceName) const;
75 //! Gets the value of a real resource according to its instance
77 Standard_EXPORT virtual Standard_Real Real (const Standard_CString aResourceName) const;
79 //! Gets the value of a CString resource according to its instance
81 Standard_EXPORT virtual Standard_CString Value (const Standard_CString aResourceName) const;
83 //! Gets the value of an ExtString resource according to its instance
85 Standard_EXPORT virtual Standard_ExtString ExtValue (const Standard_CString aResourceName);
87 //! Sets the new value of an integer resource.
88 //! If the resource does not exist, it is created.
89 Standard_EXPORT virtual void SetResource (const Standard_CString aResourceName, const Standard_Integer aValue);
91 //! Sets the new value of a real resource.
92 //! If the resource does not exist, it is created.
93 Standard_EXPORT virtual void SetResource (const Standard_CString aResourceName, const Standard_Real aValue);
95 //! Sets the new value of an CString resource.
96 //! If the resource does not exist, it is created.
97 Standard_EXPORT virtual void SetResource (const Standard_CString aResourceName, const Standard_CString aValue);
99 //! Sets the new value of an ExtString resource.
100 //! If the resource does not exist, it is created.
101 Standard_EXPORT virtual void SetResource (const Standard_CString aResourceName, const Standard_ExtString aValue);
103 //! Gets the resource file full path by its name.
104 //! If corresponding environment variable is not set
105 //! or file doesn't exist returns empty string.
106 Standard_EXPORT static void GetResourcePath (TCollection_AsciiString& aPath, const Standard_CString aName, const Standard_Boolean isUserDefaults);
111 DEFINE_STANDARD_RTTIEXT(Resource_Manager,Standard_Transient)
121 Standard_EXPORT void Load (TCollection_AsciiString& aPath, Resource_DataMapOfAsciiStringAsciiString& aMap);
123 TCollection_AsciiString myName;
124 Resource_DataMapOfAsciiStringAsciiString myRefMap;
125 Resource_DataMapOfAsciiStringAsciiString myUserMap;
126 Resource_DataMapOfAsciiStringExtendedString myExtStrMap;
127 Standard_Boolean myVerbose;
138 #endif // _Resource_Manager_HeaderFile