Added documentation.

This commit is contained in:
Jens Luedicke
2011-01-22 23:59:58 +01:00
parent c2faa76531
commit e25af5ff2a
2 changed files with 38 additions and 0 deletions

View File

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

View File

@@ -20,6 +20,9 @@
namespace string2type {
//!
//! string-to-type conversion function.
//!
template<typename T>
T convert(const std::string &value) {
return boost::lexical_cast<T>(value);