Skip to content

Commit

Permalink
Update core.hpp and item.hpp to fix namespace issues and improve code…
Browse files Browse the repository at this point in the history
… readability
  • Loading branch information
riccardodebenedictis committed Apr 14, 2024
1 parent e5e8331 commit c89fc15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
18 changes: 9 additions & 9 deletions include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ namespace riddle
*
* @param disjuncts The disjuncts.
*/
virtual void new_disjunction(std::vector<std::unique_ptr<riddle::conjunction>> &&disjuncts) = 0;
virtual void new_disjunction(std::vector<std::unique_ptr<conjunction>> &&disjuncts) = 0;

/**
* @brief Create a new fact or goal atom with the given predicate and arguments.
Expand Down Expand Up @@ -396,55 +396,55 @@ namespace riddle
* @return true If the expression is a boolean.
* @return false If the expression is not a boolean.
*/
[[nodiscard]] inline bool is_bool(const riddle::item &x) noexcept { return &x.get_type().get_scope().get_core().get_bool_type() == &x.get_type(); }
[[nodiscard]] inline bool is_bool(const item &x) noexcept { return &x.get_type().get_scope().get_core().get_bool_type() == &x.get_type(); }
/**
* @brief Determine if the expression is an integer.
*
* @param x The expression.
* @return true If the expression is an integer.
* @return false If the expression is not an integer.
*/
[[nodiscard]] inline bool is_int(const riddle::item &x) noexcept { return &x.get_type().get_scope().get_core().get_int_type() == &x.get_type(); }
[[nodiscard]] inline bool is_int(const item &x) noexcept { return &x.get_type().get_scope().get_core().get_int_type() == &x.get_type(); }
/**
* @brief Determine if the expression is a real.
*
* @param x The expression.
* @return true If the expression is a real.
* @return false If the expression is not a real.
*/
[[nodiscard]] inline bool is_real(const riddle::item &x) noexcept { return &x.get_type().get_scope().get_core().get_real_type() == &x.get_type(); }
[[nodiscard]] inline bool is_real(const item &x) noexcept { return &x.get_type().get_scope().get_core().get_real_type() == &x.get_type(); }
/**
* @brief Determine if the expression is a time.
*
* @param x The expression.
* @return true If the expression is a time.
* @return false If the expression is not a time.
*/
[[nodiscard]] inline bool is_time(const riddle::item &x) noexcept { return &x.get_type().get_scope().get_core().get_time_type() == &x.get_type(); }
[[nodiscard]] inline bool is_time(const item &x) noexcept { return &x.get_type().get_scope().get_core().get_time_type() == &x.get_type(); }
/**
* @brief Determine if the expression is an arithmetic value.
*
* @param x The expression.
* @return true If the expression is an arithmetic value.
* @return false If the expression is not an arithmetic value.
*/
[[nodiscard]] inline bool is_arith(const riddle::item &x) noexcept { return is_int(x) || is_real(x) || is_time(x); }
[[nodiscard]] inline bool is_arith(const item &x) noexcept { return is_int(x) || is_real(x) || is_time(x); }
/**
* @brief Determine if the expression is a string.
*
* @param x The expression.
* @return true If the expression is a string.
* @return false If the expression is not a string.
*/
[[nodiscard]] inline bool is_string(const riddle::item &x) noexcept { return &x.get_type().get_scope().get_core().get_string_type() == &x.get_type(); }
[[nodiscard]] inline bool is_string(const item &x) noexcept { return &x.get_type().get_scope().get_core().get_string_type() == &x.get_type(); }
/**
* @brief Determine if the expression is an enumeration.
*
* @param x The expression.
* @return true If the expression is an enumeration.
* @return false If the expression is not an enumeration.
*/
[[nodiscard]] inline bool is_enum(const riddle::item &x) noexcept { return dynamic_cast<const enum_item *>(&x) != nullptr; }
[[nodiscard]] inline bool is_enum(const item &x) noexcept { return dynamic_cast<const enum_item *>(&x) != nullptr; }
/**
* @brief Determine if the expression is a constant.
*
Expand All @@ -457,7 +457,7 @@ namespace riddle
* @return true If the expression is a constant.
* @return false If the expression is not a constant.
*/
[[nodiscard]] inline bool is_constant(const riddle::item &x) noexcept
[[nodiscard]] inline bool is_constant(const item &x) noexcept
{
if (is_bool(x)) // the expression is a boolean..
return x.get_type().get_scope().get_core().bool_value(static_cast<const bool_item &>(x)) != utils::Undefined;
Expand Down
31 changes: 31 additions & 0 deletions include/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,43 @@ namespace riddle
atom(predicate &t, bool is_fact, const utils::lit &sigma, std::map<std::string, std::shared_ptr<item>> &&args = {});
virtual ~atom() = default;

/**
* @brief Checks if the item is a fact.
*
* @return true if the item is a fact, false otherwise.
*/
[[nodiscard]] bool is_fact() const { return fact; }
/**
* @brief Get the status of the atom as a literal.
*
* @return const utils::lit& the status of the atom.
* @note the literal assumes the following values:
* - `True` if the atom is `Active`.
* - `False` if the atom is `Unified`.
* - `Undefined` if the atom is `Inactive`.
*/
[[nodiscard]] utils::lit &get_sigma() { return sigma; }
/**
* @brief Get the status of the atom as a literal.
*
* @return const utils::lit& the status of the atom.
* @note the literal assumes the following values:
* - `True` if the atom is `Active`.
* - `False` if the atom is `Unified`.
* - `Undefined` if the atom is `Inactive`.
*/
[[nodiscard]] const utils::lit &get_sigma() const { return sigma; }

private:
bool fact; // whether the atom is a fact or a goal..
utils::lit sigma; // the literal indicating the status of the atom (i.e., true if active, false if unified, undefined if inactive)..
};

/**
* @brief Gets the unique identifier of the given item.
*
* @param f the item to get the unique identifier of.
* @return uintptr_t the unique identifier of the given item.
*/
inline uintptr_t get_id(const item &itm) noexcept { return reinterpret_cast<uintptr_t>(&itm); }
} // namespace riddle

0 comments on commit c89fc15

Please sign in to comment.