Loading...
Searching...
No Matches
OFoptional_traits< T > Struct Template Reference

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

## Public Member Functions

| OFoptional_traits ()
| Required: default constructor, must initialize the state to "disengaged".
void | construct (...)
| Required: type constructors, construct the contained object.
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 otherwise.
void * | content () const
| Required: content access, must return a pointer to the contained object.

## Public Attributes

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

## 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

  the | content 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;
OFoptional_traits
Manages storage and state of the object contained in OFoptional<T>.
Definition ofoption.h:244
OFoptional_traits::content
void * content() const
Required: content access, must return a pointer to the contained object.
OFoptional_traits::destroy
void destroy()
Required: type destructor, destroys the underlying object and must set the state to "disengaged".
OFoptional_traits::OFoptional_traits
OFoptional_traits()
Required: default constructor, must initialize the state to "disengaged".
OFoptional_traits::state
OFBool state() const
Required: state query, must return OFTrue when "engaged" and OFFalse otherwise.
OFoptional_traits::is_default_constructible
< unspecified > is_default_constructible
Required: default construction policy.
Definition ofoption.h:252
OFoptional_traits::construct
void construct(...)
Required: type constructors, construct the contained object.

## 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:

- ofstd/include/dcmtk/ofstd/ofoption.h

Generated on for DCMTK Version 3.7.0 by Doxygen 1.15.0