aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-04-02 14:22:19 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-04-02 14:22:46 +0100
commit441d75fc22f00fe7e8b8dfd86ebb101486ed8136 (patch)
tree7278f339ffe0dab513a93290dec1f2aaeca23852
parent4454830ae0538b7478b270b8413ec2887dea8359 (diff)
downloadpaludis-441d75fc22f00fe7e8b8dfd86ebb101486ed8136.tar.gz
paludis-441d75fc22f00fe7e8b8dfd86ebb101486ed8136.tar.xz
Deserialise via a stream rather than a string.
-rw-r--r--paludis/ipc_output_manager.cc3
-rw-r--r--paludis/resolver/constraint.cc2
-rw-r--r--paludis/resolver/resolver_TEST_serialisation.cc3
-rw-r--r--paludis/resolver/sanitised_dependencies.cc4
-rw-r--r--paludis/serialise.cc129
-rw-r--r--paludis/serialise.hh10
-rw-r--r--src/clients/cave/cmd_display_resolution.cc3
-rw-r--r--src/clients/cave/cmd_execute_resolution.cc3
8 files changed, 86 insertions, 71 deletions
diff --git a/paludis/ipc_output_manager.cc b/paludis/ipc_output_manager.cc
index a598159..4880b37 100644
--- a/paludis/ipc_output_manager.cc
+++ b/paludis/ipc_output_manager.cc
@@ -243,7 +243,8 @@ IPCInputManager::_pipe_command_handler(const std::string & s)
if (tokens.size() != 3 || tokens[1] != "1")
return "Ebad CREATE subcommand";
- Deserialiser deserialiser(_imp->env, tokens[2]);
+ std::stringstream stream(tokens[2]);
+ Deserialiser deserialiser(_imp->env, stream);
Deserialisation deserialisation("CreateOutputManagerInfo", deserialiser);
const std::tr1::shared_ptr<CreateOutputManagerInfo> i(CreateOutputManagerInfo::deserialise(deserialisation));
diff --git a/paludis/resolver/constraint.cc b/paludis/resolver/constraint.cc
index b89435a..d838ffa 100644
--- a/paludis/resolver/constraint.cc
+++ b/paludis/resolver/constraint.cc
@@ -179,7 +179,7 @@ namespace
const std::tr1::shared_ptr<Constraint>
Constraint::deserialise(Deserialisation & d)
{
- Context context("When deserialising '" + d.raw_string() + "':");
+ Context context("When deserialising:");
Deserialisator v(d, "Constraint");
diff --git a/paludis/resolver/resolver_TEST_serialisation.cc b/paludis/resolver/resolver_TEST_serialisation.cc
index be037b9..422db69 100644
--- a/paludis/resolver/resolver_TEST_serialisation.cc
+++ b/paludis/resolver/resolver_TEST_serialisation.cc
@@ -82,8 +82,7 @@ namespace test_cases
orig_resolutions->serialise(ser);
str.nothing_more_to_write();
- std::string strstr((std::istreambuf_iterator<char>(str)), std::istreambuf_iterator<char>());
- Deserialiser deser(&env, strstr);
+ Deserialiser deser(&env, str);
Deserialisation desern("ResolverLists", deser);
resolutions = make_shared_ptr(new ResolverLists(ResolverLists::deserialise(desern)));
}
diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc
index 0d8a70f..80d01be 100644
--- a/paludis/resolver/sanitised_dependencies.cc
+++ b/paludis/resolver/sanitised_dependencies.cc
@@ -564,7 +564,7 @@ PackageOrBlockDepSpec::serialise(Serialiser & s) const
PackageOrBlockDepSpec
PackageOrBlockDepSpec::deserialise(Deserialisation & d, const std::tr1::shared_ptr<const PackageID> & for_id)
{
- Context context("When deserialising '" + d.raw_string() + "':");
+ Context context("When deserialising:");
Deserialisator v(d, "PackageOrBlockDepSpec");
@@ -625,7 +625,7 @@ SanitisedDependency::serialise(Serialiser & s) const
SanitisedDependency
SanitisedDependency::deserialise(Deserialisation & d, const std::tr1::shared_ptr<const PackageID> & from_id)
{
- Context context("When deserialising '" + d.raw_string() + "':");
+ Context context("When deserialising:");
Deserialisator v(d, "SanitisedDependency");
diff --git a/paludis/serialise.cc b/paludis/serialise.cc
index 9f0b940..08f7f05 100644
--- a/paludis/serialise.cc
+++ b/paludis/serialise.cc
@@ -20,7 +20,6 @@
#include <paludis/serialise-impl.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
-#include <paludis/util/simple_parser.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/join.hh>
@@ -125,11 +124,11 @@ namespace paludis
struct Implementation<Deserialiser>
{
const Environment * const env;
- SimpleParser parser;
+ std::istream & stream;
- Implementation(const Environment * const e, const std::string & s) :
+ Implementation(const Environment * const e, std::istream & s) :
env(e),
- parser(s)
+ stream(s)
{
}
};
@@ -142,7 +141,6 @@ namespace paludis
std::string class_name;
std::string string_value;
- std::string raw_string;
bool null;
std::list<std::tr1::shared_ptr<Deserialisation> > children;
@@ -173,7 +171,7 @@ namespace paludis
};
}
-Deserialiser::Deserialiser(const Environment * const e, const std::string & s) :
+Deserialiser::Deserialiser(const Environment * const e, std::istream & s) :
PrivateImplementationPattern<Deserialiser>(new Implementation<Deserialiser>(e, s))
{
}
@@ -182,10 +180,10 @@ Deserialiser::~Deserialiser()
{
}
-SimpleParser &
-Deserialiser::parser()
+std::istream &
+Deserialiser::stream()
{
- return _imp->parser;
+ return _imp->stream;
}
const Environment *
@@ -197,63 +195,90 @@ Deserialiser::environment() const
Deserialisation::Deserialisation(const std::string & i, Deserialiser & d) :
PrivateImplementationPattern<Deserialisation>(new Implementation<Deserialisation>(d, i))
{
- std::string::size_type before_p(d.parser().offset());
+ char c;
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
- if (d.parser().consume(simple_parser::exact("null;")))
- _imp->null = true;
- else if (d.parser().consume(simple_parser::exact("\"")))
+ if (c == '"')
{
while (true)
{
- std::string v;
- if (d.parser().consume(simple_parser::exact("\\")))
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+
+ if (c == '\\')
{
- if (! d.parser().consume(simple_parser::any_except("") >> v))
- throw InternalError(PALUDIS_HERE, "can't parse string escape");
- _imp->string_value.append(v);
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ _imp->string_value.append(1, c);
}
- else if (d.parser().consume(simple_parser::exact("\";")))
+ else if (c == '"')
break;
- else if (d.parser().consume((+simple_parser::any_except("\\\"")) >> v))
- _imp->string_value.append(v);
else
- throw InternalError(PALUDIS_HERE, "can't parse string");
+ _imp->string_value.append(1, c);
}
+
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ if (c != ';')
+ throw InternalError(PALUDIS_HERE, "can't parse string");
}
- else if (d.parser().consume(((+simple_parser::any_of(
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "_"
- )) >> _imp->class_name)
- & simple_parser::exact("(")))
+ else
{
+ _imp->class_name.append(1, c);
while (true)
{
- std::string k;
- if (d.parser().consume(simple_parser::exact(");")))
- break;
- else if (d.parser().consume(((+simple_parser::any_of(
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789"
- "-_"
- )) >> k)
- & simple_parser::exact("=")))
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+
+ if (c == ';')
{
- std::tr1::shared_ptr<Deserialisation> c(new Deserialisation(k, d));
- _imp->children.push_back(c);
+ if (_imp->class_name != "null")
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ _imp->null = true;
+ _imp->class_name.clear();
+ break;
}
+ else if (c == '(')
+ break;
else
- throw InternalError(PALUDIS_HERE, "can't parse keys, remaining text is '"
- + d.parser().text().substr(d.parser().offset()));
+ _imp->class_name.append(1, c);
}
- }
- else
- throw InternalError(PALUDIS_HERE, "can't parse keys, remaining text is '"
- + d.parser().text().substr(d.parser().offset()));
- std::string::size_type after_p(d.parser().offset());
- _imp->raw_string = d.parser().text().substr(before_p, after_p - before_p);
+ if (! _imp->null)
+ {
+ while (true)
+ {
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+
+ if (c == ')')
+ {
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ if (c != ';')
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ break;
+ }
+ else
+ {
+ std::string k;
+ k.append(1, c);
+ while (true)
+ {
+ if (! d.stream().get(c))
+ throw InternalError(PALUDIS_HERE, "can't parse string");
+ if (c == '=')
+ break;
+ k.append(1, c);
+ }
+
+ std::tr1::shared_ptr<Deserialisation> de(new Deserialisation(k, d));
+ _imp->children.push_back(de);
+ }
+ }
+ }
+ }
}
Deserialisation::~Deserialisation()
@@ -272,12 +297,6 @@ Deserialisation::class_name() const
return _imp->class_name;
}
-const std::string
-Deserialisation::raw_string() const
-{
- return _imp->raw_string;
-}
-
bool
Deserialisation::null() const
{
@@ -344,7 +363,7 @@ Deserialisator::find_remove_member(const std::string & s)
std::tr1::shared_ptr<const PackageID>
DeserialisatorHandler<std::tr1::shared_ptr<const PackageID> >::handle(Deserialisation & v)
{
- Context context("When deserialising '" + v.raw_string() + "':");
+ Context context("When deserialising:");
if (v.null())
return make_null_shared_ptr();
diff --git a/paludis/serialise.hh b/paludis/serialise.hh
index 087b817..c0f2a92 100644
--- a/paludis/serialise.hh
+++ b/paludis/serialise.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009 Ciaran McCreesh
+ * Copyright (c) 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -22,7 +22,6 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/private_implementation_pattern.hh>
-#include <paludis/util/simple_parser-fwd.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <paludis/serialise-fwd.hh>
#include <paludis/environment-fwd.hh>
@@ -89,11 +88,12 @@ namespace paludis
private PrivateImplementationPattern<Deserialiser>
{
public:
- Deserialiser(const Environment * const, const std::string &);
+ Deserialiser(const Environment * const, std::istream &);
~Deserialiser();
const Environment * environment() const PALUDIS_ATTRIBUTE((warn_unused_result));
- SimpleParser & parser() PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::istream & stream() PALUDIS_ATTRIBUTE((warn_unused_result));
};
class PALUDIS_VISIBLE Deserialisation :
@@ -111,8 +111,6 @@ namespace paludis
const std::string class_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
- const std::string raw_string() const PALUDIS_ATTRIBUTE((warn_unused_result));
-
const std::string string_value() const PALUDIS_ATTRIBUTE((warn_unused_result));
bool null() const PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/src/clients/cave/cmd_display_resolution.cc b/src/clients/cave/cmd_display_resolution.cc
index 57e8e40..cd8cfab 100644
--- a/src/clients/cave/cmd_display_resolution.cc
+++ b/src/clients/cave/cmd_display_resolution.cc
@@ -1071,8 +1071,7 @@ DisplayResolutionCommand::run(
int fd(destringify<int>(getenv_with_default("PALUDIS_SERIALISED_RESOLUTION_FD", "")));
SafeIFStream deser_stream(fd);
- const std::string deser_str((std::istreambuf_iterator<char>(deser_stream)), std::istreambuf_iterator<char>());
- Deserialiser deserialiser(env.get(), deser_str);
+ Deserialiser deserialiser(env.get(), deser_stream);
Deserialisation deserialisation("ResolverLists", deserialiser);
lists = make_shared_copy(ResolverLists::deserialise(deserialisation));
}
diff --git a/src/clients/cave/cmd_execute_resolution.cc b/src/clients/cave/cmd_execute_resolution.cc
index 3a00340..8eb8599 100644
--- a/src/clients/cave/cmd_execute_resolution.cc
+++ b/src/clients/cave/cmd_execute_resolution.cc
@@ -1355,8 +1355,7 @@ ExecuteResolutionCommand::run(
int fd(destringify<int>(getenv_with_default("PALUDIS_SERIALISED_RESOLUTION_FD", "")));
SafeIFStream deser_stream(fd);
- const std::string deser_str((std::istreambuf_iterator<char>(deser_stream)), std::istreambuf_iterator<char>());
- Deserialiser deserialiser(env.get(), deser_str);
+ Deserialiser deserialiser(env.get(), deser_stream);
Deserialisation deserialisation("ResolverLists", deserialiser);
lists = make_shared_copy(ResolverLists::deserialise(deserialisation));
}