Proton  1.1.1
Make porting easy from Python to C++11
ref_

Core reference template supporting interface through inheritance/multiple inheritance. More...

Classes

struct  proton::ref_< objT, allocator >
 The core reference support template. More...
struct  proton::key_hash< T >
 general key_hash for refs. More...
struct  proton::subkey_hash< T, key_seq >
 general subkey_hash for refs. More...

Macros

#define PROTON_COPY_DECL(type)
 declare copy_to().
#define PROTON_COPY_DECL_NV(type)
 declare copy_to() without virtual.
#define PROTON_KEY_DECL(type)
 general operator< & operator== for objects.

Functions

template<typename refT >
bool proton::is_null (const refT &x)
 test a ref null or not.
template<typename refT >
bool proton::is_valid (const refT &x)
 test a ref valid or not.
template<typename refT >
refT proton::copy (const refT &x)
 Generate a copy of object.
template<typename refT >
void proton::reset (refT &x)
 reset a ref to release its object if any.
template<typename refT >
long proton::ref_count (const refT &x)
 get the reference count of the object.
template<typename T , typename refT >
proton::cast (const refT &x)
 cast from a ref type to another.
template<typename T >
std::ostream & proton::operator<< (typename T::proton_ostream_t &s, const T &y)
 general output for refs.

Variables

init_alloc proton::alloc
 explicitly demand to initialize an object.

Detailed Description

Core reference template supporting interface through inheritance/multiple inheritance.


Macro Definition Documentation

#define PROTON_COPY_DECL (   type)

declare copy_to().

For object classes which need to support copy().

Definition at line 101 of file ref.hpp.

#define PROTON_COPY_DECL_NV (   type)

declare copy_to() without virtual.

For object classes which need to support copy(), without inheritance.

Definition at line 110 of file ref.hpp.

#define PROTON_KEY_DECL (   type)

general operator< & operator== for objects.

Need obj_t to implenment: T1 key()const, and T1 should be comparable. Don't forget virtual when needed. [TODO] need an example.

Definition at line 571 of file ref.hpp.


Function Documentation

template<typename T , typename refT >
T proton::cast ( const refT &  x)

cast from a ref type to another.

if casting fails, throw std::bad_cast().

Parameters:
xthe original ref
Returns:
the casted one

Definition at line 160 of file ref.hpp.

References proton::is_null().

template<typename refT >
refT proton::copy ( const refT &  x)

Generate a copy of object.

Note: the alloc_t of refT must support duplicate() like smart_allocator.

Parameters:
xa ref to an obj supporting the method: void copy_to(void* new_addr)const. You can use PROTON_COPY_DECL() or PROTON_COPY_DECL_NV() to declare copy_to() in the obj class.
Returns:
a cloned obj of x

Definition at line 123 of file ref.hpp.

References proton::is_null().

template<typename refT >
bool proton::is_null ( const refT &  x)

test a ref null or not.

Parameters:
xthe ref to be checked
Returns:
true: x doesn't refer to any object, false: x refers to an object.

Definition at line 84 of file ref.hpp.

Referenced by proton::cast(), proton::copy(), proton::ref_< objT, allocator >::operator()(), proton::ref_< objT, allocator >::operator<(), proton::operator<<(), proton::ref_< objT, allocator >::operator==(), and proton::ref_< objT, allocator >::operator[]().

template<typename refT >
bool proton::is_valid ( const refT &  x)

test a ref valid or not.

Parameters:
xthe ref to be checked
Returns:
true: x refers to an object, false: x doesn't refer to any object.

Definition at line 93 of file ref.hpp.

template<typename T >
std::ostream& proton::operator<< ( typename T::proton_ostream_t &  s,
const T &  y 
)

general output for refs.

Need T::obj_t to implenment the method: void output(std::ostream& s)const. Don't forget virtual when needed.

Definition at line 555 of file ref.hpp.

References proton::is_null().

template<typename refT >
long proton::ref_count ( const refT &  x)

get the reference count of the object.

Parameters:
xrefers to the object
Returns:
the reference count.

Definition at line 147 of file ref.hpp.

template<typename refT >
void proton::reset ( refT &  x)

reset a ref to release its object if any.

Parameters:
xthe ref to be resetted.

Definition at line 138 of file ref.hpp.