Skip to content

Commit

Permalink
removed intrusive str of pddl objects and replaced it by Formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Aug 13, 2024
1 parent 968df01 commit c36c767
Show file tree
Hide file tree
Showing 57 changed files with 456 additions and 1,285 deletions.
6 changes: 3 additions & 3 deletions examples/multiple_problems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ int main()
// Parse the domain
auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

// Parse first problem
const auto problem_parser = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-0.pddl", domain_parser);
const auto problem1 = problem_parser.get_problem();
std::cout << *problem1 << std::endl;
std::cout << loki::StreamWriter(*problem1) << std::endl;

// Parse second problem where the constants are reordered
const auto problem_parser2 = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-1.pddl", domain_parser);
const auto problem2 = problem_parser2.get_problem();
std::cout << *problem2 << std::endl;
std::cout << loki::StreamWriter(*problem2) << std::endl;

/* Both problems are structurally equivalent */
assert(problem1 == problem2);
Expand Down
2 changes: 1 addition & 1 deletion examples/position_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main()
// Parse the domain
auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
std::cout << *domain << std::endl << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl << std::endl;

const loki::PDDLPositionCache& position_cache = domain_parser.get_position_cache();
const loki::PDDLErrorHandler& error_handler = position_cache.get_error_handler();
Expand Down
4 changes: 2 additions & 2 deletions examples/single_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ int main()
// Parse the domain
auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl");
const auto domain = domain_parser.get_domain();
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

// Parse the problem
const auto problem_parser = loki::ProblemParser(std::string(DATA_DIR) + "gripper/p-2-0.pddl", domain_parser);
const auto problem = problem_parser.get_problem();
std::cout << *problem << std::endl;
std::cout << loki::StreamWriter(*problem) << std::endl;

return 0;
}
4 changes: 2 additions & 2 deletions examples/undefined_behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ int main()
// Parse the domain
auto domain_parser = loki::DomainParser(std::string(DATA_DIR) + "gripper/domain.pddl");
domain = domain_parser.get_domain();
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

/* Destructor of DomainParser is called and all domain and problem specific PDDL objects are destroyed. */
}

std::cout << "Bye ;(" << std::endl;

/* Undefined behavior when accessing the domain, usually the program crashes because memory was overwritten */
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

return 0;
}
2 changes: 1 addition & 1 deletion exe/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char** argv)
// 1. Parse the domain
const auto domain_parser = loki::DomainParser(domain_file);
const auto domain = domain_parser.get_domain();
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

return 0;
}
4 changes: 2 additions & 2 deletions exe/problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ int main(int argc, char** argv)
// 1. Parse the domain
auto domain_parser = loki::DomainParser(domain_file);
const auto domain = domain_parser.get_domain();
std::cout << *domain << std::endl;
std::cout << loki::StreamWriter(*domain) << std::endl;

// 2. Parse the problem
const auto problem_parser = loki::ProblemParser(problem_file, domain_parser);
const auto problem = problem_parser.get_problem();
std::cout << *problem << std::endl;
std::cout << loki::StreamWriter(*problem) << std::endl;

return 0;
}
368 changes: 184 additions & 184 deletions include/loki/details/ast/printer.hpp

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions include/loki/details/pddl/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class ActionImpl : public Base<ActionImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ActionImpl>;

public:
const std::string& get_name() const;
size_t get_original_arity() const;
Expand Down
5 changes: 0 additions & 5 deletions include/loki/details/pddl/atom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class AtomImpl : public Base<AtomImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<AtomImpl>;

public:
const Predicate& get_predicate() const;
const TermList& get_terms() const;
Expand Down
5 changes: 0 additions & 5 deletions include/loki/details/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ class AxiomImpl : public Base<AxiomImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<AxiomImpl>;

public:
const std::string& get_derived_predicate_name() const;
const ParameterList& get_parameters() const;
Expand Down
23 changes: 0 additions & 23 deletions include/loki/details/pddl/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#ifndef LOKI_INCLUDE_LOKI_PDDL_BASE_HPP_
#define LOKI_INCLUDE_LOKI_PDDL_BASE_HPP_

#include "loki/details/utils/printer.hpp"

