Get rid of binary WML
This commit is contained in:
parent
31d5fe3c3b
commit
5f91c3bd4a
15 changed files with 0 additions and 363 deletions
|
@ -612,8 +612,6 @@
|
|||
<Unit filename="..\..\src\sdl_utils.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.hpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.cpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.hpp" />
|
||||
<Unit filename="..\..\src\serialization\preprocessor.cpp" />
|
||||
|
|
|
@ -58,8 +58,6 @@
|
|||
<Unit filename="..\..\src\scoped_resource.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.hpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.cpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.hpp" />
|
||||
<Unit filename="..\..\src\serialization\preprocessor.cpp" />
|
||||
|
|
|
@ -673,8 +673,6 @@
|
|||
<Unit filename="..\..\src\sdl_utils.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.hpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.cpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.hpp" />
|
||||
<Unit filename="..\..\src\serialization\preprocessor.cpp" />
|
||||
|
|
|
@ -72,8 +72,6 @@
|
|||
<Unit filename="..\..\src\scoped_resource.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_or_text.hpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.cpp" />
|
||||
<Unit filename="..\..\src\serialization\binary_wml.hpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.cpp" />
|
||||
<Unit filename="..\..\src\serialization\parser.hpp" />
|
||||
<Unit filename="..\..\src\serialization\preprocessor.cpp" />
|
||||
|
|
|
@ -159,16 +159,6 @@ Priority=1000
|
|||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit87]
|
||||
FileName=..\..\src\serialization\binary_wml.cpp
|
||||
CompileCpp=1
|
||||
Folder=Wesnoth
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit88]
|
||||
FileName=..\..\src\serialization\parser.cpp
|
||||
CompileCpp=1
|
||||
|
@ -619,16 +609,6 @@ Priority=1000
|
|||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit151]
|
||||
FileName=..\..\src\serialization\binary_wml.cpp
|
||||
CompileCpp=1
|
||||
Folder=Wesnoth
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit152]
|
||||
FileName=..\..\src\serialization\parser.cpp
|
||||
CompileCpp=1
|
||||
|
|
|
@ -1827,16 +1827,6 @@ Priority=1000
|
|||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit35]
|
||||
FileName=..\..\src\serialization\binary_wml.cpp
|
||||
CompileCpp=1
|
||||
Folder=Sources/serialization
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit36]
|
||||
FileName=..\..\src\gui\dialogs\language_selection.cpp
|
||||
CompileCpp=1
|
||||
|
|
|
@ -989,16 +989,6 @@ Priority=1000
|
|||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit180]
|
||||
FileName=..\..\src\serialization\binary_wml.cpp
|
||||
CompileCpp=1
|
||||
Folder=Wesnoth
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit182]
|
||||
FileName=..\..\src\serialization\parser.cpp
|
||||
CompileCpp=1
|
||||
|
@ -2327,16 +2317,6 @@ Priority=1000
|
|||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=..\..\src\serialization\binary_wml.cpp
|
||||
CompileCpp=1
|
||||
Folder=wesnothd
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=..\..\src\color_range.cpp
|
||||
CompileCpp=1
|
||||
|
|
|
@ -204,10 +204,6 @@
|
|||
RelativePath="..\..\src\serialization\binary_or_text.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\serialization\binary_wml.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\serialization\parser.cpp"
|
||||
>
|
||||
|
@ -302,10 +298,6 @@
|
|||
RelativePath="..\..\src\serialization\binary_or_text.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\serialization\binary_wml.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\serialization\parser.hpp"
|
||||
>
|
||||
|
|
|
@ -271,7 +271,6 @@
|
|||
B5599B020EC62181008DD061 /* sha1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A30EC62181008DD061 /* sha1.cpp */; };
|
||||
B5599B030EC62181008DD061 /* settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A50EC62181008DD061 /* settings.cpp */; };
|
||||
B5599B040EC62181008DD061 /* binary_or_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A70EC62181008DD061 /* binary_or_text.cpp */; };
|
||||
B5599B050EC62181008DD061 /* binary_wml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A90EC62181008DD061 /* binary_wml.cpp */; };
|
||||
B5599B060EC62181008DD061 /* parser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999AB0EC62181008DD061 /* parser.cpp */; };
|
||||
B5599B070EC62181008DD061 /* preprocessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999AD0EC62181008DD061 /* preprocessor.cpp */; };
|
||||
B5599B080EC62181008DD061 /* string_utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999AF0EC62181008DD061 /* string_utils.cpp */; };
|
||||
|
@ -566,7 +565,6 @@
|
|||
B597C59A0FACD6CA00CE81F5 /* editor_main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B559A0030EC8FE2E008DD061 /* editor_main.cpp */; };
|
||||
B597C59B0FACD6CA00CE81F5 /* listbox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5A9BCFF0ECA805A002BE442 /* listbox.cpp */; };
|
||||
B597C59C0FACD6CA00CE81F5 /* action.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599FF70EC8FE2E008DD061 /* action.cpp */; };
|
||||
B597C59D0FACD6CA00CE81F5 /* binary_wml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A90EC62181008DD061 /* binary_wml.cpp */; };
|
||||
B597C59E0FACD6CA00CE81F5 /* color_range.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AAA0EC62181008DD061 /* color_range.cpp */; };
|
||||
B597C59F0FACD6CA00CE81F5 /* game_events.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599A7B0EC62181008DD061 /* game_events.cpp */; };
|
||||
B597C5A00FACD6CA00CE81F5 /* theme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B559998D0EC62181008DD061 /* theme.cpp */; };
|
||||
|
@ -838,7 +836,6 @@
|
|||
B5BB6C7B0F89427C00444FBF /* gettext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599A710EC62181008DD061 /* gettext.cpp */; };
|
||||
B5BB6C800F89435300444FBF /* log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599A020EC62181008DD061 /* log.cpp */; };
|
||||
B5BB6C820F89437400444FBF /* color_range.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AAA0EC62181008DD061 /* color_range.cpp */; };
|
||||
B5BB6C840F8943B000444FBF /* binary_wml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A90EC62181008DD061 /* binary_wml.cpp */; };
|
||||
B5BB6C860F8943F600444FBF /* config_cache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5599AA40EC62181008DD061 /* config_cache.cpp */; };
|
||||
B5BB6C880F89441700444FBF /* sha1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A30EC62181008DD061 /* sha1.cpp */; };
|
||||
B5BB6C8D0F89447200444FBF /* binary_or_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999A70EC62181008DD061 /* binary_or_text.cpp */; };
|
||||
|
@ -1276,8 +1273,6 @@
|
|||
B55999A50EC62181008DD061 /* settings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = settings.cpp; path = ../src/settings.cpp; sourceTree = "<group>"; };
|
||||
B55999A70EC62181008DD061 /* binary_or_text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binary_or_text.cpp; sourceTree = "<group>"; };
|
||||
B55999A80EC62181008DD061 /* binary_or_text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = binary_or_text.hpp; sourceTree = "<group>"; };
|
||||
B55999A90EC62181008DD061 /* binary_wml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = binary_wml.cpp; sourceTree = "<group>"; };
|
||||
B55999AA0EC62181008DD061 /* binary_wml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = binary_wml.hpp; sourceTree = "<group>"; };
|
||||
B55999AB0EC62181008DD061 /* parser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parser.cpp; sourceTree = "<group>"; };
|
||||
B55999AC0EC62181008DD061 /* parser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parser.hpp; sourceTree = "<group>"; };
|
||||
B55999AD0EC62181008DD061 /* preprocessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = preprocessor.cpp; sourceTree = "<group>"; };
|
||||
|
@ -2618,8 +2613,6 @@
|
|||
children = (
|
||||
B55999A70EC62181008DD061 /* binary_or_text.cpp */,
|
||||
B55999A80EC62181008DD061 /* binary_or_text.hpp */,
|
||||
B55999A90EC62181008DD061 /* binary_wml.cpp */,
|
||||
B55999AA0EC62181008DD061 /* binary_wml.hpp */,
|
||||
B55999AB0EC62181008DD061 /* parser.cpp */,
|
||||
B55999AC0EC62181008DD061 /* parser.hpp */,
|
||||
B55999AD0EC62181008DD061 /* preprocessor.cpp */,
|
||||
|
@ -3307,7 +3300,6 @@
|
|||
B5599B020EC62181008DD061 /* sha1.cpp in Sources */,
|
||||
B5599B030EC62181008DD061 /* settings.cpp in Sources */,
|
||||
B5599B040EC62181008DD061 /* binary_or_text.cpp in Sources */,
|
||||
B5599B050EC62181008DD061 /* binary_wml.cpp in Sources */,
|
||||
B5599B060EC62181008DD061 /* parser.cpp in Sources */,
|
||||
B5599B070EC62181008DD061 /* preprocessor.cpp in Sources */,
|
||||
B5599B080EC62181008DD061 /* string_utils.cpp in Sources */,
|
||||
|
@ -3751,7 +3743,6 @@
|
|||
B597C59A0FACD6CA00CE81F5 /* editor_main.cpp in Sources */,
|
||||
B597C59B0FACD6CA00CE81F5 /* listbox.cpp in Sources */,
|
||||
B597C59C0FACD6CA00CE81F5 /* action.cpp in Sources */,
|
||||
B597C59D0FACD6CA00CE81F5 /* binary_wml.cpp in Sources */,
|
||||
B597C59E0FACD6CA00CE81F5 /* color_range.cpp in Sources */,
|
||||
B597C59F0FACD6CA00CE81F5 /* game_events.cpp in Sources */,
|
||||
B597C5A00FACD6CA00CE81F5 /* theme.cpp in Sources */,
|
||||
|
@ -4066,7 +4057,6 @@
|
|||
B5BB6C7B0F89427C00444FBF /* gettext.cpp in Sources */,
|
||||
B5BB6C800F89435300444FBF /* log.cpp in Sources */,
|
||||
B5BB6C820F89437400444FBF /* color_range.cpp in Sources */,
|
||||
B5BB6C840F8943B000444FBF /* binary_wml.cpp in Sources */,
|
||||
B5BB6C860F8943F600444FBF /* config_cache.cpp in Sources */,
|
||||
B5BB6C880F89441700444FBF /* sha1.cpp in Sources */,
|
||||
B5BB6C8D0F89447200444FBF /* binary_or_text.cpp in Sources */,
|
||||
|
|
|
@ -209,7 +209,6 @@ set(libwesnoth-core_STAT_SRC
|
|||
util.cpp
|
||||
version.cpp
|
||||
serialization/binary_or_text.cpp
|
||||
serialization/binary_wml.cpp
|
||||
serialization/parser.cpp
|
||||
serialization/preprocessor.cpp
|
||||
serialization/string_utils.cpp
|
||||
|
|
|
@ -495,7 +495,6 @@ libwesnoth_core_a_SOURCES = \
|
|||
util.cpp \
|
||||
version.cpp \
|
||||
serialization/binary_or_text.cpp \
|
||||
serialization/binary_wml.cpp \
|
||||
serialization/parser.cpp \
|
||||
serialization/preprocessor.cpp \
|
||||
serialization/string_utils.cpp \
|
||||
|
|
|
@ -27,7 +27,6 @@ libwesnoth_core_sources = Split("""
|
|||
util.cpp
|
||||
version.cpp
|
||||
serialization/binary_or_text.cpp
|
||||
serialization/binary_wml.cpp
|
||||
serialization/parser.cpp
|
||||
serialization/preprocessor.cpp
|
||||
serialization/string_utils.cpp
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "wesconfig.h"
|
||||
#include "serialization/binary_wml.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
|
||||
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2005 - 2010 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Data compression, designed for network traffic.
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/binary_wml.hpp"
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
|
||||
// Data compression. Compression is designed for network traffic.
|
||||
// Assumptions the compression is based on:
|
||||
// - most space is taken up by element names and attribute names
|
||||
// - there are relatively few element names and attribute names
|
||||
// that are repeated many times
|
||||
//
|
||||
// How it works: there are some control characters:
|
||||
// 'compress_open_element': signals that the next word found is an element.
|
||||
// Any words found that are not after this are assumed to be attributes:
|
||||
// 'compress_close_element': signals to close the current element.
|
||||
// 'compress_schema_item': signals that following is a nul-delimited string,
|
||||
// which should be added as a word in the schema.
|
||||
// 'compress_literal_word': signals that following is a word stored as a nul-delimited string
|
||||
// (an attribute name, unless it was preceeded by 'compress_open_element').
|
||||
//
|
||||
// All other characters are mapped to words. When an item is inserted into the schema,
|
||||
// it is mapped to the first available character. Any attribute found is always followed
|
||||
// by a nul-delimited string which is the value for the attribute.
|
||||
//
|
||||
// The schema objects are designed to be persisted. That is, in a network game,
|
||||
// both peers can store their schema objects, and so rather than sending
|
||||
// schema data each time, the peers use and build their schemas as the
|
||||
// game progresses, adding a new word to the schema anytime it is required.
|
||||
|
||||
static const unsigned int
|
||||
compress_open_element = 0, compress_close_element = 1,
|
||||
compress_schema_item = 2, compress_literal_word = 3,
|
||||
compress_first_word = 4, compress_end_words = 256;
|
||||
static const size_t compress_max_words = compress_end_words - compress_first_word;
|
||||
static const size_t max_schema_item_length = 20;
|
||||
static const int max_recursion_levels = 1000;
|
||||
|
||||
static void compress_output_literal_word(std::ostream &out, std::string const &word)
|
||||
{
|
||||
out.write(word.c_str(), word.length() + 1);
|
||||
}
|
||||
|
||||
static compression_schema::word_char_map::const_iterator
|
||||
add_word_to_schema(std::string const &word, compression_schema &schema)
|
||||
{
|
||||
if (word.size() > max_schema_item_length)
|
||||
throw config::error("Schema item is too long");
|
||||
|
||||
unsigned int c = compress_first_word + schema.word_to_char.size();
|
||||
|
||||
schema.char_to_word.insert(std::make_pair(c, word));
|
||||
return schema.word_to_char.insert(std::make_pair(word, c)).first;
|
||||
}
|
||||
|
||||
static compression_schema::word_char_map::const_iterator
|
||||
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();
|
||||
|
||||
// See if this word is already in the schema
|
||||
const compression_schema::word_char_map::const_iterator w = schema.word_to_char.find(word);
|
||||
if (w != schema.word_to_char.end()) {
|
||||
// It is in the schema. Return it.
|
||||
return w;
|
||||
} else if (schema.word_to_char.size() < compress_max_words) {
|
||||
// We can add the word to the schema
|
||||
|
||||
// We insert the code to add a schema item, followed by the zero-delimited word.
|
||||
out.put(compress_schema_item);
|
||||
compress_output_literal_word(out, word);
|
||||
|
||||
return add_word_to_schema(word, schema);
|
||||
} else {
|
||||
// It is not there, and there is no room to add it
|
||||
return schema.word_to_char.end();
|
||||
}
|
||||
}
|
||||
|
||||
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, 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.
|
||||
out.put(w->second);
|
||||
} else {
|
||||
// The word is not in the schema. Output it as a literal word.
|
||||
out.put(compress_literal_word);
|
||||
compress_output_literal_word(out, word);
|
||||
}
|
||||
}
|
||||
|
||||
static std::string compress_read_literal_word(std::istream &in)
|
||||
{
|
||||
std::string buffer;
|
||||
std::getline(in, buffer, '\0');
|
||||
if (!in.good())
|
||||
throw config::error("Unexpected end of data in compressed config read");
|
||||
return buffer;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
foreach (const config::attribute &i, cfg.attribute_range()) {
|
||||
if (!i.second.empty()) {
|
||||
// Output the name, using compression
|
||||
compress_emit_word(out, i.first, schema);
|
||||
|
||||
// Output the value, with no compression
|
||||
compress_output_literal_word(out, i.second.t_str().to_serialized());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const config::any_child &item, cfg.all_children_range())
|
||||
{
|
||||
out.put(compress_open_element);
|
||||
compress_emit_word(out, item.key, schema);
|
||||
write_compressed_internal(out, item.cfg, schema, level + 1);
|
||||
out.put(compress_close_element);
|
||||
}
|
||||
}
|
||||
|
||||
void write_compressed(std::ostream &out, config const &cfg, compression_schema &schema)
|
||||
{
|
||||
write_compressed_internal(out, cfg, schema, 0);
|
||||
}
|
||||
|
||||
static void read_compressed_internal(config &cfg, std::istream &in, compression_schema &schema, int level)
|
||||
{
|
||||
if (level >= max_recursion_levels)
|
||||
throw config::error("Too many recursion levels in compressed config read");
|
||||
|
||||
bool in_open_element = false;
|
||||
for(;;) {
|
||||
unsigned char const c = in.get();
|
||||
if (!in.good())
|
||||
return;
|
||||
switch (c) {
|
||||
case compress_open_element:
|
||||
in_open_element = true;
|
||||
break;
|
||||
case compress_close_element:
|
||||
return;
|
||||
case compress_schema_item:
|
||||
add_word_to_schema(compress_read_literal_word(in), schema);
|
||||
break;
|
||||
|
||||
default: {
|
||||
std::string word;
|
||||
if (c == compress_literal_word) {
|
||||
word = compress_read_literal_word(in);
|
||||
} else {
|
||||
unsigned int code = c;
|
||||
|
||||
const compression_schema::char_word_map::const_iterator itor
|
||||
= schema.char_to_word.find(code);
|
||||
if (itor == schema.char_to_word.end()) {
|
||||
ERR_CF << "illegal word code: " << code << "\n";
|
||||
throw config::error("Illegal character in compression input");
|
||||
}
|
||||
|
||||
word = itor->second;
|
||||
}
|
||||
|
||||
if (in_open_element) {
|
||||
in_open_element = false;
|
||||
config &cfg2 = cfg.add_child(word);
|
||||
read_compressed_internal(cfg2, in, schema, level + 1);
|
||||
} else {
|
||||
// We have a name/value pair, the value is always a literal string
|
||||
std::string value = compress_read_literal_word(in);
|
||||
t_string t_value = t_string::from_serialized(value);
|
||||
cfg[word] = t_value;
|
||||
}
|
||||
}
|
||||
|
||||
} // end switch
|
||||
}
|
||||
}
|
||||
|
||||
void read_compressed(config &cfg, std::istream &in, compression_schema &schema)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2003 by David White <dave@whitevine.net>
|
||||
Copyright (C) 2005 - 2010 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
|
||||
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 SERIALIZATION_BINARY_WML_HPP_INCLUDED
|
||||
#define SERIALIZATION_BINARY_WML_HPP_INCLUDED
|
||||
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class config;
|
||||
|
||||
/** Holds the schema by which config objects can be compressed and decompressed. */
|
||||
struct compression_schema
|
||||
{
|
||||
compression_schema() : char_to_word(), word_to_char() { }
|
||||
|
||||
typedef std::map< unsigned int, std::string > char_word_map;
|
||||
char_word_map char_to_word;
|
||||
|
||||
typedef std::map< std::string, unsigned int > word_char_map;
|
||||
word_char_map word_to_char;
|
||||
};
|
||||
|
||||
// Read and write compressed data.
|
||||
|
||||
/**
|
||||
* Write compressed data.
|
||||
*
|
||||
* The schema will be created and written with the data. However if you are
|
||||
* making successive writes (e.g. a network connection), 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.
|
||||
*/
|
||||
void write_compressed(std::ostream &out, config const &cfg, compression_schema &schema);
|
||||
|
||||
/** Read compressed data. */
|
||||
void read_compressed(config &cfg, std::istream &in, compression_schema &schema); //throws config::error
|
||||
|
||||
void write_compressed(std::ostream &out, config const &cfg);
|
||||
void read_compressed(config &cfg, std::istream &in);
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue