Skip to content

Commit

Permalink
add config_of function
Browse files Browse the repository at this point in the history
in the file config_assign.cpp/hpp, it can be use similar to boost's boost::assign for config object.
I don't use it that much, but i found it useful especialy to pass or return a config that just contains one or two childs.
  • Loading branch information
gfgtdf committed Apr 1, 2014
1 parent ea7521a commit fef7c49
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -694,6 +694,7 @@ set(wesnoth-main_SRC
callable_objects.cpp
commandline_options.cpp
config_cache.cpp
config_assign.cpp
controller_base.cpp
desktop_util.cpp
dialogs.cpp
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -73,6 +73,7 @@ libwesnoth_sources = Split("""
pathfind/astarsearch.cpp
builder.cpp
clipboard.cpp
config_assign.cpp
construct_dialog.cpp
cursor.cpp
display.cpp
Expand Down
92 changes: 92 additions & 0 deletions src/config_assign.cpp
@@ -0,0 +1,92 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
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_;
}
41 changes: 41 additions & 0 deletions src/config_assign.hpp
@@ -0,0 +1,41 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef CONFIG_ASSIGN_H_INCLUDED
#define CONFIG_ASSIGN_H_INCLUDED

#include <string>
#include "config.hpp"

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);

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;
private:
config data_;
};
#endif

0 comments on commit fef7c49

Please sign in to comment.