cgv
Loading...
Searching...
No Matches
cgv::ppp::variant Class Reference

Public Types

typedef std::vector< variantlist_type
 
typedef std::map< std::string, variantmap_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
 
variantoperator= (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_typeref_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 variantget_value () const
 lookup names and follow references and return the reached variant
 
variantref_value ()
 lookup names and follow references and return reference to the reached variant
 
variantget_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
 
variantref_element (unsigned int i)
 return a reference to the i-th element in a list or map
 
const variantget_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
variantref_element (const std::string &name)
 reference an element of a map by name
 
const variantget_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 
 
};  
 

Detailed Description

Definition at line 29 of file variant.h.

Member Typedef Documentation

◆ list_type

typedef std::vector<variant> cgv::ppp::variant::list_type

Definition at line 32 of file variant.h.

◆ map_type

typedef std::map<std::string, variant> cgv::ppp::variant::map_type

Definition at line 33 of file variant.h.

Constructor & Destructor Documentation

◆ variant() [1/11]

cgv::ppp::variant::variant ( )

construct undefined value

Definition at line 23 of file ppp_variant.cxx.

◆ variant() [2/11]

cgv::ppp::variant::variant ( const variant v)

use assign operator for copy constructor

Definition at line 26 of file ppp_variant.cxx.

References vt.

◆ variant() [3/11]

cgv::ppp::variant::variant ( bool  v)

construct bool value

Definition at line 43 of file ppp_variant.cxx.

◆ variant() [4/11]

cgv::ppp::variant::variant ( int  v)

construct integer value

Definition at line 44 of file ppp_variant.cxx.

◆ variant() [5/11]

cgv::ppp::variant::variant ( double  v)

construct double value

Definition at line 45 of file ppp_variant.cxx.

◆ variant() [6/11]

cgv::ppp::variant::variant ( const std::string &  v)

construct string value

Definition at line 46 of file ppp_variant.cxx.

◆ variant() [7/11]

cgv::ppp::variant::variant ( variant v)

construct reference value

Definition at line 47 of file ppp_variant.cxx.

◆ variant() [8/11]

cgv::ppp::variant::variant ( ValueType  vt,
const std::string &  v 
)

construct name value

Definition at line 49 of file ppp_variant.cxx.

References vt.

◆ variant() [9/11]

cgv::ppp::variant::variant ( const list_type &  v)

construct list value

Definition at line 55 of file ppp_variant.cxx.

◆ variant() [10/11]

cgv::ppp::variant::variant ( const map_type &  v)

construct map value

Definition at line 57 of file ppp_variant.cxx.

◆ variant() [11/11]

cgv::ppp::variant::variant ( const func_type v)

construct func value

Definition at line 59 of file ppp_variant.cxx.

◆ ~variant()

cgv::ppp::variant::~variant ( )

destructor

Definition at line 61 of file ppp_variant.cxx.

References clear().

Member Function Documentation

◆ append_to_list()

void cgv::ppp::variant::append_to_list ( const variant v)

Definition at line 990 of file ppp_variant.cxx.

◆ apply_binary()

void cgv::ppp::variant::apply_binary ( OperatorType  ot,
const variant v2 
)

Definition at line 283 of file ppp_variant.cxx.

◆ apply_unary()

void cgv::ppp::variant::apply_unary ( OperatorType  ot)

Definition at line 137 of file ppp_variant.cxx.

◆ binary_check_defined()

bool cgv::ppp::variant::binary_check_defined ( OperatorType  ot,
const variant v2 
)

Definition at line 265 of file ppp_variant.cxx.

◆ clear()

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().

◆ ensure_int_type()

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().

◆ get_bool()

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().

◆ get_double()

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().

◆ get_element() [1/2]

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().

◆ get_element() [2/2]

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().

◆ get_element_name()

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().

◆ get_int()

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().

◆ get_list()

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().

◆ get_map()

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().

◆ get_name()

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().

◆ get_reference()

variant * cgv::ppp::variant::get_reference ( ) const

return the pointer of a reference

Definition at line 839 of file ppp_variant.cxx.

◆ get_size()

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().

◆ 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().

◆ get_total_nr_elements()

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().

◆ get_type()

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().

◆ get_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().

◆ get_value_type()

ValueType cgv::ppp::variant::get_value_type ( ) const

◆ insert()

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.

◆ is_binary_applicable()

bool cgv::ppp::variant::is_binary_applicable ( OperatorType  ot,
const variant v2 
)

