Added documentation.
This commit is contained in:
@@ -21,22 +21,44 @@
|
|||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \class abstract_attribute
|
||||||
|
//! \brief Abstract base class for attributes.
|
||||||
|
//!
|
||||||
class abstract_attribute {
|
class abstract_attribute {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! Pure virtual method.
|
||||||
|
//!
|
||||||
virtual void set_value(const std::string &value) = 0;
|
virtual void set_value(const std::string &value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \class attribute
|
||||||
|
//! \brief wrapper class for class attributes.
|
||||||
|
//!
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class attribute : public abstract_attribute {
|
class attribute : public abstract_attribute {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \brief Constructor
|
||||||
|
//!
|
||||||
explicit attribute(T &object)
|
explicit attribute(T &object)
|
||||||
: reference(object) {
|
: reference(object) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \brief Implementation of set_value method.
|
||||||
|
//!
|
||||||
virtual void set_value(const std::string &value) {
|
virtual void set_value(const std::string &value) {
|
||||||
reference = string2type::convert<T>(value);
|
reference = string2type::convert<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \brief Implementation of get_value method.
|
||||||
|
//!
|
||||||
virtual T& get_value() const {
|
virtual T& get_value() const {
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
@@ -45,11 +67,21 @@ private:
|
|||||||
T &reference;
|
T &reference;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \brief Convenience macro for attribute registration.
|
||||||
|
//!
|
||||||
#define REGISTER_ATTRIBUTE(Type, Attribute) \
|
#define REGISTER_ATTRIBUTE(Type, Attribute) \
|
||||||
this->register_attribute<Type>(#Attribute, this->Attribute);
|
this->register_attribute<Type>(#Attribute, this->Attribute);
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! \class attributes
|
||||||
|
//! \brief Provides attribute registration facility.
|
||||||
|
//!
|
||||||
class attributes {
|
class attributes {
|
||||||
public:
|
public:
|
||||||
|
//!
|
||||||
|
//! Sets named attribute \e attr to value \e value.
|
||||||
|
//!
|
||||||
void set_attribute(const std::string &attr, const std::string &value) {
|
void set_attribute(const std::string &attr, const std::string &value) {
|
||||||
attributes_map::iterator it = attributes.find(attr);
|
attributes_map::iterator it = attributes.find(attr);
|
||||||
|
|
||||||
@@ -58,6 +90,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! Registers attribute \e object with name \e name.
|
||||||
|
//!
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void register_attribute(const std::string &name, T &object) {
|
void register_attribute(const std::string &name, T &object) {
|
||||||
typedef attribute<T> specific_attribute;
|
typedef attribute<T> specific_attribute;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
|
|
||||||
namespace string2type {
|
namespace string2type {
|
||||||
|
|
||||||
|
//!
|
||||||
|
//! string-to-type conversion function.
|
||||||
|
//!
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T convert(const std::string &value) {
|
T convert(const std::string &value) {
|
||||||
return boost::lexical_cast<T>(value);
|
return boost::lexical_cast<T>(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user