Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::gil::variant< Types > Class Template Reference

Represents a concrete instance of a run-time specified type from a set of typesA concept is typically modeled by a collection of different types. More...

#include <variant.hpp>

Inheritance diagram for boost::gil::variant< Types >:

Classes

struct  base_t
 

Public Types

typedef Types types_t
 

Public Member Functions

 variant ()
 
virtual ~variant ()
 
template<typename T >
 variant (const T &obj)
 
template<typename T >
 variant (T &obj, bool do_swap)
 
template<typename T >
variantoperator= (const T &obj)
 
variantoperator= (const variant &v)
 
 variant (const variant &v)
 
template<typename T >
void move_in (T &obj)
 
template<typename T >
const T_dynamic_cast () const
 
template<typename T >
T_dynamic_cast ()
 
template<typename T >
bool current_type_is () const
 
base_t bits () const
 
std::size_t index () const
 

Static Public Member Functions

template<typename T >
static bool has_type ()
 

Friends

template<typename TS >
bool operator== (const variant< TS > &x, const variant< TS > &y)
 
template<typename TS >
bool operator!= (const variant< TS > &x, const variant< TS > &y)
 
template<typename Cs >
void swap (variant< Cs > &x, variant< Cs > &y)
 
template<typename Types2 , typename UnaryOp >
UnaryOp::result_type apply_operation (variant< Types2 > &var, UnaryOp op)
 
template<typename Types2 , typename UnaryOp >
UnaryOp::result_type apply_operation (const variant< Types2 > &var, UnaryOp op)
 
template<typename Types1 , typename Types2 , typename BinaryOp >
BinaryOp::result_type apply_operation (const variant< Types1 > &arg1, const variant< Types2 > &arg2, BinaryOp op)
 Invokes a generic constant operation (represented as a binary function object) on two variants. More...
 

Detailed Description

template<typename Types>
class boost::gil::variant< Types >

Represents a concrete instance of a run-time specified type from a set of types

A concept is typically modeled by a collection of different types.

They may be instantiations of a templated type with different template parameters or even completely unrelated types.

We call the type with which the concept is instantiated in a given place in the code "the concrete type". The concrete type must be chosen at compile time, which sometimes is a severe limitation. Consider, for example, having an image concept modeled by an image class templated over the color space. It would be difficult to write a function that reads an image from file preserving its native color space, since the type of the return value is only available at run time. It would be difficult to store images of different color spaces in the same container or apply operations on them uniformly.

The variant class addresses this deficiency. It allows for run-time instantiation of a class from a given set of allowed classes specified at compile time. For example, the set of allowed classes may include 8-bit and 16-bit RGB and CMYK images. Such a variant can be constructed with rgb8_image_t and then assigned a cmyk16_image_t.

The variant has a templated constructor, which allows us to construct it with any concrete type instantiation. It can also perform a generic operation on the concrete type via a call to apply_operation. The operation must be provided as a function object whose application operator has a single parameter which can be instantiated with any of the allowed types of the variant.

variant breaks down the instantiated type into a non-templated underlying base type and a unique instantiation type identifier. In the most common implementation the concrete instantiation in stored 'in-place' - in 'bits_t'. bits_t contains sufficient space to fit the largest of the instantiated objects.

GIL's variant is similar to boost::variant in spirit (hence we borrow the name from there) but it differs in several ways from the current boost implementation. Most notably, it does not take a variable number of template parameters but a single parameter defining the type enumeration. As such it can be used more effectively in generic code.

The Types parameter specifies the set of allowable types. It models MPL Random Access Container

Member Typedef Documentation

template<typename Types>
typedef Types boost::gil::variant< Types >::types_t

Constructor & Destructor Documentation

template<typename Types>
boost::gil::variant< Types >::variant ( )
inline
template<typename Types>
virtual boost::gil::variant< Types >::~variant ( )
inlinevirtual
template<typename Types>
template<typename T >
boost::gil::variant< Types >::variant ( const T obj)
inlineexplicit
template<typename Types >
template<typename T >
boost::gil::variant< Types >::variant ( T obj,
bool  do_swap 
)
explicit
template<typename Types>
boost::gil::variant< Types >::variant ( const variant< Types > &  v)
inline

Member Function Documentation

template<typename Types>
template<typename T >
const T& boost::gil::variant< Types >::_dynamic_cast ( ) const
inline
template<typename Types>
template<typename T >
T& boost::gil::variant< Types >::_dynamic_cast ( )
inline
template<typename Types>
base_t boost::gil::variant< Types >::bits ( ) const
inline
template<typename Types>
template<typename T >
bool boost::gil::variant< Types >::current_type_is ( ) const
inline
template<typename Types>
template<typename T >
static bool boost::gil::variant< Types >::has_type ( )
inlinestatic
template<typename Types>
std::size_t boost::gil::variant< Types >::index ( ) const
inline
template<typename Types>
template<typename T >
void boost::gil::variant< Types >::move_in ( T obj)
inline
template<typename Types>
template<typename T >
variant& boost::gil::variant< Types >::operator= ( const T obj)
inline
template<typename Types>
variant& boost::gil::variant< Types >::operator= ( const variant< Types > &  v)
inline

Friends And Related Function Documentation

template<typename Types>
template<typename Types2 , typename UnaryOp >
UnaryOp::result_type apply_operation ( variant< Types2 > &  var,
UnaryOp  op 
)
friend
template<typename Types>
template<typename Types2 , typename UnaryOp >
UnaryOp::result_type apply_operation ( const variant< Types2 > &  var,
UnaryOp  op 
)
friend
template<typename Types>
template<typename Types1 , typename Types2 , typename BinaryOp >
BinaryOp::result_type apply_operation ( const variant< Types1 > &  arg1,
const variant< Types2 > &  arg2,
BinaryOp  op 
)
friend

Invokes a generic constant operation (represented as a binary function object) on two variants.

template<typename Types>
template<typename TS >
bool operator!= ( const variant< TS > &  x,
const variant< TS > &  y 
)
friend
template<typename Types>
template<typename TS >
bool operator== ( const variant< TS > &  x,
const variant< TS > &  y 
)
friend
template<typename Types>
template<typename Cs >
void swap ( variant< Cs > &  x,
variant< Cs > &  y 
)
friend

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