Definition at line 210 of file ppp_variant.cxx.

◆ is_bool()

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().

◆ is_double()

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().

◆ is_func()

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().

◆ is_int()

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().

◆ is_list()

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().

◆ is_map()

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().

◆ is_name()

bool cgv::ppp::variant::is_name ( ) const

only a name returns true

Definition at line 683 of file ppp_variant.cxx.

References get_type().

◆ is_reference()

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().

◆ is_str()

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().

◆ is_unary_applicable()

bool cgv::ppp::variant::is_unary_applicable ( OperatorType  ot)

Definition at line 102 of file ppp_variant.cxx.

◆ is_undefined()

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().

◆ match_number_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.

◆ operator=()

variant & cgv::ppp::variant::operator= ( const variant v)

assignment operator

Definition at line 81 of file ppp_variant.cxx.

References clear(), and vt.

◆ pop_back_from_list()

void cgv::ppp::variant::pop_back_from_list ( )

Definition at line 1000 of file ppp_variant.cxx.

◆ pop_front_from_list()

void cgv::ppp::variant::pop_front_from_list ( )

Definition at line 1005 of file ppp_variant.cxx.

◆ prepend_to_list()

void cgv::ppp::variant::prepend_to_list ( const variant v)

Definition at line 995 of file ppp_variant.cxx.

◆ ref_bool()

bool & cgv::ppp::variant::ref_bool ( )

Definition at line 851 of file ppp_variant.cxx.

◆ ref_double()

double & cgv::ppp::variant::ref_double ( )

Definition at line 861 of file ppp_variant.cxx.

◆ ref_element() [1/2]

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().

◆ ref_element() [2/2]

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().

◆ ref_func()

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().

◆ ref_int()

int & cgv::ppp::variant::ref_int ( )

Definition at line 856 of file ppp_variant.cxx.

◆ ref_list()

variant::list_type & cgv::ppp::variant::ref_list ( )

Definition at line 871 of file ppp_variant.cxx.

◆ ref_map()

variant::map_type & cgv::ppp::variant::ref_map ( )

Definition at line 901 of file ppp_variant.cxx.

◆ ref_str()

std::string & cgv::ppp::variant::ref_str ( )

Definition at line 866 of file ppp_variant.cxx.

◆ ref_value()

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().

◆ set_bool()

void cgv::ppp::variant::set_bool ( bool  v)

Definition at line 793 of file ppp_variant.cxx.

◆ set_double()

void cgv::ppp::variant::set_double ( double  v)

Definition at line 803 of file ppp_variant.cxx.

◆ set_int()

void cgv::ppp::variant::set_int ( int  v)

Definition at line 798 of file ppp_variant.cxx.

◆ set_list()

void cgv::ppp::variant::set_list ( )

Definition at line 818 of file ppp_variant.cxx.

◆ set_map()

void cgv::ppp::variant::set_map ( )

Definition at line 828 of file ppp_variant.cxx.

◆ set_name()

void cgv::ppp::variant::set_name ( const std::string &  n)

Definition at line 813 of file ppp_variant.cxx.

◆ set_str()

void cgv::ppp::variant::set_str ( const std::string &  v)

Definition at line 808 of file ppp_variant.cxx.

◆ unary_check_defined()

bool cgv::ppp::variant::unary_check_defined ( OperatorType  ot)

Definition at line 123 of file ppp_variant.cxx.

Member Data Documentation

◆ bool_value

bool cgv::ppp::variant::bool_value

Definition at line 38 of file variant.h.

◆ dbl_value

double cgv::ppp::variant::dbl_value

Definition at line 40 of file variant.h.

◆ func_value

func_type* cgv::ppp::variant::func_value

Definition at line 46 of file variant.h.

◆ int_value

int cgv::ppp::variant::int_value

Definition at line 39 of file variant.h.

◆ list_value

list_type* cgv::ppp::variant::list_value

Definition at line 44 of file variant.h.

◆ map_value

map_type* cgv::ppp::variant::map_value

Definition at line 45 of file variant.h.

◆ name_value

std::string* cgv::ppp::variant::name_value

Definition at line 43 of file variant.h.

◆ reference_value

variant* cgv::ppp::variant::reference_value

Definition at line 42 of file variant.h.

◆ string_value

std::string* cgv::ppp::variant::string_value

Definition at line 41 of file variant.h.

◆ vt

ValueType cgv::ppp::variant::vt
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().


The documentation for this class was generated from the following files: