#ifndef PARAM_H #define PARAM_H #include #include #include #include #include #include #include #include namespace param { enum class Kind { Decimal, Integer, Boolean, Text }; enum class Error { None, Unknown, Undeclared, AlreadyDeclared, Value, Syntax, Mismatch }; struct Value { Kind kind = Kind::Text; std::int64_t decimal_micros = 0; int integer = 0; bool boolean = false; std::string text; }; struct Schema { std::string name; Kind kind; Value default_value; }; struct Result { Error error = Error::None; std::string payload; }; struct Assignment { std::string name; std::string token; }; bool valid_name(std::string_view name); std::optional find_schema(std::string_view name); const std::array& schema_order(); std::optional parse_value(const Schema& schema, std::string_view token); std::string format_value(const Value& value); std::string kind_name(Kind kind); std::string error_name(Error error); bool equal_value(const Value& left, const Value& right); class Store { public: Store() = default; void clear(); Result declare_one(const std::string& name); Result declare_defaults(); Result declare_many(const std::vector& names); Result get(const std::string& name) const; Result set(const std::string& name, const std::string& token); Result patch(const std::vector& assignments); Result reset(const std::string& name); Result list() const; Result count() const; Result describe(const std::string& name) const; Result compare(const std::string& name, const std::string& token) const; Result changes() const; Result restore_all(); Result remove(const std::string& name); Result remove_all(); Result validate(const std::string& name, const std::string& token) const; Result cas(const std::string& name, const std::string& expected, const std::string& replacement); Result defaults() const; Result missing() const; Result declared_query(const std::string& name) const; bool declared(const std::string& name) const; std::size_t size() const; private: std::vector> values_; Error validate_target(const std::string& name) const; Result read_with_schema(const std::string& name, const Schema& schema) const; Result write_one(const std::string& name, const Value& value); }; std::vector split_fields(std::string_view line); Result execute(Store& store, std::string_view line); std::string render(const Result& result); std::string trim_line_end(std::string line); } // namespace param #endif