diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-27 16:31:00 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-27 16:31:00 -0700 |
commit | d7533e931cfb49a68dc8e6e3f524d49e364cef83 (patch) | |
tree | 06d31523b9647d3de8ce8888f6e83d24f046aa82 /src/include/tome | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
New upstream version 2.41-ah~0.git.20200131
Diffstat (limited to 'src/include/tome')
-rw-r--r-- | src/include/tome/enum_string_map.hpp | 8 | ||||
-rw-r--r-- | src/include/tome/squelch/condition.hpp | 56 | ||||
-rw-r--r-- | src/include/tome/squelch/object_status.hpp | 4 | ||||
-rw-r--r-- | src/include/tome/squelch/rule.hpp | 7 | ||||
-rw-r--r-- | src/include/tome/unique_handle.hpp | 88 |
5 files changed, 116 insertions, 47 deletions
diff --git a/src/include/tome/enum_string_map.hpp b/src/include/tome/enum_string_map.hpp index 814827fe..bd554b5c 100644 --- a/src/include/tome/enum_string_map.hpp +++ b/src/include/tome/enum_string_map.hpp @@ -35,6 +35,10 @@ public: return i->second.c_str(); } + E parse(std::string const &s) const { + return parse(s.c_str()); + } + E parse(const char *s) const { E e; bool result = parse(s, &e); @@ -42,6 +46,10 @@ public: return e; } + bool parse(std::string const &s, E *e) const { + return parse(s.c_str(), e); + } + bool parse(const char *s, E *e) const { auto i = bimap.right.find(s); if (i == bimap.right.end()) diff --git a/src/include/tome/squelch/condition.hpp b/src/include/tome/squelch/condition.hpp index 584ecb0e..cc5deb64 100644 --- a/src/include/tome/squelch/condition.hpp +++ b/src/include/tome/squelch/condition.hpp @@ -20,10 +20,10 @@ namespace squelch { * Types of matches used for conditions. */ enum class match_type { - AND , OR , NOT , NAME , CONTAIN , - INSCRIBED, DISCOUNT, SYMBOL , STATE , STATUS , - TVAL , SVAL , RACE , SUBRACE , CLASS , - LEVEL , SKILL , ABILITY, INVENTORY, EQUIPMENT }; + AND , OR , NOT , NAME , CONTAIN, + INSCRIBED, DISCOUNT, SYMBOL , STATUS , TVAL , + SVAL , RACE , SUBRACE , CLASS , LEVEL , + SKILL , ABILITY , INVENTORY, EQUIPMENT }; /** * Bidirectional map between enumeration values and strings. @@ -31,18 +31,6 @@ enum class match_type { EnumStringMap<match_type> &match_mapping(); /** - * Identification states an object can have: identified or not - * identified. - */ -enum class identification_state { - IDENTIFIED, NOT_IDENTIFIED }; - -/** - * Biredectional map between identification_state values and strings. - */ -EnumStringMap<identification_state> &identification_state_mapping(); - -/** * Condition represents a tree of checks which * can be applied to objects, the player, etc. */ @@ -133,7 +121,7 @@ private: class NameCondition : public Condition { public: - NameCondition(std::string name) : + NameCondition(std::string const &name) : Condition(match_type::NAME), m_name(name) { } @@ -157,7 +145,7 @@ private: class ContainCondition : public Condition { public: - ContainCondition(std::string contain) : + ContainCondition(std::string const &contain) : Condition(match_type::CONTAIN), m_contain(contain) { } @@ -302,7 +290,7 @@ private: class RaceCondition : public Condition { public: - RaceCondition(std::string race) + RaceCondition(std::string const &race) : Condition(match_type::RACE) , m_race(race) { } @@ -326,7 +314,7 @@ private: class SubraceCondition : public Condition { public: - SubraceCondition(std::string subrace) + SubraceCondition(std::string const &subrace) : Condition(match_type::SUBRACE) , m_subrace(subrace) { } @@ -350,7 +338,7 @@ private: class ClassCondition : public Condition { public: - ClassCondition(std::string klass) + ClassCondition(std::string const &klass) : Condition(match_type::CLASS) , m_class(klass) { } @@ -374,7 +362,7 @@ private: class InscriptionCondition : public Condition { public: - InscriptionCondition(std::string inscription) + InscriptionCondition(std::string const &inscription) : Condition(match_type::INSCRIBED) , m_inscription(inscription) { } @@ -473,30 +461,6 @@ private: }; /** - * Check identification state - */ -class StateCondition : public Condition -{ -public: - StateCondition(identification_state state) - : Condition(match_type::STATE) - , m_state(state) { - } - - bool is_match(object_type *) const override; - - static std::shared_ptr<Condition> from_json(jsoncons::json const &); - -protected: - void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - - void to_json(jsoncons::json &) const override; - -private: - identification_state m_state; -}; - -/** * Check object symbol */ class SymbolCondition : public Condition diff --git a/src/include/tome/squelch/object_status.hpp b/src/include/tome/squelch/object_status.hpp index c52a35ea..2d90ac1a 100644 --- a/src/include/tome/squelch/object_status.hpp +++ b/src/include/tome/squelch/object_status.hpp @@ -1,6 +1,7 @@ #ifndef H_e3f9ebbe_ff9a_4687_a847_6101f094b483 #define H_e3f9ebbe_ff9a_4687_a847_6101f094b483 +#include "object_type_fwd.hpp" #include "tome/enum_string_map.hpp" namespace squelch { @@ -11,7 +12,8 @@ namespace squelch { */ enum class status_type { BAD , VERY_BAD, AVERAGE, GOOD, VERY_GOOD, - SPECIAL, TERRIBLE, NONE, CHEST_EMPTY, CHEST_DISARMED }; + SPECIAL, TERRIBLE, NONE +}; /** * Bidirectional map between status_type values and strings. diff --git a/src/include/tome/squelch/rule.hpp b/src/include/tome/squelch/rule.hpp index af86dfc8..1270266d 100644 --- a/src/include/tome/squelch/rule.hpp +++ b/src/include/tome/squelch/rule.hpp @@ -84,6 +84,13 @@ public: */ static std::shared_ptr<Rule> parse_rule(jsoncons::json const &); + /** + * Destructor. + */ + virtual ~Rule() + { + }; + protected: virtual bool do_apply_rule(object_type *, int) const = 0; virtual void do_write_tree(TreePrinter *p) const = 0; diff --git a/src/include/tome/unique_handle.hpp b/src/include/tome/unique_handle.hpp new file mode 100644 index 00000000..32cb73e2 --- /dev/null +++ b/src/include/tome/unique_handle.hpp @@ -0,0 +1,88 @@ +#pragma once + +/** + * Taken from + * + * https://github.com/milleniumbug/wiertlo/blob/master/include/wiertlo/unique_handle.hpp + * + */ + +#include <utility> + +template<typename Policy> +class unique_handle +{ + typename Policy::handle_type h; + +public: + unique_handle(const unique_handle&) = delete; + + typename Policy::handle_type get() const + { + return h; + } + + typename Policy::handle_type release() + { + typename Policy::handle_type temp = h; + h = Policy::get_null(); + return temp; + } + + explicit operator bool() const + { + return !Policy::is_null(h); + } + + bool operator!() const + { + return !static_cast<bool>(*this); + } + + void reset(typename Policy::handle_type new_handle) + { + typename Policy::handle_type old_handle = h; + h = new_handle; + if(!Policy::is_null(old_handle)) + { + Policy::close(old_handle); + } + } + + void swap(unique_handle& other) + { + std::swap(this->h, other.h); + } + + void reset() + { + reset(Policy::get_null()); + } + + ~unique_handle() + { + reset(); + } + + unique_handle& operator=(unique_handle other) noexcept + { + this->swap(other); + return *this; + } + + unique_handle(unique_handle&& other) noexcept + { + this->h = other.h; + other.h = Policy::get_null(); + } + + unique_handle() + { + h = Policy::get_null(); + } + + unique_handle(typename Policy::handle_type handle) + { + h = handle; + } +}; |