26 #include <boost/range/iterator_range.hpp>
30 class variant_value_base;
31 class variant_iterator;
47 std::shared_ptr<T> res = std::dynamic_pointer_cast<T>(ptr);
60 return dynamic_cast<const T&
>(ptr);
61 }
catch(
const std::bad_cast&) {
135 return formula_variant::type::null;
146 virtual boost::iterator_range<variant_iterator>
make_iterator()
const;
211 return value_ == value_ref_cast<variant_numeric>(other).value_;
216 return value_ < value_ref_cast<variant_numeric>(other).value_;
233 return std::to_string(
value_);
248 return formula_variant::type::integer;
261 value_ =
static_cast<int>(value);
266 }
else if(value < -0.5) {
288 return formula_variant::type::decimal;
331 return formula_variant::type::object;
334 virtual boost::iterator_range<variant_iterator>
make_iterator()
const override;
337 virtual void iterator_inc(utils::any& iter)
const override;
338 virtual void iterator_dec(utils::any& iter)
const override;
387 return string_ == value_ref_cast<variant_string>(other).string_;
392 return string_ < value_ref_cast<variant_string>(other).string_;
397 return formula_variant::type::string;
407 template<
typename Derived>
443 virtual boost::iterator_range<variant_iterator>
make_iterator()
const override;
447 virtual bool iterator_equals(
const utils::any& first,
const utils::any& second)
const override;
484 return static_cast<const Derived&
>(value).get_container();
512 return formula_variant::type::list;
551 return formula_variant::type::map;
MacOS doesn't support std::any_cast when targing MacOS < 10.14 (currently we target 10....
void notify_dead() override
virtual bool equals(const variant_value_base &other) const override
Called to determine if this variant is equal to another of the same type.
virtual std::string get_debug_string(formula_seen_stack &seen, bool verbose) const override
Returns debug info for the variant value.
variant_callable(const_formula_callable_ptr callable)
virtual bool as_bool() const override
Returns a bool expression of the variant value.
virtual bool iterator_equals(const utils::any &, const utils::any &) const override
Implements the equality functionality of variant_iterator for a value of this type.
virtual std::string get_serialized_string() const override
Returns the stored variant value in formula syntax.
virtual variant deref_iterator(const utils::any &iter) const override
Implements the dereference functionality of variant_iterator for a value of this type.
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
virtual std::string string_cast() const override
Returns the stored variant value in plain string form.
virtual void iterator_inc(utils::any &iter) const override
Implements the increment functionality of variant_iterator for a value of this type.
virtual std::size_t num_elements() const override
Returns the number of elements in a type.
virtual boost::iterator_range< variant_iterator > make_iterator() const override
Creates an iterator pair that can be used for iteration.
formula_input_vector inputs
virtual void iterator_dec(utils::any &iter) const override
Implements the decrement functionality of variant_iterator for a value of this type.
const_formula_callable_ptr callable_
const_formula_callable_ptr get_callable() const
virtual bool less_than(const variant_value_base &other) const override
Called to determine if this variant is less than another of the same type.
Generalized interface for container variants.
virtual std::string get_serialized_string() const override
Returns the stored variant value in formula syntax.
virtual bool equals(const variant_value_base &other) const override
Inherited from variant_value_base.
virtual std::string string_cast() const override
Returns the stored variant value in plain string form.
virtual std::size_t num_elements() const override
Returns the number of elements in a type.
virtual void iterator_dec(utils::any &) const override
Implements the decrement functionality of variant_iterator for a value of this type.
virtual bool less_than(const variant_value_base &other) const override
Inherited from variant_value_base.
variant_container()=default
Only derived classes can instantiate this class.
virtual std::string get_debug_string(formula_seen_stack &seen, bool verbose) const override
Returns debug info for the variant value.
bool contains(const variant &member) const
const auto & container() const
Read-only access to the underlying container.
virtual boost::iterator_range< variant_iterator > make_iterator() const override
Creates an iterator pair that can be used for iteration.
std::function< std::string(const variant &)> to_string_op
virtual bool iterator_equals(const utils::any &first, const utils::any &second) const override
Implements the equality functionality of variant_iterator for a value of this type.
virtual void iterator_inc(utils::any &) const override
Implements the increment functionality of variant_iterator for a value of this type.
std::string to_string_impl(bool annotate, bool annotate_empty, const to_string_op &mod_func) const
String conversion helper for string_cast, get_serialized_string, and get_debug_string.
static const auto & container_for(const variant_value_base &value)
Helper to call get_container for the derived class.
virtual bool as_bool() const override
Returns a bool expression of the variant value.
virtual bool is_empty() const override
Whether the stored value is considered empty or not.
variant_decimal(int value)
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
std::string to_string_impl(const bool sign_value) const
variant_decimal(double value)
virtual std::string get_debug_string(formula_seen_stack &, bool) const override
Returns debug info for the variant value.
virtual std::string string_cast() const override
Returns the stored variant value in plain string form.
virtual std::string get_serialized_string() const override
Returns the stored variant value in formula syntax.
variant build_range_variant(int limit) const
virtual std::string get_debug_string(formula_seen_stack &, bool) const override
Returns debug info for the variant value.
virtual std::string get_serialized_string() const override
Returns the stored variant value in formula syntax.
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
virtual std::string string_cast() const override
Returns the stored variant value in plain string form.
static std::string to_string_detail(const variant &value, const to_string_op &op)
Helper for variant_container::to_string_impl.
variant_list(const variant_vector &vec)
virtual variant deref_iterator(const utils::any &) const override
Implements the dereference functionality of variant_iterator for a value of this type.
variant_list(variant_vector &&vec)
const variant_vector & get_container() const
variant_vector container_
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
variant_map(const variant_map_raw &map)
virtual variant deref_iterator(const utils::any &) const override
Implements the dereference functionality of variant_iterator for a value of this type.
const variant_map_raw & get_container() const
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
static std::string to_string_detail(const variant_map_raw::value_type &value, const to_string_op &op)
Helper for variant_container::to_string_impl.
variant_map_raw container_
variant_map(variant_map_raw &&map)
Base class for numeric variant values.
int get_numeric_value() const
virtual bool less_than(const variant_value_base &other) const override
Called to determine if this variant is less than another of the same type.
virtual bool equals(const variant_value_base &other) const override
Called to determine if this variant is equal to another of the same type.
virtual bool as_bool() const override
Returns a bool expression of the variant value.
variant_numeric(int value)
virtual std::string get_serialized_string() const override
Returns the stored variant value in formula syntax.
virtual bool as_bool() const override
Returns a bool expression of the variant value.
virtual std::string string_cast() const override
Returns the stored variant value in plain string form.
virtual bool equals(const variant_value_base &other) const override
Called to determine if this variant is equal to another of the same type.
variant_string(const std::string &str)
virtual formula_variant::type get_type() const override
Returns the id of the variant type.
virtual std::string get_debug_string(formula_seen_stack &, bool) const override
Returns debug info for the variant value.
variant_string(std::string &&str)
virtual bool is_empty() const override
Whether the stored value is considered empty or not.
virtual bool less_than(const variant_value_base &other) const override
Called to determine if this variant is less than another of the same type.
const std::string & get_string() const
Base class for all variant types.
virtual bool equals(const variant_value_base &) const
Called to determine if this variant is equal to another of the same type.
virtual std::string get_debug_string(formula_seen_stack &, bool) const
Returns debug info for the variant value.
virtual bool iterator_equals(const utils::any &, const utils::any &) const
Implements the equality functionality of variant_iterator for a value of this type.
virtual boost::iterator_range< variant_iterator > make_iterator() const
Creates an iterator pair that can be used for iteration.
virtual bool as_bool() const
Returns a bool expression of the variant value.
virtual formula_variant::type get_type() const
Returns the id of the variant type.
virtual bool less_than(const variant_value_base &) const
Called to determine if this variant is less than another of the same type.
virtual variant deref_iterator(const utils::any &iter) const
Implements the dereference functionality of variant_iterator for a value of this type.
virtual std::string string_cast() const
Returns the stored variant value in plain string form.
virtual void iterator_dec(utils::any &) const
Implements the decrement functionality of variant_iterator for a value of this type.
virtual void iterator_inc(utils::any &) const
Implements the increment functionality of variant_iterator for a value of this type.
virtual std::size_t num_elements() const
Returns the number of elements in a type.
virtual ~variant_value_base()
virtual std::string get_serialized_string() const
Returns the stored variant value in formula syntax.
virtual bool is_empty() const
Whether the stored value is considered empty or not.
bool contains(const Container &container, const Value &value)
Returns true iff value is found in container.
static std::shared_ptr< T > value_cast(value_base_ptr ptr)
Casts a variant_value_base shared pointer to a new derived type.
std::shared_ptr< variant_value_base > value_base_ptr
std::vector< variant > variant_vector
std::vector< const_formula_callable_ptr > formula_seen_stack
std::vector< formula_input > formula_input_vector
std::map< variant, variant > variant_map_raw
std::shared_ptr< const formula_callable > const_formula_callable_ptr
static const T & value_ref_cast(const variant_value_base &ptr)
Casts a variant_value_base reference to a new derived type.
Base class for all the errors encountered by the engine.
type_error(const std::string &str)