Similar to lkptr<>
, but points to an array instead of a single object.
More...
#include <lkptr.h>
List of all members.
Detailed Description
template<typename X>
class array_lkptr< X >
Similar to lkptr<>
, but points to an array instead of a single object.
Definition at line 727 of file lkptr.h.
Member Typedef Documentation
Standard name for the pointed object.
Definition at line 732 of file lkptr.h.
Standard name for the pointed object.
Definition at line 733 of file lkptr.h.
Standard name for the pointer to the object.
Definition at line 734 of file lkptr.h.
Constructor & Destructor Documentation
Default constructor and constructor from a regular pointer.
.
Definition at line 742 of file lkptr.h.
template<typename X>
template<typename Y >
Constructor from a pointer to a derived class.
- Check that the pointer is not null when types are not compatible.
- Make sure the destructor for the base class is virtual.
.
Definition at line 746 of file lkptr.h.
Copy constructor: share the object with other pointers.
.
Definition at line 749 of file lkptr.h.
template<typename X>
template<typename Y >
Copy constructor from a derived clase: share the object with other pointers.
- Check that the pointer is not null when types are not compatible.
- Make sure the destructor for the base class is virtual.
.
Definition at line 753 of file lkptr.h.
Destructor.
Definition at line 755 of file lkptr.h.
Member Function Documentation
Copy operator: share the object with other pointers.
Definition at line 765 of file lkptr.h.
template<typename X>
template<typename Y >
Copy operator from a derived clase: share the object with other pointers.
- Will not copy when types are not compatible.
- Make sure the destructor for the base class is virtual.
Definition at line 801 of file lkptr.h.
Swaps with r
.
Definition at line 917 of file lkptr.h.
Returns a pointer to referenced object.
.
Definition at line 811 of file lkptr.h.
Returns the referenced object.
.
Definition at line 812 of file lkptr.h.
template<typename X>
X& array_lkptr< X >::operator* |
( |
| ) |
const throw () [inline] |
Returns the referenced object.
.
Definition at line 813 of file lkptr.h.
template<typename X>
X* array_lkptr< X >::operator-> |
( |
| ) |
const throw () [inline] |
Returns a pointer to referenced object.
.
Definition at line 814 of file lkptr.h.
template<typename X>
bool array_lkptr< X >::isNull |
( |
| ) |
const throw () [inline] |
Returns true
if the object pointed is null and false
otherwise.
.
Definition at line 817 of file lkptr.h.
template<typename X>
bool array_lkptr< X >::unique |
( |
| ) |
const throw () [inline] |
Return "true"
when only one pointer references the object.
.
Definition at line 818 of file lkptr.h.
template<typename X>
int array_lkptr< X >::use_count |
( |
| ) |
const throw () [inline] |
Returns how many pointers are sharing the object referenced by "this"
.
.
Definition at line 819 of file lkptr.h.
Releases the object.
- Before: If this was the last reference, it also deletes the referenced object.
- After: The pointer becomes
NULL
.
- After: Equivalent to
reset(0)
.
Definition at line 825 of file lkptr.h.
Resets the pointer so that it will point to "p"
.
- Before: If this was the last reference, it also deletes the referenced object.
- Before:
"p==0"
is a valid argument (NULL
is ok).
- After: The object pointed by
"p"
gets to be own by "this"
.
- [DANGER]
V.reset( r.get() )
almost always is an error because both V
and r
will destroy the referenced object. Use V = r
. struct Point { virtual int val() const { return 0; } };
struct Circle : public Point { virtual int val() const { return 1; } };
struct Cilinder : public Circle { virtual int val() const { return 2; } };
struct Square : public Point { virtual int val() const { return 3; } };
struct Rectangle : public Square { virtual int val() const { return 4; } };
{{
lkptr<Point> VEC[5];
VEC[0].reset( new Point() );
VEC[1].reset( new Circle() );
VEC[2].reset( new Cilinder() );
VEC[3].reset( new Square() );
VEC[4].reset( new Rectangle() );
for (int i=0; i<int(DIM(VEC)); ++i) {
assertTrue( VEC[i]->val() == i );
assertTrue( VEC[i].ok() );
}
}}
Definition at line 850 of file lkptr.h.
(*this) = r
.
Definition at line 861 of file lkptr.h.
template<typename X>
template<typename Y >
(*this) = r
[ from a derived class ].
Definition at line 891 of file lkptr.h.
Verifies the invariant for class lkptr<X>
.
- Returns
"true"
when "p"
contains a correct value.
- It could return
"true"
even when it's value is corrupted.
- it could never return if the value in
"p"
is corrupted.
- Rep: Description with words.
- Field
"ptr"
is the pointer to the referenced object.
- All pointers that point to the same object are linked together.
- The list is double linked to allow for O(1) insertion and removal.
- There is no "first" or "last" element in the list. What it is important is to be "in" the list, not which position in it a particular
lkptr<X>
occupies.
- Rep: Class diagram.
<=================================> <=============>
| p1 p2 p3 | | p4 |
| +-+-+ +-+-+ +-+-+ | | +-+-+ |
<===>|*|*|<===>|*|*|<===>|*|*|<===> <===>|*|*|<===>
+-+-+ +-+-+ +-+-+ +-+-+
| * | | * | | * | | * |
+-|-+ +-|-+ +-|-+ +-|-+
| | | |
\|/ \|/ \|/ \|/
+----------------------+ +----------------------+
| Shared object | | Lonely Object |
+----------------------+ +----------------------+
+--------+-------+ "ptr" points to the object
| prev | |
+--------+ ptr +
| next | | "next" is next in chain
+--------+-------+ "prev" is previous in chain
- The invariant: Description with words.
.
Definition at line 900 of file lkptr.h.
Friends And Related Function Documentation
Test array_lkptr<X>
.
Definition at line 904 of file lkptr.h.
template<typename X>
template<typename Y >
bool check_ok |
( |
const array_lkptr< Y > & |
p | ) |
throw () [friend] |
Member Data Documentation
Contains the 3 pointers for the array_lkptr<>
.
Definition at line 728 of file lkptr.h.
The documentation for this class was generated from the following file: