diff options
author | fluxgen <fluxgen> | 2003-05-10 13:45:50 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-05-10 13:45:50 (GMT) |
commit | 4f806e266a24188bc472cf1c2bb1e8512821b968 (patch) | |
tree | b3a6d06f6b9b37bf1108528563e10101b839c07e /src/Resource.hh | |
parent | 79e8404cbf326f66379f06b9f86e59266721b454 (diff) | |
download | fluxbox-4f806e266a24188bc472cf1c2bb1e8512821b968.zip fluxbox-4f806e266a24188bc472cf1c2bb1e8512821b968.tar.bz2 |
comments
Diffstat (limited to 'src/Resource.hh')
-rw-r--r-- | src/Resource.hh | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/Resource.hh b/src/Resource.hh index 0ea2dd1..d657b5b 100644 --- a/src/Resource.hh +++ b/src/Resource.hh | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: Resource.hh,v 1.11 2003/05/07 11:32:42 fluxgen Exp $ | 22 | // $Id: Resource.hh,v 1.12 2003/05/10 13:44:24 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef RESOURCE_HH | 24 | #ifndef RESOURCE_HH |
25 | #define RESOURCE_HH | 25 | #define RESOURCE_HH |
@@ -27,9 +27,8 @@ | |||
27 | #include "NotCopyable.hh" | 27 | #include "NotCopyable.hh" |
28 | #include <string> | 28 | #include <string> |
29 | #include <list> | 29 | #include <list> |
30 | /** | 30 | |
31 | Base class for resources | 31 | /// Base class for resources, this is only used in ResourceManager |
32 | */ | ||
33 | class Resource_base:private FbTk::NotCopyable | 32 | class Resource_base:private FbTk::NotCopyable |
34 | { | 33 | { |
35 | public: | 34 | public: |
@@ -66,40 +65,47 @@ public: | |||
66 | 65 | ||
67 | ResourceManager() { } | 66 | ResourceManager() { } |
68 | virtual ~ResourceManager() {} | 67 | virtual ~ResourceManager() {} |
69 | /** | 68 | |
70 | load all resouces registered to this class | 69 | /// Load all resources registered to this class |
71 | */ | 70 | /// @return true on success |
72 | virtual bool load(const char *filename); | 71 | virtual bool load(const char *filename); |
73 | /** | 72 | |
74 | save all resouces registered to this class | 73 | /// Save all resouces registered to this class |
75 | */ | 74 | /// @return true on success |
76 | virtual bool save(const char *filename, const char *mergefilename=0); | 75 | virtual bool save(const char *filename, const char *mergefilename=0); |
77 | /** | 76 | |
78 | add resource to list | 77 | /// Add resource to list, only used in Resource<T> |
79 | */ | ||
80 | template <class T> | 78 | template <class T> |
81 | void addResource(Resource<T> &r) { | 79 | void addResource(Resource<T> &r) { |
82 | m_resourcelist.push_back(&r); | 80 | m_resourcelist.push_back(&r); |
83 | m_resourcelist.unique(); | 81 | m_resourcelist.unique(); |
84 | } | 82 | } |
85 | /** | 83 | |
86 | Remove a specific resource | 84 | /// Remove a specific resource, only used in Resource<T> |
87 | */ | ||
88 | template <class T> | 85 | template <class T> |
89 | void removeResource(Resource<T> &r) { | 86 | void removeResource(Resource<T> &r) { |
90 | m_resourcelist.remove(&r); | 87 | m_resourcelist.remove(&r); |
91 | } | 88 | } |
89 | |||
92 | protected: | 90 | protected: |
93 | static void ensureXrmIsInitialize(); | 91 | static void ensureXrmIsInitialize(); |
94 | private: | ||
95 | 92 | ||
93 | private: | ||
96 | static bool m_init; | 94 | static bool m_init; |
97 | ResourceList m_resourcelist; | 95 | ResourceList m_resourcelist; |
98 | }; | 96 | }; |
99 | 97 | ||
98 | |||
99 | /// Real resource class | ||
100 | /** | 100 | /** |
101 | Real resource class | 101 | * usage: Resource<int> someresource(resourcemanager, 10, "someresourcename", "somealternativename"); \n |
102 | */ | 102 | * and then implement setFromString and getString \n |
103 | * example: \n | ||
104 | * template <> \n | ||
105 | * void Resource<int>::setFromString(const char *str) { \n | ||
106 | * *(*this) = atoi(str); \n | ||
107 | * } | ||
108 | */ | ||
103 | template <typename T> | 109 | template <typename T> |
104 | class Resource:public Resource_base | 110 | class Resource:public Resource_base |
105 | { | 111 | { |
@@ -117,10 +123,13 @@ public: | |||
117 | } | 123 | } |
118 | 124 | ||
119 | inline void setDefaultValue() { m_value = m_defaultval; } | 125 | inline void setDefaultValue() { m_value = m_defaultval; } |
126 | /// sets resource from string, specialized, must be implemented | ||
120 | void setFromString(const char *strval); | 127 | void setFromString(const char *strval); |
121 | inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} | 128 | inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} |
122 | 129 | /// specialized, must be implemented | |
123 | std::string getString(); | 130 | /// @return string value of resource |
131 | std::string getString(); | ||
132 | |||
124 | inline T& operator*() { return m_value; } | 133 | inline T& operator*() { return m_value; } |
125 | inline const T& operator*() const { return m_value; } | 134 | inline const T& operator*() const { return m_value; } |
126 | inline T *operator->() { return &m_value; } | 135 | inline T *operator->() { return &m_value; } |
@@ -130,4 +139,4 @@ private: | |||
130 | ResourceManager &m_rm; | 139 | ResourceManager &m_rm; |
131 | }; | 140 | }; |
132 | 141 | ||
133 | #endif //_RESOURCE_HH_ | 142 | #endif // RESOURCE_HH |