diff --git a/include/plasp/pddl/Description.h b/include/plasp/pddl/Description.h index 989df12..07151b6 100644 --- a/include/plasp/pddl/Description.h +++ b/include/plasp/pddl/Description.h @@ -21,6 +21,7 @@ namespace pddl class Description { public: + static Description fromParser(utils::Parser &&parser); static Description fromStream(std::istream &istream); static Description fromFile(const std::string &path); static Description fromFiles(const std::vector &paths); diff --git a/include/plasp/sas/Description.h b/include/plasp/sas/Description.h index 9f16c0a..ca97d74 100644 --- a/include/plasp/sas/Description.h +++ b/include/plasp/sas/Description.h @@ -29,6 +29,7 @@ namespace sas class Description { public: + static Description fromParser(utils::Parser &&parser); static Description fromStream(std::istream &istream); static Description fromFile(const boost::filesystem::path &path); diff --git a/include/plasp/utils/Parser.h b/include/plasp/utils/Parser.h index beb3ca0..2f82ff3 100644 --- a/include/plasp/utils/Parser.h +++ b/include/plasp/utils/Parser.h @@ -41,6 +41,13 @@ class Parser explicit Parser(); explicit Parser(std::string streamName, std::istream &istream); + // Forbid copy construction/assignment + Parser(const Parser &other) = delete; + Parser &operator=(const Parser &other) = delete; + + Parser(Parser &&other); + Parser &operator=(Parser &&other); + void readStream(std::string streamName, std::istream &istream); void readFile(const boost::filesystem::path &path); diff --git a/src/plasp/pddl/Description.cpp b/src/plasp/pddl/Description.cpp index deb2984..5d08814 100644 --- a/src/plasp/pddl/Description.cpp +++ b/src/plasp/pddl/Description.cpp @@ -31,6 +31,20 @@ Description::Description() //////////////////////////////////////////////////////////////////////////////////////////////////// +Description Description::fromParser(utils::Parser &&parser) +{ + Description description; + + description.m_parser = std::move(parser); + + description.parseContent(); + description.checkConsistency(); + + return description; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + Description Description::fromStream(std::istream &istream) { Description description; diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index 75de27a..1d5c3fa 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -28,6 +28,16 @@ Description::Description() //////////////////////////////////////////////////////////////////////////////////////////////////// +Description Description::fromParser(utils::Parser &&parser) +{ + Description description; + description.parseContent(parser); + + return description; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + Description Description::fromStream(std::istream &istream) { utils::Parser parser; diff --git a/src/plasp/utils/Parser.cpp b/src/plasp/utils/Parser.cpp index cbf7906..db05e76 100644 --- a/src/plasp/utils/Parser.cpp +++ b/src/plasp/utils/Parser.cpp @@ -41,6 +41,29 @@ Parser::Parser(std::string streamName, std::istream &istream) //////////////////////////////////////////////////////////////////////////////////////////////////// +Parser::Parser(Parser &&other) +: m_stream{std::move(other.m_stream)}, + m_streamDelimiters{std::move(other.m_streamDelimiters)}, + m_isCaseSensitive{other.m_isCaseSensitive} +{ + other.m_isCaseSensitive = true; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +Parser &Parser::operator=(Parser &&other) +{ + m_stream = std::move(other.m_stream); + m_streamDelimiters = std::move(other.m_streamDelimiters); + m_isCaseSensitive = other.m_isCaseSensitive; + + other.m_isCaseSensitive = true; + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + void Parser::readStream(std::string streamName, std::istream &istream) { // Store position of new section