From 2987f964d309366b5a8ea8e480f1596f8ff5a060 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Switch Automatizer over to using jsoncons --- src/include/tome/squelch/automatizer.hpp | 11 ++-- src/include/tome/squelch/condition.hpp | 90 ++++++++++++++++---------------- src/include/tome/squelch/rule.hpp | 10 ++-- 3 files changed, 55 insertions(+), 56 deletions(-) (limited to 'src/include/tome') diff --git a/src/include/tome/squelch/automatizer.hpp b/src/include/tome/squelch/automatizer.hpp index 786ca1ae..4361941a 100644 --- a/src/include/tome/squelch/automatizer.hpp +++ b/src/include/tome/squelch/automatizer.hpp @@ -2,8 +2,8 @@ #include #include +#include #include -#include #include "tome/squelch/rule_fwd.hpp" #include "tome/squelch/cursor_fwd.hpp" @@ -44,15 +44,14 @@ public: bool apply_rules(object_type *o_ptr, int item_idx) const; /** - * Build a JSON data structure to represent - * all the rules. + * Build a JSON document to represent all the rules. */ - std::shared_ptr to_json() const; + jsoncons::json to_json() const; /** - * Load rules from a JSON data structure. + * Load rules from a JSON document. */ - void load_json(json_t *json); + void load_json(jsoncons::json const &); /** * Remove currently selected condition or rule. diff --git a/src/include/tome/squelch/condition.hpp b/src/include/tome/squelch/condition.hpp index 5d1240f5..584ecb0e 100644 --- a/src/include/tome/squelch/condition.hpp +++ b/src/include/tome/squelch/condition.hpp @@ -3,10 +3,10 @@ #include "tome/squelch/condition_fwd.hpp" #include +#include #include #include -#include -#include +#include #include "tome/squelch/cursor_fwd.hpp" #include "tome/squelch/tree_printer_fwd.hpp" @@ -60,7 +60,7 @@ public: } public: - json_t *to_json() const; + jsoncons::json to_json() const; virtual void add_child(ConditionFactory const &factory) { // Default is to not support children. @@ -88,16 +88,16 @@ public: /** * Parse condition from JSON */ - static std::shared_ptr parse_condition(json_t *); + static std::shared_ptr parse_condition(jsoncons::json const &); /** * Convert an (optional) condition to JSON. */ - static json_t *optional_to_json(std::shared_ptr condition); + static jsoncons::json optional_to_json(std::shared_ptr condition); protected: virtual void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const = 0; - virtual void to_json(json_t *) const = 0; + virtual void to_json(jsoncons::json &) const = 0; // What do we want to match? match_type match; @@ -116,12 +116,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: uint8_t m_tval; @@ -140,12 +140,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_name; @@ -164,12 +164,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_contain; @@ -189,12 +189,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: uint8_t m_min; @@ -228,10 +228,10 @@ public: virtual std::shared_ptr next_child(Condition *current) override; // Parse a list of conditions from JSON property - static std::vector< std::shared_ptr > parse_conditions(json_t *); + static std::vector< std::shared_ptr > parse_conditions(jsoncons::json const &); protected: - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; protected: std::vector< std::shared_ptr > m_conditions; @@ -248,7 +248,7 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; @@ -265,7 +265,7 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; @@ -285,12 +285,12 @@ public: public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: status_type m_status; @@ -309,12 +309,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_race; @@ -333,12 +333,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_subrace; @@ -357,12 +357,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_class; @@ -381,12 +381,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: std::string m_inscription; @@ -406,12 +406,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: int m_min; @@ -432,12 +432,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: int m_min; @@ -459,12 +459,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: uint16_t m_skill_idx; @@ -485,12 +485,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: identification_state m_state; @@ -509,12 +509,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: char m_symbol; @@ -533,12 +533,12 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; private: uint16_t m_ability_idx; @@ -563,10 +563,10 @@ public: virtual std::shared_ptr first_child() override; protected: - void to_json(json_t *) const override; + void to_json(jsoncons::json &) const override; static std::shared_ptr parse_single_subcondition( - json_t *condition_json); + jsoncons::json const &condition_json); protected: std::shared_ptr m_subcondition; @@ -584,7 +584,7 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; @@ -603,7 +603,7 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: @@ -623,7 +623,7 @@ public: bool is_match(object_type *) const override; - static std::shared_ptr from_json(json_t *); + static std::shared_ptr from_json(jsoncons::json const &); protected: void write_tree(TreePrinter *, Cursor *, uint8_t, uint8_t) const override; diff --git a/src/include/tome/squelch/rule.hpp b/src/include/tome/squelch/rule.hpp index 63f1b6c0..752a0c2e 100644 --- a/src/include/tome/squelch/rule.hpp +++ b/src/include/tome/squelch/rule.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "tome/squelch/condition_fwd.hpp" #include "tome/squelch/cursor_fwd.hpp" @@ -75,14 +75,14 @@ public: bool apply_rule(object_type *o_ptr, int item_idx) const; /** - * Convert rule to JSON + * Convert rule to JSON. */ - virtual json_t *to_json() const; + virtual jsoncons::json to_json() const; /** * Parse rule from JSON */ - static std::shared_ptr parse_rule(json_t *); + static std::shared_ptr parse_rule(jsoncons::json const &); protected: virtual bool do_apply_rule(object_type *, int) const = 0; @@ -148,7 +148,7 @@ public: , m_inscription(inscription) { } - json_t *to_json() const override; + jsoncons::json to_json() const override; protected: virtual void do_write_tree(TreePrinter *p) const override; -- cgit v1.2.3