DCMTK  Version 3.6.1 20170228
OFFIS DICOM Toolkit
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Macros | Functions
ofutil.h File Reference

Implement fallback support for modern techniques defined in the STL's <utility> header (e.g. move semantics) for older compilers. More...

Classes

struct  OFrvalue< T >
 A helper class to 'tag' objects as rvalues to help DCMTK's move emulation employed on pre C++11 compilers. More...
 
class  OFPair< K, V >
 a pair - this implements parts of std::pair's interface. More...
 

Macros

#define OFrvalue_ref(T)   unspecified
 Determines rvalue reference type for the type T. More...
 

Functions

template<typename T >
T & OFrvalue_access (OFrvalue_ref(T) rv)
 Obtain an lvalue reference from an rvalue reference. More...
 
template<typename T >
OFconstexpr xvalue OFmove (T< unspecified > t)
 Obtains an rvalue reference to its argument and converts it to an xvalue. More...
 
template<typename T >
void OFswap (T &t0, T &t1)
 Exchanges the given values. More...
 

Detailed Description

Implement fallback support for modern techniques defined in the STL's <utility> header (e.g. move semantics) for older compilers.

Macro Definition Documentation

#define OFrvalue_ref (   T)    unspecified

Determines rvalue reference type for the type T.

Parameters
Tthe base type to determine the rvalue reference type for.
Note
OFrvalue_ref(T) will expand to T&& when C++11 support is available. Otherwise DCMTK's move emulation will be used, employing an unspecified type to implement rvalue references.

Example

This example shows how to implement the move constructor and move assignment for a custom class in a portable fashion (employing C++11's native features when available and using DCMTK's move emulation otherwise).

1 class MyMovable
2 {
3 public:
4  MyMovable( OFrvalue_ref(MyMovable) rhs )
5  : m_hDatabase( rhs.m_hDatabase )
6  {
7  // You need to use OFrvalue_access to get write access
8  // to rvalue references when DCMTK's move emulation
9  // is used.
10  OFrvalue_access(rhs).m_hDatabase = OFnullptr;
11  }
12 
13  MyMovable& operator=( OFrvalue_ref(MyMovable) rvrhs )
14  {
15  // You may bind the rvalue reference to an lvalue
16  // reference to ease access.
17  MyMovable& rhs = OFrvalue_access(rvrhs);
18  if( this != &rhs )
19  {
20  disconnectDatabase( m_hDatabase );
21  m_hDatabase = rhs.m_hDatabase;
22  rhs.m_hDatabase = OFnullptr;
23  }
24  return *this;
25  }
26 };

Function Documentation

template<typename T >
OFconstexpr xvalue OFmove ( T< unspecified >  t)

Obtains an rvalue reference to its argument and converts it to an xvalue.

OFmove is meant to 'mark' an object for a move operation, e.g. to move an OFVector object into another OFVector instance instead of copying it.

Note
OFmove will be an alias for std::move when native move semantics are supported (C++11 support is available). Otherwise DCMTK's move emulation will be used. This means you will have to specify rvalues (e.g. function return values) employing the OFrvalue class template.
Parameters
tThe object to move.
See also
OFrvalue
OFrvalue_ref
template<typename T >
T& OFrvalue_access ( OFrvalue_ref(T)  rv)

Obtain an lvalue reference from an rvalue reference.

DCMTK's move emulations does restrict write access to rvalue references due to compiler limitations. This method enables you to workaround this restriction by converting DCMTK's emulated rvalue references to lvalue references.

Note
Native rvalue references from C++11 don't need this workaround, therefore OFrvalue_access has no effect when C++11 support is available.
Parameters
rvan rvalue reference, e.g. the parameter of a move constructor.
template<typename T >
void OFswap ( T &  t0,
T &  t1 
)

Exchanges the given values.

OFswap is an alias for std::swap if C++11 is supported. Otherwise OFswap simply creates a temporary copy of one argument to exchange both values.

Note
As intended for std::swap, there are some specializations for OFswap available, e.g. for OFoptional, which specializes OFswap to exchange optional objects more efficiently. When creating your own specializations for OFswap, make sure to specialize std::swap instead when C++11 support is available.
Parameters
t0An object to be exchanged.
t1The object to be exchanged with t0.

Referenced by DSRTree< T >::swap().


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