xlnt - community edition
Public Types | Public Member Functions | Static Public Member Functions | List of all members
xlnt::variant Class Reference

Represents an object that can have variable type. More...

#include <variant.hpp>

Public Types

enum  type {
  vector = 1, null = 6, i4 = 9, lpstr = 20,
  date = 23, boolean = 25
}
 The possible types a variant can hold. More...
 

Public Member Functions

 variant ()
 Default constructor. Creates a null-type variant. More...
 
 variant (const std::string &value)
 Creates a string-type variant with the given value. More...
 
 variant (const char *value)
 Creates a string-type variant with the given value. More...
 
 variant (std::int32_t value)
 Creates a i4-type variant with the given value. More...
 
 variant (bool value)
 Creates a bool-type variant with the given value. More...
 
 variant (const datetime &value)
 Creates a datetime-type variant with the given value. More...
 
 variant (const std::initializer_list< std::int32_t > &value)
 Creates a vector_i4-type variant with the given value. More...
 
 variant (const std::vector< std::int32_t > &value)
 Creates a vector_i4-type variant with the given value. More...
 
 variant (const std::initializer_list< const char *> &value)
 Creates a vector_string-type variant with the given value. More...
 
 variant (const std::vector< const char *> &value)
 Creates a vector_string-type variant with the given value. More...
 
 variant (const std::initializer_list< std::string > &value)
 Creates a vector_string-type variant with the given value. More...
 
 variant (const std::vector< std::string > &value)
 Creates a vector_string-type variant with the given value. More...
 
 variant (const std::initializer_list< bool > &value)
 Creates a vector_bool-type variant with the given value. More...
 
 variant (const std::vector< bool > &value)
 Creates a vector_bool-type variant with the given value. More...
 
 variant (const std::initializer_list< datetime > &value)
 Creates a vector_datetime-type variant with the given value. More...
 
 variant (const std::vector< datetime > &value)
 Creates a vector_datetime-type variant with the given value. More...
 
 variant (const std::initializer_list< variant > &value)
 Creates a vector_variant-type variant with the given value. More...
 
 variant (const std::vector< variant > &value)
 Creates a vector_variant-type variant with the given value. More...
 
bool is (type t) const
 Returns true if this variant is of type t. More...
 
template<typename T >
get () const
 Returns the value of this variant as type T. Assumes that the variant is of type T (please call is() or value_type() to check). For details on each type, please see the documentation for each get<T> function below. An xlnt::bad_variant_access exception will be thrown if the types are not convertible. More...
 
type value_type () const
 Returns the type of this variant. More...
 
bool operator== (const variant &rhs) const
 
bool operator!= (const variant &rhs) const
 
