|
|
std::string m_altname; ///< alternative name | std::string m_altname; ///< alternative name |
}; | }; |
| |
class ResourceManager; |
|
|
|
/** |
|
Real resource class |
|
*/ |
|
template <typename T> | template <typename T> |
class Resource:public Resource_base |
class Resource; |
{ |
|
public: |
|
Resource(ResourceManager &rm, T val, |
|
const std::string &name, const std::string &altname): |
|
Resource_base(name, altname), |
|
m_value(val), m_defaultval(val), |
|
m_rm(rm) |
|
{ |
|
m_rm.addResource(*this); // add this to resource handler |
|
} |
|
virtual ~Resource() { |
|
m_rm.removeResource(*this); // remove this from resource handler |
|
} |
|
|
|
inline void setDefaultValue() { m_value = m_defaultval; } |
|
void setFromString(const char *strval); |
|
inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} |
|
|
|
std::string getString(); |
|
inline T& operator*() { return m_value; } |
|
inline const T& operator*() const { return m_value; } |
|
inline T *operator->() { return &m_value; } |
|
inline const T *operator->() const { return &m_value; } |
|
private: |
|
T m_value, m_defaultval; |
|
ResourceManager &m_rm; |
|
}; |
|
| |
class ResourceManager | class ResourceManager |
{ | { |
|
|
ResourceList m_resourcelist; | ResourceList m_resourcelist; |
}; | }; |
| |
|
/** |
|
Real resource class |
|
*/ |
|
template <typename T> |
|
class Resource:public Resource_base |
|
{ |
|
public: |
|
Resource(ResourceManager &rm, T val, |
|
const std::string &name, const std::string &altname): |
|
Resource_base(name, altname), |
|
m_value(val), m_defaultval(val), |
|
m_rm(rm) |
|
{ |
|
m_rm.addResource(*this); // add this to resource handler |
|
} |
|
virtual ~Resource() { |
|
m_rm.removeResource(*this); // remove this from resource handler |
|
} |
|
|
|
inline void setDefaultValue() { m_value = m_defaultval; } |
|
void setFromString(const char *strval); |
|
inline Resource<T>& operator = (const T& newvalue) { m_value = newvalue; return *this;} |
|
|
|
std::string getString(); |
|
inline T& operator*() { return m_value; } |
|
inline const T& operator*() const { return m_value; } |
|
inline T *operator->() { return &m_value; } |
|
inline const T *operator->() const { return &m_value; } |
|
private: |
|
T m_value, m_defaultval; |
|
ResourceManager &m_rm; |
|
}; |
|
|
#endif //_RESOURCE_HH_ | #endif //_RESOURCE_HH_ |