DCMTK  Version 3.6.5
OFFIS DICOM Toolkit
Public Member Functions | Public Attributes | List of all members
OFoptional_traits< T > Struct Template Reference

Manages storage and state of the object contained in OFoptional<T>. More...

Public Member Functions

 OFoptional_traits ()
 Requried: default constructor, must initialize the state to "disengaged".
 
void construct (...)
 Required: type constructors, construct the contained object. More...
 
void destroy ()
 Required: type destructor, destroys the underlying object and must set the state to "disengaged".
 
OFBool state () const
 Required: state query, must return OFTrue when "engaged" and OFFalse otherwhise.
 
void * content () const
 Required: content access, must return a pointer to the contained object.
 

Public Attributes

< unspecified > is_default_constructible
 Required: default construction policy. More...
 

Detailed Description

template<typename T>
struct OFoptional_traits< T >

Manages storage and state of the object contained in OFoptional<T>.

OFoptional_traits is a customization point for OFoptional that enables you to define a custom storage management policy for individual types T. If you don't want to implement everything from scratch, use OFdefault_optional_traits as base class for your implementation.

Template Parameters
thecontent type of the respective OFoptional instance.
See also
OFoptional
OFdefault_optional_traits

Example

The following example shows how to implement custom OFoptional_traits for an enum that already contains a specific element to denote an invalid state.

enum FILE_ACCESS
{
NONE = 0000,
READ = 0400,
WRITE = 0200,
. . .
INVALID_ACCESS_CODE = 01000
};
template<>
struct OFoptional_traits<FILE_ACCESS>
{
// Tell OFoptional that this is default-constructible
typedef OFtrue_type is_default_constructible;
// Initialize storage to the invalid state during construction
OFoptional_traits() : access( INVALID_ACCESS_CODE ) {}
// Constructors
void construct() { access = NONE; }
void construct( FILE_ACCESS fa ) { access = fa; }
// There is nothing to destroy, just set the state to "disengaged"
void destroy() { access = INVALID_ACCESS_CODE; }
// Tell OFoptional how to distinguish "engaged" and "disengaged" FILE_ACCESS objects
OFBool state() const { return access != INVALID_ACCESS_CODE; }
// Just return a pointer to the underlying object
void* content() const { return &access; }
// The actual object
mutable FILE_ACCESS access;
};
COUT << "This should now be the same: " << sizeof( FILE_ACCESS ) << ' ' << sizeof( OFoptional<FILE_ACCESS> ) << OFendl;

Member Function Documentation

◆ construct()

template<typename T >
void OFoptional_traits< T >::construct (   ...)

Required: type constructors, construct the contained object.

You need to define at least one method of this kind, that takes appropriate parameter(s) to construct the underlying object. Must set the state to "engaged". If is_default_constructible evaluates to OFTrue, an overload taking zero arguments is also required.

Member Data Documentation

◆ is_default_constructible

template<typename T >
<unspecified> OFoptional_traits< T >::is_default_constructible

Required: default construction policy.

You need to define an appropriate integral constant as "is_default_constructible" that denotes if OFoptional<T> may attempt to default construct the underlying object under certain circumstances. You may use OFdefault_optional_traits<T>::is_default_constructible to specify this member, which uses SFINAE mechanisms to query a type's default constructibility.


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


Generated on Mon Oct 28 2019 for DCMTK Version 3.6.5 by Doxygen 1.8.15