template<>
bool get () const
 Returns the value of this variant as type bool. Assumes that the variant is of type::boolean (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 
template<>
std::int32_t get () const
 Returns the value of this variant as type std::int32_t. Assumes that the variant is of type::i4 (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 
template<>
std::string get () const
 Returns the value of this variant as type std::string. Please call is() or value_type() to check the type. The following types are compatible: More...
 
template<>
datetime get () const
 Returns the value of this variant as type xlnt::datetime. Assumes that the variant is of type::date (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 
template<>
std::vector< variantget () const
 Returns the value of this variant as type std::vector<xlnt::variant>. Please call is() or value_type() to check the type. The following types are compatible: More...
 
template<>
std::vector< bool > get () const
 Returns the value of this variant as type std::vector<bool>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::boolean. An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 
template<>
std::vector< std::int32_t > get () const
 Returns the value of this variant as type std::vector<std::int32_t>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::i4. An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 
template<>
std::vector< std::string > get () const
 Returns the value of this variant as type std::vector<std::string>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type: More...
 
template<>
std::vector< datetimeget () const
 Returns the value of this variant as type std::vector<xlnt::datetime>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::date. An xlnt::bad_variant_access exception will be thrown if the types are not compatible. More...
 

Static Public Member Functions

static std::string get_type_string (type type)
 Returns a displayable string for the specified type. More...
 

Detailed Description

Represents an object that can have variable type.

Member Enumeration Documentation

◆ type

enum xlnt::variant::type
strong

The possible types a variant can hold.

Constructor & Destructor Documentation

◆ variant() [1/18]

xlnt::variant::variant ( )

Default constructor. Creates a null-type variant.

◆ variant() [2/18]

xlnt::variant::variant ( const std::string &  value)

Creates a string-type variant with the given value.

◆ variant() [3/18]

xlnt::variant::variant ( const char *  value)

Creates a string-type variant with the given value.

◆ variant() [4/18]

xlnt::variant::variant ( std::int32_t  value)

Creates a i4-type variant with the given value.

◆ variant() [5/18]

xlnt::variant::variant ( bool  value)

Creates a bool-type variant with the given value.

◆ variant() [6/18]

xlnt::variant::variant ( const datetime value)

Creates a datetime-type variant with the given value.

◆ variant() [7/18]

xlnt::variant::variant ( const std::initializer_list< std::int32_t > &  value)

Creates a vector_i4-type variant with the given value.

◆ variant() [8/18]

xlnt::variant::variant ( const std::vector< std::int32_t > &  value)

Creates a vector_i4-type variant with the given value.

◆ variant() [9/18]

xlnt::variant::variant ( const std::initializer_list< const char *> &  value)

Creates a vector_string-type variant with the given value.

◆ variant() [10/18]

xlnt::variant::variant ( const std::vector< const char *> &  value)

Creates a vector_string-type variant with the given value.

◆ variant() [11/18]

xlnt::variant::variant ( const std::initializer_list< std::string > &  value)

Creates a vector_string-type variant with the given value.

◆ variant() [12/18]

xlnt::variant::variant ( const std::vector< std::string > &  value)

Creates a vector_string-type variant with the given value.

◆ variant() [13/18]

xlnt::variant::variant ( const std::initializer_list< bool > &  value)

Creates a vector_bool-type variant with the given value.

◆ variant() [14/18]

xlnt::variant::variant ( const std::vector< bool > &  value)

Creates a vector_bool-type variant with the given value.

◆ variant() [15/18]

xlnt::variant::variant ( const std::initializer_list< datetime > &  value)

Creates a vector_datetime-type variant with the given value.

◆ variant() [16/18]

xlnt::variant::variant ( const std::vector< datetime > &  value)

Creates a vector_datetime-type variant with the given value.

◆ variant() [17/18]

xlnt::variant::variant ( const std::initializer_list< variant > &  value)

Creates a vector_variant-type variant with the given value.

◆ variant() [18/18]

xlnt::variant::variant ( const std::vector< variant > &  value)

Creates a vector_variant-type variant with the given value.

Member Function Documentation

◆ get() [1/10]

template<typename T >
T xlnt::variant::get ( ) const

Returns the value of this variant as type T. Assumes that the variant is of type T (please call is() or value_type() to check). For details on each type, please see the documentation for each get<T> function below. An xlnt::bad_variant_access exception will be thrown if the types are not convertible.

◆ get() [2/10]

template<>
bool xlnt::variant::get ( ) const

Returns the value of this variant as type bool. Assumes that the variant is of type::boolean (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [3/10]

template<>
std::int32_t xlnt::variant::get ( ) const

Returns the value of this variant as type std::int32_t. Assumes that the variant is of type::i4 (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [4/10]

template<>
std::string xlnt::variant::get ( ) const

Returns the value of this variant as type std::string. Please call is() or value_type() to check the type. The following types are compatible:

  • type::lpstr
  • type::date (DEPRECATED, will no longer be allowed in a future major version) An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [5/10]

template<>
datetime xlnt::variant::get ( ) const

Returns the value of this variant as type xlnt::datetime. Assumes that the variant is of type::date (please call is() or value_type() to check). An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [6/10]

template<>
std::vector<variant> xlnt::variant::get ( ) const

Returns the value of this variant as type std::vector<xlnt::variant>. Please call is() or value_type() to check the type. The following types are compatible:

  • type::vector containing elements of type::variant
  • type::vector containing any other elements (DEPRECATED, will no longer be allowed in a future major version) An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [7/10]

template<>
std::vector<bool> xlnt::variant::get ( ) const

Returns the value of this variant as type std::vector<bool>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::boolean. An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [8/10]

template<>
std::vector<std::int32_t> xlnt::variant::get ( ) const

Returns the value of this variant as type std::vector<std::int32_t>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::i4. An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [9/10]

template<>
std::vector<std::string> xlnt::variant::get ( ) const

Returns the value of this variant as type std::vector<std::string>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type:

  • type::lpstr
  • type::date (DEPRECATED, will no longer be allowed in a future major version) An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get() [10/10]

template<>
std::vector<datetime> xlnt::variant::get ( ) const

Returns the value of this variant as type std::vector<xlnt::datetime>. Assumes that the variant is of type::vector (please call is() or value_type() to check) containing elements of type::date. An xlnt::bad_variant_access exception will be thrown if the types are not compatible.

◆ get_type_string()

static std::string xlnt::variant::get_type_string ( type  type)
static

Returns a displayable string for the specified type.

◆ is()

bool xlnt::variant::is ( type  t) const

Returns true if this variant is of type t.

◆ value_type()

type xlnt::variant::value_type ( ) const

Returns the type of this variant.


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