Author: suokko
Date: Sat Aug 30 14:44:52 2008
New Revision: 29107
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29107&view=rev
Log:
* Moved support for loading and writing preproc_defines into class.
Modified:
trunk/src/serialization/binary_or_text.cpp
trunk/src/serialization/binary_or_text.hpp
trunk/src/serialization/preprocessor.cpp
trunk/src/serialization/preprocessor.hpp
Modified: trunk/src/serialization/binary_or_text.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/binary_or_text.cpp?rev=29107&r1=29106&r2=29107&view=diff
==============================================================================
--- trunk/src/serialization/binary_or_text.cpp (original)
+++ trunk/src/serialization/binary_or_text.cpp Sat Aug 30 14:44:52 2008
@@ -70,28 +70,6 @@
}
-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_);
Modified: trunk/src/serialization/binary_or_text.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/binary_or_text.hpp?rev=29107&r1=29106&r2=29107&view=diff
==============================================================================
--- trunk/src/serialization/binary_or_text.hpp (original)
+++ trunk/src/serialization/binary_or_text.hpp Sat Aug 30 14:44:52 2008
@@ -43,9 +43,6 @@
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);
Modified: trunk/src/serialization/preprocessor.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/preprocessor.cpp?rev=29107&r1=29106&r2=29107&view=diff
==============================================================================
--- trunk/src/serialization/preprocessor.cpp (original)
+++ trunk/src/serialization/preprocessor.cpp Sat Aug 30 14:44:52 2008
@@ -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 @@
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)
{
Modified: trunk/src/serialization/preprocessor.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/preprocessor.hpp?rev=29107&r1=29106&r2=29107&view=diff
==============================================================================
--- trunk/src/serialization/preprocessor.hpp (original)
+++ trunk/src/serialization/preprocessor.hpp Sat Aug 30 14:44:52 2008
@@ -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 @@
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 @@
};
};
-typedef std::map< std::string, preproc_define > preproc_map;
std::ostream& operator<<(std::ostream& stream, const preproc_map::value_type&
def);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits