[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp font....
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp font.... |
Date: |
Fri, 25 Mar 2005 13:19:20 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/03/25 18:19:20
Modified files:
src : filesystem.cpp filesystem.hpp font.cpp game.cpp
gamestatus.cpp help.cpp language.cpp
preferences.cpp publish_campaign.cpp
titlescreen.cpp
src/campaign_server: campaign_server.cpp
src/editor : editor.cpp editor_main.cpp
src/serialization: binary_or_text.cpp parser.cpp parser.hpp
preprocessor.cpp preprocessor.hpp
src/tools : exploder_cutter.cpp
Log message:
Now the preprocessor output is also a stream, and so is the parser
input, hence they can be plugged, yay. Also introduce a scoped_istream to
prevent leaking descriptors in case of exceptions. Once again, the stream
changes are purely on the interface level for the time being, so there can be a
slight performance hit when no cache is present. But once the cache is built,
everything should be fine, even faster than it was before the changes. And
isn't that the point of a cache?
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.62&tr2=1.63&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.hpp.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.125&tr2=1.126&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.215&tr2=1.216&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.62&tr2=1.63&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/help.cpp.diff?tr1=1.82&tr2=1.83&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/language.cpp.diff?tr1=1.79&tr2=1.80&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/preferences.cpp.diff?tr1=1.145&tr2=1.146&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/publish_campaign.cpp.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/titlescreen.cpp.diff?tr1=1.38&tr2=1.39&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/campaign_server/campaign_server.cpp.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/editor/editor.cpp.diff?tr1=1.99&tr2=1.100&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/editor/editor_main.cpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_or_text.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/parser.cpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/parser.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.cpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/tools/exploder_cutter.cpp.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: wesnoth/src/campaign_server/campaign_server.cpp
diff -u wesnoth/src/campaign_server/campaign_server.cpp:1.11
wesnoth/src/campaign_server/campaign_server.cpp:1.12
--- wesnoth/src/campaign_server/campaign_server.cpp:1.11 Fri Mar 25
16:43:54 2005
+++ wesnoth/src/campaign_server/campaign_server.cpp Fri Mar 25 18:19:20 2005
@@ -44,7 +44,8 @@
int campaign_server::load_config()
{
- read(cfg_, read_file(file_));
+ scoped_istream stream = stream_file(file_);
+ read(cfg_, *stream);
return lexical_cast_default<int>(cfg_["port"], 15002);
}
@@ -90,9 +91,8 @@
network::send_data(construct_error("Campaign not found."),sock);
} else {
config cfg;
- std::istream *stream =
stream_file((*campaign)["filename"]);
+ scoped_istream stream =
stream_file((*campaign)["filename"]);
read_compressed(cfg, *stream);
- delete stream;
network::queue_data(cfg,sock);
const int downloads =
lexical_cast_default<int>((*campaign)["downloads"],0)+1;
Index: wesnoth/src/editor/editor.cpp
diff -u wesnoth/src/editor/editor.cpp:1.99 wesnoth/src/editor/editor.cpp:1.100
--- wesnoth/src/editor/editor.cpp:1.99 Wed Mar 23 21:30:46 2005
+++ wesnoth/src/editor/editor.cpp Fri Mar 25 18:19:20 2005
@@ -99,7 +99,8 @@
// Perform some initializations that should only be performed
// the first time the editor object is created.
try {
- read(prefs_, read_file(prefs_filename));
+ scoped_istream stream = stream_file(prefs_filename);
+ read(prefs_, *stream);
}
catch (config::error e) {
std::cerr << "Error when reading " << prefs_filename <<
": "
Index: wesnoth/src/editor/editor_main.cpp
diff -u wesnoth/src/editor/editor_main.cpp:1.30
wesnoth/src/editor/editor_main.cpp:1.31
--- wesnoth/src/editor/editor_main.cpp:1.30 Tue Mar 22 23:42:37 2005
+++ wesnoth/src/editor/editor_main.cpp Fri Mar 25 18:19:20 2005
@@ -227,7 +227,8 @@
//Read the configuration af
config cfg;
try {
- read(cfg, preprocess_file("data/game.cfg", &defines_map));
+ scoped_istream stream = preprocess_file("data/game.cfg",
&defines_map);
+ read(cfg, *stream);
}
catch (config::error e) {
std::cerr << "Error when reading game config: '" << e.message
<< "'" << std::endl;
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.62 wesnoth/src/filesystem.cpp:1.63
--- wesnoth/src/filesystem.cpp:1.62 Fri Mar 25 17:09:06 2005
+++ wesnoth/src/filesystem.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.62 2005/03/25 17:09:06 silene Exp $ */
+/* $Id: filesystem.cpp,v 1.63 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -825,3 +825,13 @@
return "";
}
+void scoped_istream::operator=(std::istream *s)
+{
+ delete stream;
+ stream = s;
+}
+
+scoped_istream::~scoped_istream()
+{
+ delete stream;
+}
Index: wesnoth/src/filesystem.hpp
diff -u wesnoth/src/filesystem.hpp:1.33 wesnoth/src/filesystem.hpp:1.34
--- wesnoth/src/filesystem.hpp:1.33 Fri Mar 25 16:10:08 2005
+++ wesnoth/src/filesystem.hpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.hpp,v 1.33 2005/03/25 16:10:08 silene Exp $ */
+/* $Id: filesystem.hpp,v 1.34 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -15,6 +15,7 @@
#include <time.h>
+#include <iosfwd>
#include <string>
#include <vector>
@@ -139,4 +140,14 @@
//the file isn't present
std::string get_binary_file_location(const std::string& type, const
std::string& filename);
+class scoped_istream {
+ std::istream *stream;
+public:
+ scoped_istream(std::istream *s): stream(s) {}
+ void operator=(std::istream *);
+ std::istream &operator*() { return *stream; }
+ std::istream *operator->() { return stream; }
+ ~scoped_istream();
+};
+
#endif
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.125 wesnoth/src/font.cpp:1.126
--- wesnoth/src/font.cpp:1.125 Thu Mar 24 21:35:50 2005
+++ wesnoth/src/font.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.125 2005/03/24 21:35:50 ydirson Exp $ */
+/* $Id: font.cpp,v 1.126 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1322,7 +1322,8 @@
//config when changing languages
config cfg;
try {
- read(cfg, preprocess_file("data/fonts.cfg"));
+ scoped_istream stream = preprocess_file("data/fonts.cfg");
+ read(cfg, *stream);
} catch(config::error&) {
std::cerr << "Could not read fonts.cfg\n";
return false;
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.215 wesnoth/src/game.cpp:1.216
--- wesnoth/src/game.cpp:1.215 Fri Mar 25 16:43:54 2005
+++ wesnoth/src/game.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.215 2005/03/25 16:43:54 silene Exp $ */
+/* $Id: game.cpp,v 1.216 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -256,7 +256,8 @@
try {
if(file_exists(fname_checksum))
{
config checksum_cfg;
- read(checksum_cfg,
read_file(fname_checksum));
+ scoped_istream stream =
stream_file(fname_checksum);
+ read(checksum_cfg,
*stream);
dir_checksum =
file_tree_checksum(checksum_cfg);
}
} catch(config::error&) {
@@ -269,12 +270,9 @@
if(use_cache && file_exists(fname) &&
file_create_time(fname) > data_tree_checksum().modified && dir_checksum ==
data_tree_checksum()) {
std::cerr << "found valid cache at '"
<< fname << "' using it\n";
log_scope("read cache");
- compression_schema schema;
-
try {
- std::istream *stream =
stream_file(fname);
- read_compressed(cfg, *stream,
schema);
- delete stream;
+ scoped_istream stream =
stream_file(fname);
+ read_compressed(cfg, *stream);
return;
} catch(config::error&) {
std::cerr << "cache is corrupt.
Loading from files\n";
@@ -286,10 +284,10 @@
std::cerr << "no valid cache found. Writing
cache to '" << fname << "'\n";
//read the file and then write to the cache
- read(cfg, preprocess_file("data/game.cfg",
&defines, &line_src), &line_src);
+ scoped_istream stream =
preprocess_file("data/game.cfg", &defines, &line_src);
+ read(cfg, *stream, &line_src);
try {
- compression_schema schema;
- write_file(fname, write_compressed(cfg,
schema));
+ write_file(fname,
write_compressed(cfg));
config checksum_cfg;
data_tree_checksum().write(checksum_cfg);
@@ -305,7 +303,8 @@
}
std::cerr << "caching cannot be done. Reading file\n";
- read(cfg, preprocess_file("data/game.cfg", &defines, &line_src),
&line_src);
+ scoped_istream stream = preprocess_file("data/game.cfg", &defines,
&line_src);
+ read(cfg, *stream, &line_src);
}
bool less_campaigns_rank(const config* a, const config* b) {
@@ -1525,8 +1524,8 @@
const std::string input(argv[arg+1]);
const std::string output(argv[arg+2]);
- const std::string in(read_file(input));
- if(in == "") {
+ scoped_istream stream = stream_file(input);
+ if (stream->fail()) {
std::cerr << "could not read file '" << input
<< "'\n";
return 0;
}
@@ -1535,7 +1534,7 @@
const bool compress = val == "--compress";
try {
- const bool is_compressed =
detect_format_and_read(cfg, in);
+ const bool is_compressed =
detect_format_and_read(cfg, *stream);
if(is_compressed && compress) {
std::cerr << input << " is already
compressed\n";
return 0;
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.62 wesnoth/src/gamestatus.cpp:1.63
--- wesnoth/src/gamestatus.cpp:1.62 Wed Mar 23 22:08:52 2005
+++ wesnoth/src/gamestatus.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.62 2005/03/23 22:08:52 ydirson Exp $ */
+/* $Id: gamestatus.cpp,v 1.63 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -418,13 +418,12 @@
std::replace(modified_name.begin(),modified_name.end(),' ','_');
//try reading the file both with and without underscores
- std::string file_data = read_file(get_saves_dir() + "/" +
modified_name);
- if(file_data.empty()) {
- file_data = read_file(get_saves_dir() + "/" + name);
- }
+ scoped_istream file_stream = stream_file(get_saves_dir() + "/" +
modified_name);
+ if (file_stream->fail())
+ file_stream = stream_file(get_saves_dir() + "/" + name);
cfg.clear();
- detect_format_and_read(cfg, file_data);
+ detect_format_and_read(cfg, *file_stream);
if(cfg.empty()) {
std::cerr << "Could not parse file data into config\n";
@@ -479,7 +478,8 @@
{
if(save_index_loaded == false) {
try {
- detect_format_and_read(save_index_cfg,
read_file(get_save_index_file()));
+ scoped_istream stream =
stream_file(get_save_index_file());
+ detect_format_and_read(save_index_cfg, *stream);
} catch(io_exception& e) {
std::cerr << "error reading save index: '" << e.what()
<< "'\n";
} catch(config::error&) {
Index: wesnoth/src/help.cpp
diff -u wesnoth/src/help.cpp:1.82 wesnoth/src/help.cpp:1.83
--- wesnoth/src/help.cpp:1.82 Thu Mar 24 21:35:52 2005
+++ wesnoth/src/help.cpp Fri Mar 25 18:19:20 2005
@@ -1677,7 +1677,8 @@
// Should be parsed as WML.
try {
config cfg;
- read(cfg, *it);
+ std::istringstream stream(*it);
+ read(cfg, stream);
config *child = cfg.child("ref");
if (child != NULL) {
handle_ref_cfg(*child);
Index: wesnoth/src/language.cpp
diff -u wesnoth/src/language.cpp:1.79 wesnoth/src/language.cpp:1.80
--- wesnoth/src/language.cpp:1.79 Fri Mar 25 15:43:42 2005
+++ wesnoth/src/language.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: language.cpp,v 1.79 2005/03/25 15:43:42 silene Exp $ */
+/* $Id: language.cpp,v 1.80 2005/03/25 18:19:20 silene Exp $ */
/* vim:set encoding=utf-8: */
/*
Copyright (C) 2003 by David White <address@hidden>
@@ -15,6 +15,7 @@
#include "global.hpp"
#include "config.hpp"
+#include "filesystem.hpp"
#include "gettext.hpp"
#include "language.hpp"
#include "preferences.hpp"
@@ -158,7 +159,8 @@
// fill string_table (should be moved somwhere else some day)
try {
- read(cfg, preprocess_file("data/translations/english.cfg"));
+ scoped_istream stream =
preprocess_file("data/translations/english.cfg");
+ read(cfg, *stream);
} catch(config::error& e) {
std::cerr << "Could not read english.cfg\n";
throw e;
Index: wesnoth/src/preferences.cpp
diff -u wesnoth/src/preferences.cpp:1.145 wesnoth/src/preferences.cpp:1.146
--- wesnoth/src/preferences.cpp:1.145 Thu Mar 24 21:35:52 2005
+++ wesnoth/src/preferences.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: preferences.cpp,v 1.145 2005/03/24 21:35:52 ydirson Exp $ */
+/* $Id: preferences.cpp,v 1.146 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -68,7 +68,8 @@
manager::manager()
{
- read(prefs, read_file(get_prefs_file()));
+ scoped_istream stream = stream_file(get_prefs_file());
+ read(prefs, *stream);
set_music_volume(music_volume());
set_sound_volume(sound_volume());
Index: wesnoth/src/publish_campaign.cpp
diff -u wesnoth/src/publish_campaign.cpp:1.6
wesnoth/src/publish_campaign.cpp:1.7
--- wesnoth/src/publish_campaign.cpp:1.6 Sat Mar 5 10:54:25 2005
+++ wesnoth/src/publish_campaign.cpp Fri Mar 25 18:19:20 2005
@@ -26,7 +26,8 @@
void get_campaign_info(const std::string& campaign_name, config& cfg)
{
- read(cfg, read_file(campaign_dir() + "/" + campaign_name + ".pbl"));
+ scoped_istream stream = stream_file(campaign_dir() + "/" +
campaign_name + ".pbl");
+ read(cfg, *stream);
}
void set_campaign_info(const std::string& campaign_name, const config& cfg)
Index: wesnoth/src/serialization/binary_or_text.cpp
diff -u wesnoth/src/serialization/binary_or_text.cpp:1.2
wesnoth/src/serialization/binary_or_text.cpp:1.3
--- wesnoth/src/serialization/binary_or_text.cpp:1.2 Fri Mar 25 16:43:54 2005
+++ wesnoth/src/serialization/binary_or_text.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_or_text.cpp,v 1.2 2005/03/25 16:43:54 silene Exp $ */
+/* $Id: binary_or_text.cpp,v 1.3 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -16,17 +16,14 @@
#include "serialization/binary_wml.hpp"
#include "serialization/parser.hpp"
-#include <sstream>
-
-bool detect_format_and_read(config &cfg, std::string const &data)
+bool detect_format_and_read(config &cfg, std::istream &in)
{
try {
- std::istringstream stream(data);
- read_compressed(cfg, stream);
+ read_compressed(cfg, in);
return true;
} catch (config::error &) {
}
- read(cfg, data);
+ read(cfg, in);
return false;
}
Index: wesnoth/src/serialization/parser.cpp
diff -u wesnoth/src/serialization/parser.cpp:1.5
wesnoth/src/serialization/parser.cpp:1.6
--- wesnoth/src/serialization/parser.cpp:1.5 Thu Mar 24 19:56:33 2005
+++ wesnoth/src/serialization/parser.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: parser.cpp,v 1.5 2005/03/24 19:56:33 silene Exp $ */
+/* $Id: parser.cpp,v 1.6 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -50,8 +50,17 @@
return res;
}
-void read(config &cfg, std::string const &data, std::vector< line_source >
const *line_sources)
+void read(config &cfg, std::istream &data_in, std::vector< line_source > const
*line_sources)
{
+ std::string data_str;
+ {
+ //temporary, only here to accomodate the old parser
+ std::stringstream tmp_in;
+ tmp_in << data_in.rdbuf();
+ data_str = tmp_in.str();
+ }
+ std::string const &data = data_str;
+
cfg.clear();
std::stack< std::string > element_names;
Index: wesnoth/src/serialization/parser.hpp
diff -u wesnoth/src/serialization/parser.hpp:1.2
wesnoth/src/serialization/parser.hpp:1.3
--- wesnoth/src/serialization/parser.hpp:1.2 Tue Mar 8 02:26:03 2005
+++ wesnoth/src/serialization/parser.hpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: parser.hpp,v 1.2 2005/03/08 02:26:03 Sirp Exp $ */
+/* $Id: parser.hpp,v 1.3 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -14,7 +14,7 @@
#ifndef SERIALIZATION_PARSER_HPP_INCLUDED
#define SERIALIZATION_PARSER_HPP_INCLUDED
-#include <string>
+#include <iosfwd>
#include <vector>
class config;
@@ -23,13 +23,13 @@
line_source get_line_source(std::vector< line_source > const &line_src, int
line);
//read data in, clobbering existing data.
-void read(config &cfg, std::string const &data, std::vector< line_source >
const *lines = 0); //throws config::error
+void read(config &cfg, std::istream &in, std::vector< line_source > const
*lines = 0); //throws config::error
std::string write(config const &cfg);
//function which reads a file, and automatically detects whether it's
compressed or not before
//reading it. If it's not a valid file at all, it will throw an error as if it
was trying to
//read it as text WML. Returns true iff the format is compressed
-bool detect_format_and_read(config &cfg, std::string const &data); //throws
config::error
+bool detect_format_and_read(config &cfg, std::istream &in); //throws
config::error
#endif
Index: wesnoth/src/serialization/preprocessor.cpp
diff -u wesnoth/src/serialization/preprocessor.cpp:1.3
wesnoth/src/serialization/preprocessor.cpp:1.4
--- wesnoth/src/serialization/preprocessor.cpp:1.3 Fri Mar 25 16:10:09 2005
+++ wesnoth/src/serialization/preprocessor.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.cpp,v 1.3 2005/03/25 16:10:09 silene Exp $ */
+/* $Id: preprocessor.cpp,v 1.4 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -389,7 +389,7 @@
} //end anonymous namespace
-std::string preprocess_file(std::string const &fname,
+std::istream *preprocess_file(std::string const &fname,
const preproc_map* defines,
std::vector<line_source>* line_sources)
{
@@ -401,5 +401,5 @@
std::vector<char> res;
int linenum = 0;
internal_preprocess_file(fname,defines_copy,0,res,line_sources,linenum);
- return std::string(res.begin(),res.end());
+ return new std::istringstream(std::string(res.begin(), res.end()));
}
Index: wesnoth/src/serialization/preprocessor.hpp
diff -u wesnoth/src/serialization/preprocessor.hpp:1.2
wesnoth/src/serialization/preprocessor.hpp:1.3
--- wesnoth/src/serialization/preprocessor.hpp:1.2 Sat Mar 5 10:54:25 2005
+++ wesnoth/src/serialization/preprocessor.hpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.hpp,v 1.2 2005/03/05 10:54:25 silene Exp $ */
+/* $Id: preprocessor.hpp,v 1.3 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -14,6 +14,7 @@
#ifndef SERIALIZATION_PREPROCESSOR_HPP_INCLUDED
#define SERIALIZATION_PREPROCESSOR_HPP_INCLUDED
+#include <iosfwd>
#include <map>
#include <string>
#include <vector>
@@ -48,8 +49,8 @@
//function to use the WML preprocessor on a file, and returns the resulting
//preprocessed file data. defines is a map of symbols defined. src is used
//internally and should be set to NULL
-std::string preprocess_file(std::string const &fname,
- preproc_map const *defines = NULL,
- std::vector< line_source > *src = NULL);
+std::istream *preprocess_file(std::string const &fname,
+ preproc_map const *defines = NULL,
+ std::vector< line_source > *src = NULL);
#endif
Index: wesnoth/src/titlescreen.cpp
diff -u wesnoth/src/titlescreen.cpp:1.38 wesnoth/src/titlescreen.cpp:1.39
--- wesnoth/src/titlescreen.cpp:1.38 Thu Mar 24 21:35:52 2005
+++ wesnoth/src/titlescreen.cpp Fri Mar 25 18:19:20 2005
@@ -4,6 +4,7 @@
#include "cursor.hpp"
#include "display.hpp"
#include "events.hpp"
+#include "filesystem.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "hotkeys.hpp"
@@ -126,7 +127,8 @@
std::cerr << "Loading tips of day\n";
try {
- read(cfg, preprocess_file("data/tips.cfg"));
+ scoped_istream stream = preprocess_file("data/tips.cfg");
+ read(cfg, *stream);
} catch(config::error&) {
std::cerr << "Could not read tips.cfg\n";
}
Index: wesnoth/src/tools/exploder_cutter.cpp
diff -u wesnoth/src/tools/exploder_cutter.cpp:1.5
wesnoth/src/tools/exploder_cutter.cpp:1.6
--- wesnoth/src/tools/exploder_cutter.cpp:1.5 Sat Mar 5 10:54:25 2005
+++ wesnoth/src/tools/exploder_cutter.cpp Fri Mar 25 18:19:20 2005
@@ -1,4 +1,4 @@
-/* $Id: exploder_cutter.cpp,v 1.5 2005/03/05 10:54:25 silene Exp $ */
+/* $Id: exploder_cutter.cpp,v 1.6 2005/03/25 18:19:20 silene Exp $ */
/*
Copyright (C) 2004 by Philippe Plantier <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -27,12 +27,12 @@
const config cutter::load_config(const std::string &filename)
{
const std::string conf_string = find_configuration(filename);
- const std::string pre_conf_string = preprocess_file(conf_string);
config res;
try {
- read(res, pre_conf_string);
+ scoped_istream stream = preprocess_file(conf_string);
+ read(res, *stream);
} catch(config::error err) {
throw exploder_failure("Unable to load the configuration for
the file " + filename + ": "+ err.message);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp font....,
Guillaume Melquiond <=