DCMTK  Version 3.6.1 20170228
OFFIS DICOM Toolkit
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Functions
OFvisit – OFvariant

Apply a visitor to an OFvariant object. More...

Functions

template<typename Result , typename Visitor , typename... Alternatives>
Result OFvisit (Visitor visitor, OFvariant< Alternatives...> &v)
 Applies the given visitor to the given OFvariant object. More...
 
template<typename Result , typename Visitor , typename... Alternatives>
Result OFvisit (Visitor visitor, const OFvariant< Alternatives...> &v)
 Applies the given visitor to the given OFvariant object. More...
 

Detailed Description

Apply a visitor to an OFvariant object.

See also
OFget – Get a pointer to the value stored in an OFvariant holding the selected alternative.

Function Documentation

template<typename Result , typename Visitor , typename... Alternatives>
Result OFvisit ( Visitor  visitor,
OFvariant< Alternatives...> &  v 
)
related

Applies the given visitor to the given OFvariant object.

Template Parameters
Resultthe type of the returned value. Pre C++11 compiles do not allow determining the result type automatically in a portable way, therefore, it must be explicitly given by the caller.
Visitorthe type of the visitor, will be deduced automatically.
Alternativesthe alternatives the given variant could hold, will be deduced automatically.
Parameters
visitorthe visitor that will be invoked with the alternative currently being held by the given OFvariant object.
va reference to an OFvariant object that is going to be visited.
Returns
Let CurrentAlternative be the alternative that v currently holds: the result of visitor( *OFget<CurrentAlternative>( &v ) ) will be converted to Result and then returned.
Precondition
all possible results must be convertible to Result.
visitor must be able to take all possible alternatives.
Note
If C++11 support is available, the visitor will be forwarded using perfect forwarding. If not, the visitor may be copy constructed at least once, therefore, the visitor needs to be copy constructible when pre C++11 compilers are targeted.

Usage Example:

struct PowerVisitor
{
template<typename Number>
Number operator()( Number number )
{
return number * number;
}
};
struct PrintVisitor
{
template<typename Number>
void operator()( Number number )
{
COUT << number << OFendl;
}
};
struct AssignVisitor
{
template<typename Number>
void operator()( Number& number )
{
number *= number;
}
};
// ...
OFvariant<int,float,double> result = OFvisit<OFvariant<int,float,double> >( PowerVisitor(), v );
switch( result.index() )
{
case 0: COUT << "int "; break;
case 1: COUT << "float "; break;
case 2: COUT << "double "; break;
}
OFvisit<void>( PrintVisitor(), result );
COUT << "double " << OFvisit<double>( PowerVisitor(), v ) << OFendl; // OK, every alternative fits inside double
COUT << "int " << OFvisit<int>( PowerVisitor(), v ) << OFendl; // OK, value will be truncated!
COUT << "string " << OFvisit<OFString>( PowerVisitor(), v ) << OFendl; // ERROR!
OFvisit<void>( AssignVisitor(), v );
OFvisit<void>( PrintVisitor(), v );

Output (if the error was removed):

double 9.8596
double 9.8596
int 9
9.8596
template<typename Result , typename Visitor , typename... Alternatives>
Result OFvisit ( Visitor  visitor,
const OFvariant< Alternatives...> &  v 
)
related

Applies the given visitor to the given OFvariant object.

Template Parameters
Resultthe type of the returned value. Pre C++11 compiles do not allow determining the result type automatically in a portable way, therefore, it must be explicitly given by the caller.
Visitorthe type of the visitor, will be deduced automatically.
Alternativesthe alternatives the given variant could hold, will be deduced automatically.
Parameters
visitorthe visitor that will be invoked with the alternative currently being held by the given OFvariant object.
va const reference to an OFvariant object that is going to be visited.
Returns
Let CurrentAlternative be the alternative that v currently holds: the result of visitor( *OFget<CurrentAlternative>( &v ) ) will be converted to Result and then returned.
Precondition
all possible results must be convertible to Result.
visitor must be able to take all possible alternatives.
Note
If C++11 support is available, the visitor will be forwarded using perfect forwarding. If not, the visitor may be copy constructed at least once, therefore, the visitor needs to be copy constructible when pre C++11 compilers are targeted.

Usage Example:

struct PowerVisitor
{
template<typename Number>
Number operator()( Number number )
{
return number * number;
}
};
struct PrintVisitor
{
template<typename Number>
void operator()( Number number )
{
COUT << number << OFendl;
}
};
struct AssignVisitor
{
template<typename Number>
void operator()( Number& number )
{
number *= number;
}
};
// ...
OFvariant<int,float,double> result = OFvisit<OFvariant<int,float,double> >( PowerVisitor(), v );
switch( result.index() )
{
case 0: COUT << "int "; break;
case 1: COUT << "float "; break;
case 2: COUT << "double "; break;
}
OFvisit<void>( PrintVisitor(), result );
COUT << "double " << OFvisit<double>( PowerVisitor(), v ) << OFendl; // OK, every alternative fits inside double
COUT << "int " << OFvisit<int>( PowerVisitor(), v ) << OFendl; // OK, value will be truncated!
COUT << "string " << OFvisit<OFString>( PowerVisitor(), v ) << OFendl; // ERROR!
OFvisit<void>( AssignVisitor(), v ); // ERROR, v is const!
OFvisit<void>( PrintVisitor(), v );

Output (if the errors were removed):

double 9.8596
double 9.8596
int 9
3.14


Generated on Tue Feb 28 2017 for DCMTK Version 3.6.1 20170228 by Doxygen 1.8.8