diff options
author | fluxgen <fluxgen> | 2003-05-07 11:32:42 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-05-07 11:32:42 (GMT) |
commit | 96005a8feb75f31579b981b25a96c5ef92a02e6d (patch) | |
tree | 6bac070409c0e7a450d685fff86aa3c4b6da6541 /src | |
parent | 9548e4bf500afb2e40600ab358a2b157c78b0732 (diff) | |
download | fluxbox_pavel-96005a8feb75f31579b981b25a96c5ef92a02e6d.zip fluxbox_pavel-96005a8feb75f31579b981b25a96c5ef92a02e6d.tar.bz2 |
rearranged Resource class
Diffstat (limited to 'src')
-rw-r--r-- | src/Resource.hh | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/Resource.hh b/src/Resource.hh index 0c9bb7a..0ea2dd1 100644 --- a/src/Resource.hh +++ b/src/Resource.hh | |||
@@ -1,5 +1,5 @@ | |||
1 | // Resource.hh | 1 | // Resource.hh |
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) | 2 | // Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) |
3 | // | 3 | // |
4 | // Permission is hereby granted, free of charge, to any person obtaining a | 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
5 | // copy of this software and associated documentation files (the "Software"), | 5 | // copy of this software and associated documentation files (the "Software"), |
@@ -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.10 2003/04/25 11:40:58 fluxgen Exp $ | 22 | // $Id: Resource.hh,v 1.11 2003/05/07 11:32:42 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef RESOURCE_HH | 24 | #ifndef RESOURCE_HH |
25 | #define RESOURCE_HH | 25 | #define RESOURCE_HH |
@@ -56,40 +56,8 @@ private: | |||
56 | std::string m_altname; ///< alternative name | 56 | std::string m_altname; ///< alternative name |
57 | }; | 57 | }; |
58 | 58 | ||
59 | class ResourceManager; | ||
60 | |||
61 | /** | ||
62 | Real resource class | ||
63 | */ | ||
64 | template <typename T> | 59 | template <typename T> |
65 | class Resource:public Resource_base | 60 | class Resource; |
66 | { | ||
67 | public: | ||
68 | Resource(ResourceManager &rm, T val, | ||
69 | const std::string &name, const std::string &altname): | ||
70 | Resource_base(name, altname), | ||
71 | m_value(val), m_defaultval(val), | ||
72 | m_rm(rm) | ||
73 | { | ||
74 | m_rm.addResource(*this); // add this to resource handler | ||
75 | } | ||
76 | virtual ~Resource() { | ||
77 | m_rm.removeResource(*this); // remove this from resource handler | ||
78 | } | ||
79 | |||
80 | inline void setDefaultValue() { m_value = m_defaultval; } | ||
81 | void setFromString(const char *strval); | ||
82 | inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} | ||
83 | |||
84 | std::string getString(); | ||
85 | inline T& operator*() { return m_value; } | ||
86 | inline const T& operator*() const { return m_value; } | ||
87 | inline T *operator->() { return &m_value; } | ||
88 | inline const T *operator->() const { return &m_value; } | ||
89 | private: | ||
90 | T m_value, m_defaultval; | ||
91 | ResourceManager &m_rm; | ||
92 | }; | ||
93 | 61 | ||
94 | class ResourceManager | 62 | class ResourceManager |
95 | { | 63 | { |
@@ -129,4 +97,37 @@ private: | |||
129 | ResourceList m_resourcelist; | 97 | ResourceList m_resourcelist; |
130 | }; | 98 | }; |
131 | 99 | ||
100 | /** | ||
101 | Real resource class | ||
102 | */ | ||
103 | template <typename T> | ||
104 | class Resource:public Resource_base | ||
105 | { | ||
106 | public: | ||
107 | Resource(ResourceManager &rm, T val, | ||
108 | const std::string &name, const std::string &altname): | ||
109 | Resource_base(name, altname), | ||
110 | m_value(val), m_defaultval(val), | ||
111 | m_rm(rm) | ||
112 | { | ||
113 | m_rm.addResource(*this); // add this to resource handler | ||
114 | } | ||
115 | virtual ~Resource() { | ||
116 | m_rm.removeResource(*this); // remove this from resource handler | ||
117 | } | ||
118 | |||
119 | inline void setDefaultValue() { m_value = m_defaultval; } | ||
120 | void setFromString(const char *strval); | ||
121 | inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} | ||
122 | |||
123 | std::string getString(); | ||
124 | inline T& operator*() { return m_value; } | ||
125 | inline const T& operator*() const { return m_value; } | ||
126 | inline T *operator->() { return &m_value; } | ||
127 | inline const T *operator->() const { return &m_value; } | ||
128 | private: | ||
129 | T m_value, m_defaultval; | ||
130 | ResourceManager &m_rm; | ||
131 | }; | ||
132 | |||
132 | #endif //_RESOURCE_HH_ | 133 | #endif //_RESOURCE_HH_ |