Many modern C APIs have reference-counted classes, which also have a copy function. In order to get a more natural C++ idiom, we wrap these reference-counted classes into value types, and let refptr represent the reference type interface. Thus, copying the value type does a real copy, whereas copying the refptr only increments the refcount. The refptr then calls into private constructors which are all tagged with impl::retain_tag.
The comparison operators simply reuse the equivalents on the value type.
The following types use refptr: macstl::core_array.
| T | The value type, which should have the following constructors:
|
Public Types | |
| typedef T::data_type | data_type |
| The raw data type. | |
| typedef T | element_type |
| The value type. | |
Public Member Functions | |
| element_type * | get () const |
| Gets a pointer to the element type. | |
| element_type & | operator * () const |
| Gets a reference to the element type. | |
| element_type * | operator-> () const |
| Gets a pointer to the element type. | |
| template<typename T2> | |
| refptr & | operator= (const refptr< T2 > &other) |
| Assigns the different type other. | |
| refptr & | operator= (const refptr &other) |
| Assigns the other. | |
| template<typename T2> | |
| refptr (const refptr< T2 > &other) | |
| Copies the different type other. | |
| refptr (refptr &other) | |
| Copies the other. | |
| refptr (element_type *ptr) | |
| Constructs from an element ptr. | |
| refptr (data_type ptr=NULL) | |
| Constructs from a raw data ptr. | |
| template<typename T2> | |
| void | reset (T2 *ptr) |
| Resets the pointer to point to ptr. | |
| void | swap (refptr &other) |
| Swaps the pointer with other. | |
Related Functions | |
| (Note that these are not member functions.) | |
| bool | operator!= (const refptr< T1 > &lhs, const refptr< T2 > &rhs) |
| Tests whether the elements of lhs and rhs are not equal. | |
| bool | operator< (const refptr< T1 > &lhs, const refptr< T2 > &rhs) |
| Tests whether the elements of lhs and rhs are less than. | |
| bool | operator== (const refptr< T1 > &lhs, const refptr< T2 > &rhs) |
| Tests whether the elements of lhs and rhs are equal. | |
| void | swap (refptr< T > &lhs, refptr< T > &rhs) |
| Swaps the pointers of lhs and rhs. | |