#include <algorithm>
#include <cstddef>
#include <sstream>
Expand All @@ -33,8 +31,6 @@ template<typename Derived>
class Base
{
private:
constexpr const auto& self() const { return static_cast<Derived const&>(*this); }

size_t m_index;

explicit Base(size_t index) : m_index(index) {}
Expand All @@ -47,25 +43,6 @@ class Base
Base(Base&& other) = default;
Base& operator=(Base&& other) = default;

/// @brief Overload of the output stream insertion operator (operator<<).
friend std::ostream& operator<<(std::ostream& os, const Base& element)
{
os << element.str();
return os;
}

/// @brief Compute a string representation of this object.
void str(std::ostream& out, const FormattingOptions& options) const { self().str_impl(out, options); }

/// @brief Compute a string representation of this object.
std::string str() const
{
std::ostringstream out;
FormattingOptions options { 0, 4 };
str(out, options);
return out.str();
}

/// @brief Get the index.
size_t get_index() const { return m_index; }
};
Expand Down
37 changes: 0 additions & 37 deletions include/loki/details/pddl/conditions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class ConditionLiteralImpl : public Base<ConditionLiteralImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionLiteralImpl>;

public:
const Literal& get_literal() const;
};
Expand All @@ -59,11 +54,6 @@ class ConditionAndImpl : public Base<ConditionAndImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionAndImpl>;

public:
const ConditionList& get_conditions() const;
};
Expand All @@ -80,13 +70,6 @@ class ConditionOrImpl : public Base<ConditionOrImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

bool is_structurally_equivalent_to_impl(const ConditionOrImpl& other) const;
size_t hash_impl() const;
void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionOrImpl>;

public:
const ConditionList& get_conditions() const;
};
Expand All @@ -103,11 +86,6 @@ class ConditionNotImpl : public Base<ConditionNotImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionNotImpl>;

public:
const Condition& get_condition() const;
};
Expand All @@ -125,11 +103,6 @@ class ConditionImplyImpl : public Base<ConditionImplyImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionImplyImpl>;

public:
const Condition& get_condition_left() const;
const Condition& get_condition_right() const;
Expand All @@ -148,11 +121,6 @@ class ConditionExistsImpl : public Base<ConditionExistsImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionExistsImpl>;

public:
const ParameterList& get_parameters() const;
const Condition& get_condition() const;
Expand All @@ -171,11 +139,6 @@ class ConditionForallImpl : public Base<ConditionForallImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<ConditionForallImpl>;

public:
const ParameterList& get_parameters() const;
const Condition& get_condition() const;
Expand Down
5 changes: 0 additions & 5 deletions include/loki/details/pddl/domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ class DomainImpl : public Base<DomainImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<DomainImpl>;

public:
const std::optional<fs::path>& get_filepath() const;
const std::string& get_name() const;
Expand Down
25 changes: 0 additions & 25 deletions include/loki/details/pddl/effects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class EffectLiteralImpl : public Base<EffectLiteralImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<EffectLiteralImpl>;

public:
const Literal& get_literal() const;
};
Expand All @@ -70,11 +65,6 @@ class EffectAndImpl : public Base<EffectAndImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<EffectAndImpl>;

public:
const EffectList& get_effects() const;
};
Expand All @@ -93,11 +83,6 @@ class EffectNumericImpl : public Base<EffectNumericImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<EffectNumericImpl>;

public:
AssignOperatorEnum get_assign_operator() const;
const Function& get_function() const;
Expand All @@ -117,11 +102,6 @@ class EffectConditionalForallImpl : public Base<EffectConditionalForallImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<EffectConditionalForallImpl>;

public:
const ParameterList& get_parameters() const;
const Effect& get_effect() const;
Expand All @@ -140,11 +120,6 @@ class EffectConditionalWhenImpl : public Base<EffectConditionalWhenImpl>
template<typename HolderType, typename Hash, typename EqualTo>
friend class UniqueFactory;

void str_impl(std::ostream& out, const FormattingOptions& options) const;

// Give access to the private interface implementations.
friend class Base<EffectConditionalWhenImpl>;

public:
const Condition& get_condition() const;
const Effect& get_effect() const;
Expand Down
Loading

0 comments on commit c36c767

Please sign in to comment.