Moved support for loading and writing preproc_defines into class.

This commit is contained in:
Pauli Nieminen 2008-08-30 12:44:52 +00:00
parent 0d75346ca0
commit 5329413a23
4 changed files with 76 additions and 26 deletions

View File

@ -70,28 +70,6 @@ config_writer::config_writer(
}
void config_writer::write_define(const preproc_map::value_type& def)
{
out_ << "#line " << def.second.linenum << " " << def.second.location << "\n";
out_ << "#textdomain " << def.second.textdomain << "\n";
out_ << "#define " << def.first;
for(std::vector<std::string>::const_iterator it = def.second.arguments.begin();
it != def.second.arguments.end();
++it)
{
out_ << *it << " ";
}
out_ << "\n";
out_ << def.second.value;
out_ << "#enddef\n";
}
void config_writer::write(const preproc_map& defines_map)
{
std::for_each(defines_map.begin(), defines_map.end(), boost::bind(&config_writer::write_define,this,_1));
}
void config_writer::write(const config &cfg)
{
::write(out_, cfg, level_);

View File

@ -43,9 +43,6 @@ public:
config_writer(std::ostream &out, bool compress, const std::string &textdomain, int level = -1);
void write(const config &cfg);
void write(const preproc_map& defines_map);
void write_define(const preproc_map::value_type&);
void write_child(const std::string &key, const config &cfg);
void write_key_val(const std::string &key, const std::string &value);

View File

@ -18,9 +18,11 @@
#include "../global.hpp"
#include "../config.hpp"
#include "../filesystem.hpp"
#include "../log.hpp"
#include "../wesconfig.h"
#include "binary_or_text.hpp"
#include "preprocessor.hpp"
#include "string_utils.hpp"
@ -50,6 +52,69 @@ bool preproc_define::operator<(preproc_define const &v) const {
return linenum < v.linenum;
}
#include <list>
void preproc_define::write_argument(config_writer& writer, const std::string& arg) const
{
const std::string key = "argument";
writer.open_child(key);
writer.write_key_val("name", arg);
writer.close_child(key);
}
void preproc_define::write(config_writer& writer, const std::string& name) const
{
const std::string key = "preproc_define";
writer.open_child(key);
writer.write_key_val("name", name);
writer.write_key_val("value", value);
writer.write_key_val("textdomain", textdomain);
writer.write_key_val("linenum", lexical_cast<std::string>(linenum));
writer.write_key_val("location", location);
std::for_each(arguments.begin(), arguments.end(),
boost::bind(&preproc_define::write_argument,
this,
boost::ref(writer),
_1));
writer.close_child(key);
}
void preproc_define::read_argument(const config* cfg)
{
arguments.push_back((*cfg)["name"]);
}
void preproc_define::read(const config& cfg)
{
value = cfg["value"];
textdomain = cfg["textdomain"];
linenum = lexical_cast<int>(cfg["linenum"]);
location = cfg["location"];
const config::child_list args= cfg.get_children("argument");
typedef std::vector< std::string > arg_vec;
std::for_each(args.begin(), args.end(),
boost::bind(&preproc_define::read_argument,
this,
_1
)
);
}
preproc_map::value_type preproc_define::read_pair(const config* cfg)
{
std::string first = (*cfg)["name"];
preproc_define second;
second.read(*cfg);
return std::make_pair(first, second);
}
std::ostream& operator<<(std::ostream& stream, const preproc_define& def)
{

View File

@ -25,6 +25,12 @@
#include "game_errors.hpp"
class config_writer;
class config;
struct preproc_define;
typedef std::map< std::string, preproc_define > preproc_map;
struct preproc_define
{
preproc_define() : value(""), arguments(), textdomain(""), linenum(0), location("") {}
@ -37,6 +43,11 @@ struct preproc_define
std::string textdomain;
int linenum;
std::string location;
void write(config_writer&, const std::string&) const;
void write_argument(config_writer&, const std::string&) const;
void read(const config&);
void read_argument(const config*);
static preproc_map::value_type read_pair(const config*);
bool operator==(preproc_define const &) const;
bool operator<(preproc_define const &) const;
bool operator!=(preproc_define const &v) const { return !operator==(v); }
@ -50,7 +61,6 @@ struct preproc_config {
};
};
typedef std::map< std::string, preproc_define > preproc_map;
std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type& def);