Mirror reflection library 0.5.13

mirror::some Class Reference

A type erasure similar to Boost.Any with optional reference semantics. More...

#include <mirror/utils/some_type.hpp>

List of all members.

Public Member Functions

 some (void)
 Constructs an empty standalone instance without any value.
template<typename T >
 some (T value, std::false_type=std::false_type())
 Constructs a new instance containing the passed value.
template<typename T >
 some (T &inst, std::true_type by_ptr)
 Constructs a new instance referring to the passed inst.
template<typename T >
 some (const T &inst, std::true_type by_ptr)
 Constructs a new instance referring to the passed inst.
bool empty (void) const
 Tests if this instance of some is empty.
bool standalone (void) const
 Tests if this instance is standalone or it refers to something.
somedetach (void)
 Function that detaches this from the external instace by doing a copy.
bool is_const (void) const
 Returns true if the the value referred-to by this instance is const.
bool is_reference (void) const
 Returns true if this is a non-constant reference to an external value.
bool is_value (void) const
 Returns true if this owns its value or refers to a const instance.
template<typename T >
bool is (void) const
 Testing if this stores or refers to a value of a certain type.
template<typename T >
as (const some &s) const
 Function for getting the stored or referred-to value.

Friends

template<typename T >
T or T & some_cast (some &s)
 Operator for casting to the stored type.
template<typename T >
some_cast (const some &s)
 Operator for casting to the stored type.

Detailed Description

A type erasure similar to Boost.Any with optional reference semantics.

The some class is a type erasure which can store values or references to values of other types. The instances of some can be either standalone in cases when they contain the value, or they can refer to external instances. In case an instance of some refers to another instance, this instance must be kept alive during the lifetime of the type erased some instance or it must be detached before the lifetime of the instance referred-to ends.

See also:
some::empty()
some::standalone()
some::detach()

Constructor & Destructor Documentation

mirror::some::some ( void  ) [inline]

Constructs an empty standalone instance without any value.

The some_cast and as function must not be called on empty instances of some.

See also:
empty
standalone
template<typename T >
mirror::some::some ( value,
std::false_type  = std::false_type() 
) [inline]

Constructs a new instance containing the passed value.

This constructor creates a new standalone instance which contains the value passed as parameter.

See also:
empty
standalone
is_value
is_reference
template<typename T >
mirror::some::some ( T &  inst,
std::true_type  by_ptr 
) [inline]

Constructs a new instance referring to the passed inst.

This constructor creates a new instance attached (referring) to the value referred to by the inst reference. The instance referred-to must be kept alive the whole time the newly constructed instance of some is used or this instance must be detached from the instance it refers to.

See also:
empty
standalone
is_const
is_reference
detach
template<typename T >
mirror::some::some ( const T &  inst,
std::true_type  by_ptr 
) [inline]

Constructs a new instance referring to the passed inst.

This constructor creates a new instance attached (referring) to the value referred-to by the inst reference. The instance referred-to must be kept alive the whole time the newly constructed instance of some is used or this instance must be detached from the instance it refers to.

See also:
empty
standalone
is_const
is_reference
detach

Member Function Documentation

template<typename T >
T mirror::some::as ( const some s) const

Function for getting the stored or referred-to value.

This member function can be use to get read-only access to the value stored inside or refered-to by this instance of some. You don't need to use the const specifier on the template parameter in contrast to the some_cast operator.

See also:
empty
is
detach
as
some& mirror::some::detach ( void  ) [inline]

Function that detaches this from the external instace by doing a copy.

If this instance is not standalone, then the detach member function will make a copy of the external instance referred-to by this instance and store the copy. If this instance already is standalone then detach does not do anything.

See also:
standalone
bool mirror::some::empty ( void  ) const

Tests if this instance of some is empty.

The some_cast and as member functions must not be used on empty instances.

See also:
some_cast
as
template<typename T >
bool mirror::some::is ( void  ) const [inline]

Testing if this stores or refers to a value of a certain type.

This member function can be used to test if this instance of some owns and stores or refers to an external instance of the T type.

See also:
empty
as
some_cast
bool mirror::some::is_const ( void  ) const [inline]

Returns true if the the value referred-to by this instance is const.

This member function returns true, if the value referred-to by this instance is const. If true then the some_cast should be done only with const T.

See also:
some_cast
as
detach
bool mirror::some::is_reference ( void  ) const [inline]

Returns true if this is a non-constant reference to an external value.

This function can be used for testing if this instance of refers to some non-const external instance which can be modified via this. If this owns its value or it refers to a const value it returns false.

See also:
is_value
is_const
empty
standalone
detach
some_cast
bool mirror::some::is_value ( void  ) const [inline]

Returns true if this owns its value or refers to a const instance.

This function can be used for testing if this instance owns its value or it refers to an external instance via a const reference. If this member function returns true, then it is necessary to test for constness with the is_const member function before requesting non-const access (for assignement, calling non-const member functions, etc). If only read-only access is desired then the some_cast should be used with const type or the as member function should be used.

See also:
is_value
is_const
empty
standalone
detach
some_cast
as
bool mirror::some::standalone ( void  ) const [inline]

Tests if this instance is standalone or it refers to something.

If this instance of some contains and owns its value then standalone returns true otherwise, if it refers to an external instance it returns false. Instances which are not standalone can be made standalone by calling the detach member function. This member function is the right one to test if this refers to something, since is_value and is_reference member functions are for other purposes.

See also:
detach
is_value
is_reference

Friends And Related Function Documentation

template<typename T >
T or T& some_cast ( some s) [friend]

Operator for casting to the stored type.

This function can be use to get read-only or read-write access to the value stored inside or refered to by this instance of some. To get read-only access use const Type as the template parameter to get read-write reference to the value use a non-const type. Before trying to get access for writing test for constness with the is_const member function.

See also:
empty
is
is_const
detach
as
template<typename T >
T some_cast ( const some s) [friend]

Operator for casting to the stored type.

This function can be use to get read-only access to the value stored inside or refered to by this instance of some. To get read-only access use const Type as the template parameter.

See also:
empty
is
detach
as

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

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.