cgv
|
Public Types | |
typedef std::vector< variant > | list_type |
typedef std::map< std::string, variant > | map_type |
Public Member Functions | |
constructors | |
variant () | |
construct undefined value | |
variant (const variant &v) | |
use assign operator for copy constructor | |
variant (bool v) | |
construct bool value | |
variant (int v) | |
construct integer value | |
variant (double v) | |
construct double value | |
variant (const std::string &v) | |
construct string value | |
variant (variant *v) | |
construct reference value | |
variant (ValueType vt, const std::string &v) | |
construct name value | |
variant (const list_type &v) | |
construct list value | |
variant (const map_type &v) | |
construct map value | |
variant (const func_type &v) | |
construct func value | |
void | clear () |
remove all elements from a list or map and set to undefined type | |
variant & | operator= (const variant &v) |
assignment operator | |
~variant () | |
destructor | |
operator interface | |
bool | is_unary_applicable (OperatorType ot) |
bool | unary_check_defined (OperatorType ot) |
void | apply_unary (OperatorType ot) |
bool | is_binary_applicable (OperatorType ot, const variant &v2) |
bool | binary_check_defined (OperatorType ot, const variant &v2) |
void | apply_binary (OperatorType ot, const variant &v2) |
query type | |
ValueType | get_type () const |
return the variant type | |
ValueType | get_value_type () const |
lookup names and follow references and return value type | |
bool | is_undefined () const |
lookup names and follow references and return whether variant is undefined | |
bool | is_int () const |
lookup names and follow references and return whether variant is int | |
bool | is_double () const |
lookup names and follow references and return whether variant is double | |
bool | is_bool () const |
lookup names and follow references and return whether variant is bool | |
bool | is_str () const |
lookup names and follow references and return whether variant is string | |
bool | is_list () const |
lookup names and follow references and return whether variant is list | |
bool | is_map () const |
lookup names and follow references and return whether variant is map | |
bool | is_func () const |
lookup names and follow references and return whether variant is func | |
bool | is_reference () const |
name and reference type return true | |
bool | is_name () const |
only a name returns true | |
access to values with implicit type conversions accept list and map types | |
bool | get_bool () const |
lookup names and follow references and convert to bool: undef ... false, int ... compares unequal zero, string ... convert to int and compare unequal zero, list/map ... check size unequal zero | |
int | get_int () const |
lookup names and follow references and convert to int: undef ... -1, bool ... 0 or 1, string ... atoi, list/map ... size | |
double | get_double () const |
lookup names and follow references and convert to double: undef ... -1, bool ... 0 or 1, string ... atof, list/map ... size | |
std::string | get_str () const |
lookup names and follow references and convert to string | |
const list_type & | get_list () const |
constant access to list value | |
const map_type & | get_map () const |
constant access to map value | |
void | ensure_int_type () |
convert to int type | |
bool | match_number_type (const variant &v2) |
convert to int or double such that result of binary operators can be stored in this variant without loss of data, return whether conversion was to int | |
references to values. Before usage ensure that type is matched. | |
bool & | ref_bool () |
int & | ref_int () |
double & | ref_double () |
std::string & | ref_str () |
list_type & | ref_list () |
map_type & | ref_map () |
func_type & | ref_func () |
access to func value | |
setters | |
void | set_bool (bool v) |
void | set_int (int v) |
void | set_double (double v) |
void | set_str (const std::string &v) |
void | set_name (const std::string &n) |
void | set_list () |
void | set_list (const std::vector< variant > &l) |
void | set_map () |
void | set_map (const std::map< std::string, variant > &m) |
name and reference interface | |
const variant & | get_value () const |
lookup names and follow references and return the reached variant | |
variant & | ref_value () |
lookup names and follow references and return reference to the reached variant | |
variant * | get_reference () const |
return the pointer of a reference | |
const std::string & | get_name () const |
return the name of a name value | |
common list and map interface | |
unsigned int | get_size () const |
return number of elements in a list or map | |
unsigned | get_total_nr_elements () const |
return total number of elements in a list or map summing over all elements recursively | |
variant & | ref_element (unsigned int i) |
return a reference to the i-th element in a list or map | |
const variant & | get_element (unsigned int i) const |
return a const reference to the i-th element in a list or map | |
list interface | |
void | append_to_list (const variant &v) |
void | prepend_to_list (const variant &v) |
void | pop_back_from_list () |
void | pop_front_from_list () |
map interface | |
variant & | ref_element (const std::string &name) |
reference an element of a map by name | |
const variant & | get_element (const std::string &name) |
const reference an element of a map by name | |
const std::string & | get_element_name (unsigned int i) const |
return the name of the i-th element in a map | |
void | insert (const std::string &name, const variant &v) |
insert a new entry to the map | |
Protected Attributes | ||
ValueType | vt | |
store type of value | ||
union { | ||
bool bool_value | ||
int int_value | ||
double dbl_value | ||
std::string * string_value | ||
variant * reference_value | ||
std::string * name_value | ||
list_type * list_value | ||
map_type * map_value | ||
func_type * func_value | ||
}; | ||
typedef std::map<std::string, variant> cgv::ppp::variant::map_type |
cgv::ppp::variant::variant | ( | ) |
construct undefined value
Definition at line 23 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | const variant & | v | ) |
use assign operator for copy constructor
Definition at line 26 of file ppp_variant.cxx.
References vt.
cgv::ppp::variant::variant | ( | bool | v | ) |
construct bool value
Definition at line 43 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | int | v | ) |
construct integer value
Definition at line 44 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | double | v | ) |
construct double value
Definition at line 45 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | const std::string & | v | ) |
construct string value
Definition at line 46 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | variant * | v | ) |
construct reference value
Definition at line 47 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | ValueType | vt, |
const std::string & | v | ||
) |
cgv::ppp::variant::variant | ( | const list_type & | v | ) |
construct list value
Definition at line 55 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | const map_type & | v | ) |
construct map value
Definition at line 57 of file ppp_variant.cxx.
cgv::ppp::variant::variant | ( | const func_type & | v | ) |
construct func value
Definition at line 59 of file ppp_variant.cxx.
cgv::ppp::variant::~variant | ( | ) |
void cgv::ppp::variant::append_to_list | ( | const variant & | v | ) |
Definition at line 990 of file ppp_variant.cxx.
void cgv::ppp::variant::apply_binary | ( | OperatorType | ot, |
const variant & | v2 | ||
) |
Definition at line 283 of file ppp_variant.cxx.
void cgv::ppp::variant::apply_unary | ( | OperatorType | ot | ) |
Definition at line 137 of file ppp_variant.cxx.
bool cgv::ppp::variant::binary_check_defined | ( | OperatorType | ot, |
const variant & | v2 | ||
) |
Definition at line 265 of file ppp_variant.cxx.
void cgv::ppp::variant::clear | ( | ) |
remove all elements from a list or map and set to undefined type
Definition at line 66 of file ppp_variant.cxx.
References vt.
Referenced by operator=(), and ~variant().
void cgv::ppp::variant::ensure_int_type | ( | ) |
convert to int type
Definition at line 882 of file ppp_variant.cxx.
References get_int(), and ref_value().
Referenced by match_number_type().
bool cgv::ppp::variant::get_bool | ( | ) | const |
lookup names and follow references and convert to bool: undef ... false, int ... compares unequal zero, string ... convert to int and compare unequal zero, list/map ... check size unequal zero
Definition at line 689 of file ppp_variant.cxx.
References get_size(), get_str(), get_value(), and get_value_type().
double cgv::ppp::variant::get_double | ( | ) | const |
lookup names and follow references and convert to double: undef ... -1, bool ... 0 or 1, string ... atof, list/map ... size
Definition at line 731 of file ppp_variant.cxx.
References get_size(), get_str(), get_value(), and get_value_type().
Referenced by match_number_type().
const variant & cgv::ppp::variant::get_element | ( | const std::string & | name | ) |
const reference an element of a map by name
Definition at line 1010 of file ppp_variant.cxx.
References get_value_type().
const variant & cgv::ppp::variant::get_element | ( | unsigned int | i | ) | const |
return a const reference to the i-th element in a list or map
Definition at line 979 of file ppp_variant.cxx.
References get_list(), get_map(), and get_value_type().
Referenced by cgv::ppp::expression_processor::evaluate(), and get_str().
const std::string & cgv::ppp::variant::get_element_name | ( | unsigned int | i | ) | const |
return the name of the i-th element in a map
Definition at line 1031 of file ppp_variant.cxx.
References get_map().
Referenced by cgv::ppp::expression_processor::evaluate(), and get_str().
int cgv::ppp::variant::get_int | ( | ) | const |
lookup names and follow references and convert to int: undef ... -1, bool ... 0 or 1, string ... atoi, list/map ... size
Definition at line 710 of file ppp_variant.cxx.
References get_size(), get_str(), get_value(), and get_value_type().
Referenced by ensure_int_type(), and cgv::ppp::expression_processor::evaluate().
const variant::list_type & cgv::ppp::variant::get_list | ( | ) | const |
constant access to list value
Definition at line 845 of file ppp_variant.cxx.
References get_value().
Referenced by get_element(), get_size(), and get_total_nr_elements().
const variant::map_type & cgv::ppp::variant::get_map | ( | ) | const |
constant access to map value
Definition at line 876 of file ppp_variant.cxx.
References get_value().
Referenced by get_element(), get_element_name(), get_size(), and get_total_nr_elements().
const std::string & cgv::ppp::variant::get_name | ( | ) | const |
return the name of a name value
Definition at line 784 of file ppp_variant.cxx.
References get_type().
Referenced by get_value(), get_value_type(), and ref_value().
variant * cgv::ppp::variant::get_reference | ( | ) | const |
return the pointer of a reference
Definition at line 839 of file ppp_variant.cxx.
unsigned int cgv::ppp::variant::get_size | ( | ) | const |
return number of elements in a list or map
Definition at line 931 of file ppp_variant.cxx.
References get_list(), get_map(), get_value(), and get_value_type().
Referenced by get_bool(), get_double(), get_int(), and get_str().
std::string cgv::ppp::variant::get_str | ( | ) | const |
lookup names and follow references and convert to string
Definition at line 752 of file ppp_variant.cxx.
References get_element(), get_element_name(), get_size(), get_str(), get_type(), get_value(), get_value_type(), and cgv::utils::to_string().
Referenced by cgv::ppp::expression_processor::evaluate(), get_bool(), get_double(), get_int(), and get_str().
unsigned cgv::ppp::variant::get_total_nr_elements | ( | ) | const |
return total number of elements in a list or map summing over all elements recursively
Definition at line 943 of file ppp_variant.cxx.
References get_list(), get_map(), get_total_nr_elements(), and get_value_type().
Referenced by get_total_nr_elements().
ValueType cgv::ppp::variant::get_type | ( | ) | const |
return the variant type
Definition at line 617 of file ppp_variant.cxx.
References vt.
Referenced by get_name(), get_str(), get_value(), get_value_type(), is_name(), is_reference(), match_number_type(), and ref_value().
const variant & cgv::ppp::variant::get_value | ( | ) | const |
lookup names and follow references and return the reached variant
Definition at line 913 of file ppp_variant.cxx.
References get_name(), get_type(), and get_value().
Referenced by get_bool(), get_double(), get_int(), get_list(), get_map(), get_size(), get_str(), and get_value().
ValueType cgv::ppp::variant::get_value_type | ( | ) | const |
lookup names and follow references and return value type
Definition at line 622 of file ppp_variant.cxx.
References get_name(), get_type(), and get_value_type().
Referenced by get_bool(), get_double(), get_element(), get_element(), get_int(), get_size(), get_str(), get_total_nr_elements(), get_value_type(), is_bool(), is_double(), is_func(), is_int(), is_list(), is_map(), is_str(), is_undefined(), ref_element(), and ref_element().
void cgv::ppp::variant::insert | ( | const std::string & | name, |
const variant & | v | ||
) |
insert a new entry to the map
Definition at line 1039 of file ppp_variant.cxx.
bool cgv::ppp::variant::is_binary_applicable | ( | OperatorType | ot, |
const variant & | v2 | ||
) |
Definition at line 210 of file ppp_variant.cxx.
bool cgv::ppp::variant::is_bool | ( | ) | const |
lookup names and follow references and return whether variant is bool
Definition at line 641 of file ppp_variant.cxx.
References get_value_type().
bool cgv::ppp::variant::is_double | ( | ) | const |
lookup names and follow references and return whether variant is double
Definition at line 651 of file ppp_variant.cxx.
References get_value_type().
bool cgv::ppp::variant::is_func | ( | ) | const |
lookup names and follow references and return whether variant is func
Definition at line 672 of file ppp_variant.cxx.
References get_value_type().
Referenced by cgv::ppp::expression_processor::evaluate().
bool cgv::ppp::variant::is_int | ( | ) | const |
lookup names and follow references and return whether variant is int
Definition at line 646 of file ppp_variant.cxx.
References get_value_type().
Referenced by cgv::ppp::expression_processor::evaluate().
bool cgv::ppp::variant::is_list | ( | ) | const |
lookup names and follow references and return whether variant is list
Definition at line 661 of file ppp_variant.cxx.
References get_value_type().
bool cgv::ppp::variant::is_map | ( | ) | const |
lookup names and follow references and return whether variant is map
Definition at line 666 of file ppp_variant.cxx.
References get_value_type().
bool cgv::ppp::variant::is_name | ( | ) | const |
bool cgv::ppp::variant::is_reference | ( | ) | const |
name and reference type return true
Definition at line 678 of file ppp_variant.cxx.
References get_type().
bool cgv::ppp::variant::is_str | ( | ) | const |
lookup names and follow references and return whether variant is string
Definition at line 656 of file ppp_variant.cxx.
References get_value_type().
Referenced by cgv::ppp::expression_processor::evaluate().
bool cgv::ppp::variant::is_unary_applicable | ( | OperatorType | ot | ) |
Definition at line 102 of file ppp_variant.cxx.
bool cgv::ppp::variant::is_undefined | ( | ) | const |
lookup names and follow references and return whether variant is undefined
Definition at line 636 of file ppp_variant.cxx.
References get_value_type().
bool cgv::ppp::variant::match_number_type | ( | const variant & | v2 | ) |
convert to int or double such that result of binary operators can be stored in this variant without loss of data, return whether conversion was to int
Definition at line 888 of file ppp_variant.cxx.
References ensure_int_type(), get_double(), get_type(), ref_value(), and vt.
void cgv::ppp::variant::pop_back_from_list | ( | ) |
Definition at line 1000 of file ppp_variant.cxx.
void cgv::ppp::variant::pop_front_from_list | ( | ) |
Definition at line 1005 of file ppp_variant.cxx.
void cgv::ppp::variant::prepend_to_list | ( | const variant & | v | ) |
Definition at line 995 of file ppp_variant.cxx.
bool & cgv::ppp::variant::ref_bool | ( | ) |
Definition at line 851 of file ppp_variant.cxx.
double & cgv::ppp::variant::ref_double | ( | ) |
Definition at line 861 of file ppp_variant.cxx.
variant & cgv::ppp::variant::ref_element | ( | const std::string & | name | ) |
reference an element of a map by name
Definition at line 1019 of file ppp_variant.cxx.
References get_value_type().
variant & cgv::ppp::variant::ref_element | ( | unsigned int | i | ) |
return a reference to the i-th element in a list or map
Definition at line 968 of file ppp_variant.cxx.
References get_value_type().
func_type & cgv::ppp::variant::ref_func | ( | ) |
access to func value
Definition at line 907 of file ppp_variant.cxx.
References ref_value().
Referenced by cgv::ppp::expression_processor::evaluate().
int & cgv::ppp::variant::ref_int | ( | ) |
Definition at line 856 of file ppp_variant.cxx.
variant::list_type & cgv::ppp::variant::ref_list | ( | ) |
Definition at line 871 of file ppp_variant.cxx.
variant::map_type & cgv::ppp::variant::ref_map | ( | ) |
Definition at line 901 of file ppp_variant.cxx.
std::string & cgv::ppp::variant::ref_str | ( | ) |
Definition at line 866 of file ppp_variant.cxx.
variant & cgv::ppp::variant::ref_value | ( | ) |
lookup names and follow references and return reference to the reached variant
Definition at line 922 of file ppp_variant.cxx.
References get_name(), get_type(), and ref_value().
Referenced by ensure_int_type(), cgv::ppp::expression_processor::evaluate(), match_number_type(), ref_func(), and ref_value().
void cgv::ppp::variant::set_bool | ( | bool | v | ) |
Definition at line 793 of file ppp_variant.cxx.
void cgv::ppp::variant::set_double | ( | double | v | ) |
Definition at line 803 of file ppp_variant.cxx.
void cgv::ppp::variant::set_int | ( | int | v | ) |
Definition at line 798 of file ppp_variant.cxx.
void cgv::ppp::variant::set_list | ( | ) |
Definition at line 818 of file ppp_variant.cxx.
void cgv::ppp::variant::set_map | ( | ) |
Definition at line 828 of file ppp_variant.cxx.
void cgv::ppp::variant::set_name | ( | const std::string & | n | ) |
Definition at line 813 of file ppp_variant.cxx.
void cgv::ppp::variant::set_str | ( | const std::string & | v | ) |
Definition at line 808 of file ppp_variant.cxx.
bool cgv::ppp::variant::unary_check_defined | ( | OperatorType | ot | ) |
Definition at line 123 of file ppp_variant.cxx.
|
protected |
store type of value
Definition at line 36 of file variant.h.
Referenced by clear(), get_type(), match_number_type(), operator=(), variant(), and variant().