20 #ifndef TENSOR_REFCOUNT_H
21 #define TENSOR_REFCOUNT_H
48 template<
class value_type>
78 const elt_t *
end()
const {
return ref_->end(); }
80 elt_t *
end() { appropriate();
return ref_->end(); }
83 size_t size()
const {
return ref_->size(); }
86 size_t ref_count()
const {
return ref_->references(); }
93 mutable pointer *ref_;
99 pointer *reference()
const;
106 shared_ptr(T *t) : _value(t), _ref(new int(1)) {}
107 ~shared_ptr() { --(*_ref);
if (!(*_ref)) {
delete _value;
delete _ref; }}
108 T* operator->()
const {
return _value; }
109 T& operator*()
const {
return *_value; }
117 #include <tensor/detail/refcount.hpp>
const elt_t * end_const() const
Retreive the pointer without caring for references (unsafe).
value_type elt_t
Type of data pointed to.
A reference counting pointer with copy-on-write.
RefPointer< elt_t > & operator=(const RefPointer< elt_t > &p)
Copy a pointer increasing the reference count.
elt_t * begin()
Retreive the pointer without caring for references (unsafe).
size_t size() const
Size of pointed-to data.
const elt_t * end() const
Retreive the pointer without caring for references (unsafe).
~RefPointer()
Destructor that deletes no longer reference data.
const elt_t * begin_const() const
Retreive the pointer without caring for references (unsafe).
elt_t * end()
Retreive the pointer without caring for references (unsafe).
void reallocate(size_t new_size)
Replace the pointer with newly allocated data.
size_t ref_count() const
Number of references to the internal data.
RefPointer()
Create an empty reference.
const elt_t * begin() const
Retreive the pointer without caring for references (unsafe).