SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Encapsulates an object of an arbitrary type. More...

#include <rw/any.h>

Public Member Functions

 RWAny ()
 
 RWAny (const RWAny &ref)
 
template<class T >
 RWAny (const T &ref)
 
 RWAny (RWAny &&ref)
 
template<class T >
T * address ()
 
template<class T >
const T * address () const
 
template<class T >
T & get ()
 
template<class T >
const T & get () const
 
RWAnyoperator= (const RWAny &ref)
 
template<typename T >
RWAnyoperator= (const T &ref)
 
RWAnyoperator= (RWAny &&ref)
 
RWAnyswap (RWAny &ref)
 
const std::type_info * type () const
 

Detailed Description

RWAny encapsulates an object of an arbitrary type; it can:

  • store objects of arbitrary types (by value or by pointer)
  • retrieve the original object in a "type-safe" manner
  • swap the object with another RWAny
  • assign objects of type RWAny

Requirements for types held by RWAny are:

  • the type must be complete
  • the type must be copy constructible
  • the type must be assignable
Synopsis
#include <rw/any.h>
Encapsulates an object of an arbitrary type.
Definition any.h:49
Persistence
None

Constructor & Destructor Documentation

◆ RWAny() [1/4]

RWAny::RWAny ( )
inline

Default constructor. Creates an empty object. Post-condition: for any T, (address<T>() == 0).

◆ RWAny() [2/4]

template<class T >
RWAny::RWAny ( const T & ref)
inline

Template constructor for type any holding T. Creates RWAny object holding a copy of argument ref.

◆ RWAny() [3/4]

RWAny::RWAny ( const RWAny & ref)
inline

Copy constructor. Creates a copy of ref.

◆ RWAny() [4/4]

RWAny::RWAny ( RWAny && ref)
inline

Move constructor. The constructed instance takes ownership of the data owned by ref.

Condition:
This method is available only on platforms with rvalue reference support.

Member Function Documentation

◆ address() [1/2]

template<class T >
T * RWAny::address ( )
inline

Implements address retrieval. Returns the address of the object held in any or 0 if the object is not of the type requested.

◆ address() [2/2]

template<class T >
const T * RWAny::address ( ) const
inline

Implements address retrieval. Returns the address of the object held in any or 0 if the object is not of the type requested.

◆ get() [1/2]

template<class T >
T & RWAny::get ( )
inline

Implements value retrieval. Returns *address<T>() if T is the type of the object stored in self, or throws an exception of type (or a type derived from) std::bad_cast otherwise.

◆ get() [2/2]

template<class T >
const T & RWAny::get ( ) const
inline

Implements value retrieval. Returns *address<T>() if T is the type of the object stored in self, or throws an exception of type (or a type derived from) std::bad_cast otherwise.

◆ operator=() [1/3]

RWAny & RWAny::operator= ( const RWAny & ref)
inline

Assignment operator. Deep-copies ref. Returns a reference to self.

◆ operator=() [2/3]

template<typename T >
RWAny & RWAny::operator= ( const T & ref)
inline

Template assignment operator for type any holding T. Assigns self to hold copy of argument ref.

◆ operator=() [3/3]

RWAny & RWAny::operator= ( RWAny && ref)
inline

Move assignment. Self takes ownership of the data owned by ref.

Condition:
This method is available only on platforms with rvalue reference support.

◆ swap()

RWAny & RWAny::swap ( RWAny & ref)
inline

Implements a swap operation. After the swap, this object contains the old content of the argument and vice versa.

◆ type()

const std::type_info * RWAny::type ( ) const
inline

Implements type retrieval. Returns &typeid (T) if any holds an object of type T, or 0 otherwise.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.