Renamed libsettable to libattributes.
This commit is contained in:
@@ -14,21 +14,13 @@
|
|||||||
#ifndef SETTABLE_HPP
|
#ifndef SETTABLE_HPP
|
||||||
#define SETTABLE_HPP
|
#define SETTABLE_HPP
|
||||||
|
|
||||||
|
#include "string2type.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
namespace string2type {
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T convert(const std::string &value);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace settable {
|
|
||||||
|
|
||||||
class abstract_setter {
|
class abstract_setter {
|
||||||
public:
|
public:
|
||||||
virtual void set_value(const std::string &value) = 0;
|
virtual void set_value(const std::string &value) = 0;
|
||||||
@@ -48,10 +40,10 @@ public:
|
|||||||
T &reference;
|
T &reference;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REGISTER_MEMBER(Type, Attribute) \
|
#define REGISTER_ATTRIBUTE(Type, Attribute) \
|
||||||
this->register_setter<Type>(#Attribute, this->Attribute);
|
this->register_attribute<Type>(#Attribute, this->Attribute);
|
||||||
|
|
||||||
class settable {
|
class attributes {
|
||||||
public:
|
public:
|
||||||
void set_attribute(const std::string &attr, const std::string &value) {
|
void set_attribute(const std::string &attr, const std::string &value) {
|
||||||
setters_map::iterator it = setters.find(attr);
|
setters_map::iterator it = setters.find(attr);
|
||||||
@@ -62,7 +54,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void register_setter(const std::string &name, T &ptr) {
|
void register_attribute(const std::string &name, T &ptr) {
|
||||||
typedef setter<T> specific_setter;
|
typedef setter<T> specific_setter;
|
||||||
|
|
||||||
setter_ptr setter(new specific_setter(ptr));
|
setter_ptr setter(new specific_setter(ptr));
|
||||||
@@ -77,7 +69,5 @@ private:
|
|||||||
setters_map setters;
|
setters_map setters;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SETTABLE_HPP */
|
#endif /* SETTABLE_HPP */
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "settable.hpp"
|
#include "attributes.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ int convert<int>(const std::string &value) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct foo : settable::settable {
|
struct foo : attributes {
|
||||||
foo() {
|
foo() {
|
||||||
REGISTER_MEMBER(int, x);
|
REGISTER_ATTRIBUTE(int, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
|
|||||||
26
string2type.hpp
Normal file
26
string2type.hpp
Normal file
@@ -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 <string>
|
||||||
|
|
||||||
|
namespace string2type {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T convert(const std::string &value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* STRING2TYPE_HPP */
|
||||||
Reference in New Issue
Block a user