[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src game.cpp gamestatus.cpp network.cpp...
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src game.cpp gamestatus.cpp network.cpp... |
Date: |
Fri, 25 Mar 2005 14:35:28 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/03/25 19:35:28
Modified files:
src : game.cpp gamestatus.cpp network.cpp
src/campaign_server: campaign_server.cpp
src/serialization: binary_wml.cpp binary_wml.hpp
Log message:
Switch the compressed writer to using stream too.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/game.cpp.diff?tr1=1.216&tr2=1.217&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/gamestatus.cpp.diff?tr1=1.63&tr2=1.64&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network.cpp.diff?tr1=1.58&tr2=1.59&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/campaign_server/campaign_server.cpp.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_wml.cpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/binary_wml.hpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: wesnoth/src/campaign_server/campaign_server.cpp
diff -u wesnoth/src/campaign_server/campaign_server.cpp:1.12
wesnoth/src/campaign_server/campaign_server.cpp:1.13
--- wesnoth/src/campaign_server/campaign_server.cpp:1.12 Fri Mar 25
18:19:20 2005
+++ wesnoth/src/campaign_server/campaign_server.cpp Fri Mar 25 19:35:27 2005
@@ -127,10 +127,10 @@
const config* const data =
upload->child("data");
if(data != NULL) {
- compression_schema
schema;
- const std::string&
filedata = write_compressed(*data, schema);
-
write_file((*campaign)["filename"],filedata);
- (*campaign)["size"] =
lexical_cast<std::string>(filedata.size());
+ std::ostringstream
filedata;
+
write_compressed(filedata, *data);
+
write_file((*campaign)["filename"], filedata.str());
+ (*campaign)["size"] =
lexical_cast<std::string>(filedata.str().size());
}
write_file(file_, write(cfg_));
Index: wesnoth/src/game.cpp
diff -u wesnoth/src/game.cpp:1.216 wesnoth/src/game.cpp:1.217
--- wesnoth/src/game.cpp:1.216 Fri Mar 25 18:19:20 2005
+++ wesnoth/src/game.cpp Fri Mar 25 19:35:27 2005
@@ -1,4 +1,4 @@
-/* $Id: game.cpp,v 1.216 2005/03/25 18:19:20 silene Exp $ */
+/* $Id: game.cpp,v 1.217 2005/03/25 19:35:27 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -287,7 +287,9 @@
scoped_istream stream =
preprocess_file("data/game.cfg", &defines, &line_src);
read(cfg, *stream, &line_src);
try {
- write_file(fname,
write_compressed(cfg));
+ std::ostringstream cache;
+ write_compressed(cache, cfg);
+ write_file(fname, cache.str());
config checksum_cfg;
data_tree_checksum().write(checksum_cfg);
@@ -1543,8 +1545,13 @@
return 0;
}
- const std::string res(compress ?
write_compressed(cfg) : write(cfg));
- write_file(output,res);
+ std::string res;
+ if (compress) {
+ std::ostringstream savefile;
+ write_compressed(savefile, cfg);
+ res = savefile.str();
+ } else res = write(cfg);
+ write_file(output, res);
} catch(config::error& e) {
std::cerr << input << " is not a valid Wesnoth
file: " << e.message << "\n";
Index: wesnoth/src/gamestatus.cpp
diff -u wesnoth/src/gamestatus.cpp:1.63 wesnoth/src/gamestatus.cpp:1.64
--- wesnoth/src/gamestatus.cpp:1.63 Fri Mar 25 18:19:20 2005
+++ wesnoth/src/gamestatus.cpp Fri Mar 25 19:35:27 2005
@@ -1,4 +1,4 @@
-/* $Id: gamestatus.cpp,v 1.63 2005/03/25 18:19:20 silene Exp $ */
+/* $Id: gamestatus.cpp,v 1.64 2005/03/25 19:35:27 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -455,7 +455,13 @@
const std::string fname = get_saves_dir() + "/" + name;
- write_file(fname, preferences::compress_saves() ?
write_compressed(cfg) : write(cfg));
+ std::string savefile;
+ if (preferences::compress_saves()) {
+ std::ostringstream stream;
+ write_compressed(stream, cfg);
+ savefile = stream.str();
+ } else savefile = write(cfg);
+ write_file(fname, savefile);
config& summary = save_summary(state.label);
extract_summary_data_from_save(state,summary);
@@ -520,7 +526,9 @@
{
log_scope("write_save_index()");
try {
- write_file(get_save_index_file(),
write_compressed(save_index()));
+ std::ostringstream index;
+ write_compressed(index, save_index());
+ write_file(get_save_index_file(), index.str());
} catch(io_exception& e) {
std::cerr << "error writing to save index file: '" << e.what()
<< "'\n";
}
Index: wesnoth/src/network.cpp
diff -u wesnoth/src/network.cpp:1.58 wesnoth/src/network.cpp:1.59
--- wesnoth/src/network.cpp:1.58 Fri Mar 25 16:43:54 2005
+++ wesnoth/src/network.cpp Fri Mar 25 19:35:27 2005
@@ -570,7 +570,9 @@
const schema_map::iterator schema = schemas.find(connection_num);
wassert(schema != schemas.end());
- const std::string& value =
write_compressed(cfg,schema->second.outgoing);
+ std::ostringstream compressor;
+ write_compressed(compressor, cfg, schema->second.outgoing);
+ std::string const &value = compressor.str();
// std::cerr << "--- SEND DATA to " << ((int)connection_num) << ": '"
// << cfg.write() << "'\n--- END SEND DATA\n";
Index: wesnoth/src/serialization/binary_wml.cpp
diff -u wesnoth/src/serialization/binary_wml.cpp:1.4
wesnoth/src/serialization/binary_wml.cpp:1.5
--- wesnoth/src/serialization/binary_wml.cpp:1.4 Fri Mar 25 16:43:54 2005
+++ wesnoth/src/serialization/binary_wml.cpp Fri Mar 25 19:35:27 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_wml.cpp,v 1.4 2005/03/25 16:43:54 silene Exp $ */
+/* $Id: binary_wml.cpp,v 1.5 2005/03/25 19:35:27 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -24,16 +24,6 @@
#define ERR_CF lg::err(lg::config)
-std::string write_compressed(config const &cfg) {
- compression_schema schema;
- return write_compressed(cfg, schema);
-}
-
-void read_compressed(config &cfg, std::istream &in) {
- compression_schema schema;
- read_compressed(cfg, in, schema);
-}
-
//data compression. Compression is designed for network traffic.
//assumptions compression is based on:
// - most space is taken up by element names and attribute names
@@ -65,11 +55,9 @@
static const size_t max_schema_item_length = 20;
static const int max_recursion_levels = 100;
-static void compress_output_literal_word(std::string const &word, std::vector<
char > &output)
+static void compress_output_literal_word(std::ostream &out, std::string const
&word)
{
- output.resize(output.size() + word.size());
- std::copy(word.begin(), word.end(), output.end() - word.size());
- output.push_back(char(0));
+ out.write(word.c_str(), word.length() + 1);
}
static compression_schema::word_char_map::const_iterator
@@ -85,7 +73,7 @@
}
static compression_schema::word_char_map::const_iterator
-get_word_in_schema(std::string const &word, compression_schema &schema,
std::vector< char > &output)
+get_word_in_schema(std::string const &word, compression_schema &schema,
std::ostream &out)
{
if (word.size() > max_schema_item_length)
return schema.word_to_char.end();
@@ -99,8 +87,8 @@
//we can add the word to the schema
//we insert the code to add a schema item, followed by the
zero-delimited word
- output.push_back(char(compress_schema_item));
- compress_output_literal_word(word, output);
+ out.put(compress_schema_item);
+ compress_output_literal_word(out, word);
return add_word_to_schema(word, schema);
} else {
@@ -109,17 +97,17 @@
}
}
-static void compress_emit_word(std::string const &word, compression_schema
&schema, std::vector< char > &res)
+static void compress_emit_word(std::ostream &out, std::string const &word,
compression_schema &schema)
{
//get the word in the schema
- const compression_schema::word_char_map::const_iterator w =
get_word_in_schema(word, schema, res);
+ const compression_schema::word_char_map::const_iterator w =
get_word_in_schema(word, schema, out);
if (w != schema.word_to_char.end()) {
//the word is in the schema, all we have to do is output the
compression code for it.
- res.push_back(w->second);
+ out.put(w->second);
} else {
//the word is not in the schema. Output it as a literal word
- res.push_back(char(compress_literal_word));
- compress_output_literal_word(word, res);
+ out.put(compress_literal_word);
+ compress_output_literal_word(out, word);
}
}
@@ -133,12 +121,12 @@
throw config::error("Unexpected end of data in
compressed config read\n");
if (c == 0)
break;
- stream << c;
+ stream.put(c);
}
return stream.str();
}
-static void write_compressed_internal(config const &cfg, compression_schema
&schema, std::vector< char > &res, int level)
+static void write_compressed_internal(std::ostream &out, config const &cfg,
compression_schema &schema, int level)
{
if (level > max_recursion_levels)
throw config::error("Too many recursion levels in compressed
config write\n");
@@ -146,10 +134,10 @@
for (string_map::const_iterator i = cfg.values.begin(), i_end =
cfg.values.end(); i != i_end; ++i) {
if (i->second.empty() == false) {
//output the name, using compression
- compress_emit_word(i->first, schema, res);
+ compress_emit_word(out, i->first, schema);
//output the value, with no compression
- compress_output_literal_word(i->second, res);
+ compress_output_literal_word(out, i->second);
}
}
@@ -158,21 +146,16 @@
std::string const &name = *item.first;
config const &cfg2 = *item.second;
- res.push_back(compress_open_element);
- compress_emit_word(name, schema, res);
- write_compressed_internal(cfg2, schema, res, level + 1);
- res.push_back(compress_close_element);
+ out.put(compress_open_element);
+ compress_emit_word(out, name, schema);
+ write_compressed_internal(out, cfg2, schema, level + 1);
+ out.put(compress_close_element);
}
}
-std::string write_compressed(config const &cfg, compression_schema &schema)
+void write_compressed(std::ostream &out, config const &cfg, compression_schema
&schema)
{
- std::vector< char > res;
- write_compressed_internal(cfg, schema, res, 0);
- std::string s;
- s.resize(res.size());
- std::copy(res.begin(), res.end(), s.begin());
- return s;
+ write_compressed_internal(out, cfg, schema, 0);
}
static void read_compressed_internal(config &cfg, std::istream &in,
compression_schema &schema, int level)
@@ -232,3 +215,13 @@
cfg.clear();
read_compressed_internal(cfg, in, schema, 0);
}
+
+void write_compressed(std::ostream &out, config const &cfg) {
+ compression_schema schema;
+ write_compressed(out, cfg, schema);
+}
+
+void read_compressed(config &cfg, std::istream &in) {
+ compression_schema schema;
+ read_compressed(cfg, in, schema);
+}
Index: wesnoth/src/serialization/binary_wml.hpp
diff -u wesnoth/src/serialization/binary_wml.hpp:1.3
wesnoth/src/serialization/binary_wml.hpp:1.4
--- wesnoth/src/serialization/binary_wml.hpp:1.3 Fri Mar 25 16:43:54 2005
+++ wesnoth/src/serialization/binary_wml.hpp Fri Mar 25 19:35:27 2005
@@ -1,4 +1,4 @@
-/* $Id: binary_wml.hpp,v 1.3 2005/03/25 16:43:54 silene Exp $ */
+/* $Id: binary_wml.hpp,v 1.4 2005/03/25 19:35:27 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -35,11 +35,10 @@
//you can re-use the same schema on the sending end, and the receiver can
store the schema,
//meaning that the entire schema won't have to be transmitted each time.
-std::string write_compressed(config const &cfg, compression_schema &schema);
+void write_compressed(std::ostream &out, config const &cfg, compression_schema
&schema);
void read_compressed(config &cfg, std::istream &in, compression_schema
&schema); //throws config::error
-
-std::string write_compressed(config const &cfg);
+void write_compressed(std::ostream &out, config const &cfg);
void read_compressed(config &cfg, std::istream &in);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src game.cpp gamestatus.cpp network.cpp...,
Guillaume Melquiond <=