Skip to content

Commit

Permalink
moved specializations to respective headers, rename Hash and EqualTo …
Browse files Browse the repository at this point in the history
…to be more specific
  • Loading branch information
drexlerd committed Aug 14, 2024
1 parent bc3f392 commit 30662e3
Show file tree
Hide file tree
Showing 53 changed files with 1,274 additions and 1,275 deletions.
14 changes: 14 additions & 0 deletions include/loki/details/pddl/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_ACTION_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"

#include <optional>
#include <string>
Expand Down Expand Up @@ -62,6 +64,18 @@ class ActionImpl
const std::optional<Effect>& get_effect() const;
};

template<>
struct UniquePDDLHasher<const ActionImpl*>
{
size_t operator()(const ActionImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const ActionImpl*>
{
bool operator()(const ActionImpl* l, const ActionImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const ActionImpl& element);

}
Expand Down
14 changes: 14 additions & 0 deletions include/loki/details/pddl/atom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_ATOM_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"

#include <string>

Expand Down Expand Up @@ -49,6 +51,18 @@ class AtomImpl
const TermList& get_terms() const;
};

template<>
struct UniquePDDLHasher<const AtomImpl*>
{
size_t operator()(const AtomImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const AtomImpl*>
{
bool operator()(const AtomImpl* l, const AtomImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const AtomImpl& element);

}
Expand Down
14 changes: 14 additions & 0 deletions include/loki/details/pddl/axiom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_DERIVED_PREDICATE_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"

#include <string>

Expand Down Expand Up @@ -53,6 +55,18 @@ class AxiomImpl
size_t get_num_parameters_to_ground_head() const;
};

template<>
struct UniquePDDLHasher<const AxiomImpl*>
{
size_t operator()(const AxiomImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const AxiomImpl*>
{
bool operator()(const AxiomImpl* l, const AxiomImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const AxiomImpl& element);

}
Expand Down
98 changes: 98 additions & 0 deletions include/loki/details/pddl/conditions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_CONDITIONS_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"

#include <string>

Expand Down Expand Up @@ -199,6 +201,102 @@ class ConditionForallImpl
const Condition& get_condition() const;
};

template<>
struct UniquePDDLHasher<const ConditionLiteralImpl&>
{
size_t operator()(const ConditionLiteralImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionAndImpl&>
{
size_t operator()(const ConditionAndImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionOrImpl&>
{
size_t operator()(const ConditionOrImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionNotImpl&>
{
size_t operator()(const ConditionNotImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionImplyImpl&>
{
size_t operator()(const ConditionImplyImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionExistsImpl&>
{
size_t operator()(const ConditionExistsImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionForallImpl&>
{
size_t operator()(const ConditionForallImpl& e) const;
};

template<>
struct UniquePDDLHasher<const ConditionImpl*>
{
size_t operator()(const ConditionImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionLiteralImpl&>
{
bool operator()(const ConditionLiteralImpl& l, const ConditionLiteralImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionAndImpl&>
{
bool operator()(const ConditionAndImpl& l, const ConditionAndImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionOrImpl&>
{
bool operator()(const ConditionOrImpl& l, const ConditionOrImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionNotImpl&>
{
bool operator()(const ConditionNotImpl& l, const ConditionNotImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionImplyImpl&>
{
bool operator()(const ConditionImplyImpl& l, const ConditionImplyImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionExistsImpl&>
{
bool operator()(const ConditionExistsImpl& l, const ConditionExistsImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionForallImpl&>
{
bool operator()(const ConditionForallImpl& l, const ConditionForallImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const ConditionImpl*>
{
bool operator()(const ConditionImpl* l, const ConditionImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const ConditionLiteralImpl& element);
extern std::ostream& operator<<(std::ostream& out, const ConditionAndImpl& element);
extern std::ostream& operator<<(std::ostream& out, const ConditionOrImpl& element);
Expand Down
14 changes: 14 additions & 0 deletions include/loki/details/pddl/domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_DOMAIN_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"
#include "loki/details/utils/filesystem.hpp"

#include <optional>
Expand Down Expand Up @@ -75,6 +77,18 @@ class DomainImpl
const AxiomList& get_axioms() const;
};

template<>
struct UniquePDDLHasher<const DomainImpl*>
{
size_t operator()(const DomainImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const DomainImpl*>
{
bool operator()(const DomainImpl* l, const DomainImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const DomainImpl& element);

}
Expand Down
74 changes: 74 additions & 0 deletions include/loki/details/pddl/effects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define LOKI_INCLUDE_LOKI_PDDL_EFFECTS_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/pddl/equal_to.hpp"
#include "loki/details/pddl/hash.hpp"

#include <string>

Expand Down Expand Up @@ -164,6 +166,78 @@ class EffectConditionalWhenImpl
const Effect& get_effect() const;
};

template<>
struct UniquePDDLHasher<const EffectLiteralImpl&>
{
size_t operator()(const EffectLiteralImpl& e) const;
};

template<>
struct UniquePDDLHasher<const EffectAndImpl&>
{
size_t operator()(const EffectAndImpl& e) const;
};

template<>
struct UniquePDDLHasher<const EffectNumericImpl&>
{
size_t operator()(const EffectNumericImpl& e) const;
};

template<>
struct UniquePDDLHasher<const EffectConditionalForallImpl&>
{
size_t operator()(const EffectConditionalForallImpl& e) const;
};

template<>
struct UniquePDDLHasher<const EffectConditionalWhenImpl&>
{
size_t operator()(const EffectConditionalWhenImpl& e) const;
};

template<>
struct UniquePDDLHasher<const EffectImpl*>
{
size_t operator()(const EffectImpl* e) const;
};

template<>
struct UniquePDDLEqualTo<const EffectLiteralImpl&>
{
bool operator()(const EffectLiteralImpl& l, const EffectLiteralImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const EffectAndImpl&>
{
bool operator()(const EffectAndImpl& l, const EffectAndImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const EffectNumericImpl&>
{
bool operator()(const EffectNumericImpl& l, const EffectNumericImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const EffectConditionalForallImpl&>
{
bool operator()(const EffectConditionalForallImpl& l, const EffectConditionalForallImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const EffectConditionalWhenImpl&>
{
bool operator()(const EffectConditionalWhenImpl& l, const EffectConditionalWhenImpl& r) const;
};

template<>
struct UniquePDDLEqualTo<const EffectImpl*>
{
bool operator()(const EffectImpl* l, const EffectImpl* r) const;
};

extern std::ostream& operator<<(std::ostream& out, const EffectLiteralImpl& element);
extern std::ostream& operator<<(std::ostream& out, const EffectAndImpl& element);
extern std::ostream& operator<<(std::ostream& out, const EffectNumericImpl& element);
Expand Down
70 changes: 70 additions & 0 deletions include/loki/details/pddl/equal_to.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2023 Dominik Drexler and Simon Stahlberg
*
* 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 3 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; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*<
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef LOKI_INCLUDE_LOKI_PDDL_EQUAL_TO_HPP_
#define LOKI_INCLUDE_LOKI_PDDL_EQUAL_TO_HPP_

#include "loki/details/pddl/declarations.hpp"
#include "loki/details/utils/concepts.hpp"

#include <functional>
#include <variant>

namespace loki
{

/// @brief `UniquePDDLEqualTo` is a comparator that should be implemented to work in the context where
/// all objects of a custom type `T` are uniquely created and uncopieable.
/// This ensures that pointers can simply be compared and do not need to be dereferenced.
/// @tparam T the type of the object to compare.
template<typename T>
struct UniquePDDLEqualTo
{
bool operator()(const T& l, const T& r) const { return std::equal_to<T>()(l, r); }
};

/// Spezialization for std::variant.
template<typename... Ts>
struct UniquePDDLEqualTo<std::variant<Ts...>>
{
bool operator()(const std::variant<Ts...>& l, const std::variant<Ts...>& r) const
{
if (l.index() != r.index())
{
return false; // Different types held
}
// Compare the held values, but only if they are of the same type
return std::visit(
[](const auto& lhs, const auto& rhs) -> bool
{
if constexpr (std::is_same_v<decltype(lhs), decltype(rhs)>)
{
return UniquePDDLEqualTo<decltype(lhs)>()(lhs, rhs);
}
else
{
return false; // Different types can't be equal
}
},
l,
r);
}
};

}

#endif
Loading

0 comments on commit 30662e3

Please sign in to comment.