Skip to content

Commit

Permalink
use template for config_assign
Browse files Browse the repository at this point in the history
this removes code dublication,
  • Loading branch information
gfgtdf committed Apr 23, 2014
1 parent da71e01 commit 1f70827
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 95 deletions.
81 changes: 1 addition & 80 deletions src/config_assign.cpp
Expand Up @@ -10,83 +10,4 @@
See the COPYING file for more details.
*/
#include "config_assign.hpp"
#include "config.hpp"


config_of::config_of(const std::string& attrname, bool value)
{
this->operator()(attrname, value);
}

config_of::config_of(const std::string& attrname, int value)
{
this->operator()(attrname, value);
}

config_of::config_of(const std::string& attrname, unsigned int value)
{
this->operator()(attrname, value);
}

config_of::config_of(const std::string& attrname, double value)
{
this->operator()(attrname, value);
}

config_of::config_of(const std::string& attrname, const std::string& value)
{
this->operator()(attrname, value);
}
config_of::config_of(const std::string& attrname, config::attribute_value value)
{
this->operator()(attrname, value);
}

config_of::config_of(const std::string& tagname, const config& child)
{
this->operator()(tagname, child);
}

config_of& config_of::operator()(const std::string& attrname, bool value)
{
data_[attrname] = value;
return *this;
}
config_of& config_of::operator()(const std::string& attrname, int value)
{
data_[attrname] = value;
return *this;
}

config_of& config_of::operator()(const std::string& attrname, unsigned int value)
{
data_[attrname] = value;
return *this;
}
config_of& config_of::operator()(const std::string& attrname, double value)
{
data_[attrname] = value;
return *this;
}
config_of& config_of::operator()(const std::string& attrname, const std::string& value)
{
data_[attrname] = value;
return *this;
}
config_of& config_of::operator()(const std::string& attrname, config::attribute_value value)
{
data_[attrname] = value;
return *this;
}

config_of& config_of::operator()(const std::string& tagname, const config& child)
{
data_.add_child(tagname, child);
return *this;
}

config_of::operator config() const
{
return data_;
}
#include "config_assign.hpp"
42 changes: 27 additions & 15 deletions src/config_assign.hpp
Expand Up @@ -19,22 +19,34 @@
class config_of
{
public:
config_of(const std::string& attrname, int value);
config_of(const std::string& attrname, unsigned int value);
config_of(const std::string& attrname, bool value);
config_of(const std::string& attrname, double value);
config_of(const std::string& attrname, const std::string& value);
config_of(const std::string& attrname, config::attribute_value value);
config_of(const std::string& tagname, const config& child);
template <typename AT>
config_of(const std::string& attrname, AT value)
{
this->operator()(attrname, value);
}

config_of(const std::string& tagname, const config& child)
{
this->operator()(tagname, child);
}

config_of& operator()(const std::string& attrname, int value);
config_of& operator()(const std::string& attrname, unsigned int value);
config_of& operator()(const std::string& attrname, bool value);
config_of& operator()(const std::string& attrname, double value);
config_of& operator()(const std::string& attrname, const std::string& value);
config_of& operator()(const std::string& attrname, config::attribute_value value);
config_of& operator()(const std::string& tagname, const config& child);
operator config() const;
template <typename AT>
config_of& operator()(const std::string& attrname, AT value)
{
data_[attrname] = value;
return *this;
}

config_of& operator()(const std::string& tagname, const config& child)
{
data_.add_child(tagname, child);
return *this;
}

operator config() const
{
return data_;
}
private:
config data_;
};
Expand Down

0 comments on commit 1f70827

Please sign in to comment.