Renamed libsettable to libattributes.

This commit is contained in:
Jens Luedicke
2011-01-22 20:08:41 +01:00
parent e403394516
commit fb4eca99db
3 changed files with 35 additions and 19 deletions

View File

@@ -14,21 +14,13 @@
#ifndef SETTABLE_HPP
#define SETTABLE_HPP
#include "string2type.hpp"
#include <map>
#include <string>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
namespace string2type {
template<typename T>
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<Type>(#Attribute, this->Attribute);
#define REGISTER_ATTRIBUTE(Type, Attribute) \
this->register_attribute<Type>(#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<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;
setter_ptr setter(new specific_setter(ptr));
@@ -77,7 +69,5 @@ private:
setters_map setters;
};
}
#endif /* SETTABLE_HPP */

View File

@@ -1,4 +1,4 @@
#include "settable.hpp"
#include "attributes.hpp"
#include <iostream>
@@ -13,9 +13,9 @@ int convert<int>(const std::string &value) {
}
struct foo : settable::settable {
struct foo : attributes {
foo() {
REGISTER_MEMBER(int, x);
REGISTER_ATTRIBUTE(int, x);
}
int x;

26
string2type.hpp Normal file
View 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 */