MPQC
3.0.0-alpha
|
A template class that maintains references counts. More...
#include <util/ref/ref.h>
Public Types | |
typedef T | element_type |
Public Member Functions | |
Ref () | |
Create a reference to a null object. | |
Ref (T *a) | |
Create a reference to the object a. | |
Ref (const Ref< T > &a) | |
Create a reference to the object referred to by a. | |
template<class A > | |
Ref (const Ref< A > &a) | |
Create a reference to the object referred to by a. | |
~Ref () | |
Create a reference to the object a. More... | |
T * | operator-> () const |
Returns the reference counted object. More... | |
T * | pointer () const |
Returns a pointer the reference counted object. | |
RefCount * | parentpointer () const |
Implements the parentpointer pure virtual in the base class. | |
operator T* () const | |
T & | operator* () const |
Returns a C++ reference to the reference counted object. More... | |
bool | null () const |
Return true if this is a reference to a null object. More... | |
bool | operator! () const |
template<class A > | |
int | operator== (const Ref< A > &a) const |
Ordering and equivalence operators are determined by the identifier if both pointers are not null. More... | |
template<class A > | |
int | operator>= (const Ref< A > &a) const |
template<class A > | |
int | operator<= (const Ref< A > &a) const |
template<class A > | |
int | operator> (const Ref< A > &a) const |
template<class A > | |
int | operator< (const Ref< A > &a) const |
template<class A > | |
int | operator!= (const Ref< A > &a) const |
int | compare (const Ref< T > &a) const |
Compare two objects returning -1, 0, or 1. More... | |
void | clear () |
Refer to the null object. | |
Ref< T > & | operator= (const Ref< T > &c) |
Assignment to c. | |
template<class A > | |
Ref< T > & | operator= (const Ref< A > &c) |
Assignment to c. | |
Ref< T > & | operator<< (const RefBase &a) |
Assignment to the object that a references using dynamic_cast. | |
Ref< T > & | operator<< (RefCount *a) |
Assigns to the given base class pointer using dynamic_cast. More... | |
Ref< T > & | operator= (T *cr) |
Assignment to cr. | |
void | assign_pointer (T *cr) |
Assignment to cr. | |
void | check_pointer () const |
Check the validity of the pointer. | |
void | ref_info (std::ostream &os) const |
Print information about the reference to os. | |
void | warn (const char *s) const |
Print a warning concerning the reference. | |
bool | nonnull () const |
Return !null(). | |
Public Member Functions inherited from sc::RefBase | |
void | require_nonnull () const |
Requires that a nonnull reference is held. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from sc::RefBase | |
void | warn (const char *msg) const |
Print a warning message. | |
void | warn_ref_to_stack () const |
Called when stack data is referenced. | |
void | warn_skip_stack_delete () const |
Called when the deletion of stack data is skipped. | |
void | warn_bad_ref_count () const |
Called when the reference count is corrupted. | |
void | ref_info (RefCount *p, std::ostream &os) const |
Print information about the reference. | |
void | ref_info (std::ostream &os) const |
void | check_pointer () const |
void | reference (RefCount *) |
int | dereference (RefCount *) |
A template class that maintains references counts.
Several of these operations can cause a reference to an object to be replaced by a reference to a different object. If a reference to a nonnull object is eliminated, the object's reference count is decremented and the object is deleted if the reference count becomes zero.
There also may be a to convert to T*, where T is the type of the object which Ref references. Some compilers have bugs that prevent the use of operator T*(). The pointer() member should be used instead.
Create a reference to the object a.
Do a dynamic_cast to convert a to the appropiate type. / Ref(const RefBase&a) { p = dynamic_cast<T>(a.parentpointer()); reference(p); } /** Create a reference to the object a. Do a dynamic_cast to convert a to the appropiate type. */ Ref(RefCount*a): p(0) { operator<<(a); } /** Delete this reference to the object. Decrement the object's reference count and delete the object if the count is zero.
Compare two objects returning -1, 0, or 1.
Similar to the C library routine strcmp.
|
inline |
Return true if this is a reference to a null object.
Otherwise return false.
Referenced by sc::R12IntEval::contract_tbint_tensors_to_obtensor(), and sc::sma2::Array< 6 >::n_element_allocated().
|
inline |
Returns a C++ reference to the reference counted object.
The behaviour is undefined if the object is null.
|
inline |
Returns the reference counted object.
Will abort if object is null.
Assigns to the given base class pointer using dynamic_cast.
If the dynamic_cast fails and the argument is nonnull and has a reference count of zero, then it is deleted.
|
inline |
Ordering and equivalence operators are determined by the identifier if both pointers are not null.
If one or both of the pointers is null then we compare the pointers.