diff --git a/settable.hpp b/attributes.hpp similarity index 82% rename from settable.hpp rename to attributes.hpp index 1ec95b2..85d4a0d 100644 --- a/settable.hpp +++ b/attributes.hpp @@ -14,21 +14,13 @@ #ifndef SETTABLE_HPP #define SETTABLE_HPP +#include "string2type.hpp" + #include #include -#include #include -namespace string2type { - -template -T convert(const std::string &value); - -} - -namespace settable { - class abstract_setter { public: virtual void set_value(const std::string &value) = 0; @@ -48,10 +40,10 @@ public: T &reference; }; -#define REGISTER_MEMBER(Type, Attribute) \ - this->register_setter(#Attribute, this->Attribute); +#define REGISTER_ATTRIBUTE(Type, Attribute) \ + this->register_attribute(#Attribute, this->Attribute); -class settable { +class attributes { public: void set_attribute(const std::string &attr, const std::string &value) { setters_map::iterator it = setters.find(attr); @@ -62,7 +54,7 @@ public: } template - void register_setter(const std::string &name, T &ptr) { + void register_attribute(const std::string &name, T &ptr) { typedef setter specific_setter; setter_ptr setter(new specific_setter(ptr)); @@ -77,7 +69,5 @@ private: setters_map setters; }; -} - #endif /* SETTABLE_HPP */ diff --git a/examples/demo.cpp b/examples/demo.cpp index 4999d39..ae14c60 100644 --- a/examples/demo.cpp +++ b/examples/demo.cpp @@ -1,4 +1,4 @@ -#include "settable.hpp" +#include "attributes.hpp" #include @@ -13,9 +13,9 @@ int convert(const std::string &value) { } -struct foo : settable::settable { +struct foo : attributes { foo() { - REGISTER_MEMBER(int, x); + REGISTER_ATTRIBUTE(int, x); } int x; diff --git a/string2type.hpp b/string2type.hpp new file mode 100644 index 0000000..044b842 --- /dev/null +++ b/string2type.hpp @@ -0,0 +1,26 @@ +//! \file string2type.hpp +//! \brief C++ Library (header-only). + +// settable.hpp ------------------------------------------------------------// + +// +// Copyright Jens Luedicke 2010 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +//----------------------------------------------------------------------------// + +#ifndef STRING2TYPE_HPP +#define STRING2TYPE_HPP + +#include + +namespace string2type { + +template +T convert(const std::string &value); + +} + +#endif /* STRING2TYPE_HPP */