diff --git a/src/attributes.hpp b/src/attributes.hpp index 297d20b..ff7e360 100644 --- a/src/attributes.hpp +++ b/src/attributes.hpp @@ -21,22 +21,44 @@ #include +//! +//! \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 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(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(#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 void register_attribute(const std::string &name, T &object) { typedef attribute specific_attribute; diff --git a/src/string2type.hpp b/src/string2type.hpp index 332a48c..67d9fdc 100644 --- a/src/string2type.hpp +++ b/src/string2type.hpp @@ -20,6 +20,9 @@ namespace string2type { +//! +//! string-to-type conversion function. +//! template T convert(const std::string &value) { return boost::lexical_cast(value);