43#ifndef TEUCHOS_ARRAY_RCP_DECL_HPP
44#define TEUCHOS_ARRAY_RCP_DECL_HPP
48#include "Teuchos_Exceptions.hpp"
49#include "Teuchos_ArrayViewDecl.hpp"
165#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
193 inline ArrayRCP( ENull null_arg = null );
241 template<
class Dealloc_T>
353 inline T*
get()
const;
592 inline void assign(Iter first, Iter last);
790 inline void debug_assert_not_null ()
const {
791#ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
797 debug_assert_in_range (
size_type lowerOffset_in,
800 (void) lowerOffset_in;
802#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
807 inline void debug_assert_valid_ptr()
const {
815#ifndef DOXYGEN_COMPILE
821 const RCPNodeHandle& node );
822 T* access_private_ptr()
const;
823 RCPNodeHandle& nonconst_access_private_node();
824 const RCPNodeHandle& access_private_node()
const;
840 typedef Teuchos_Ordinal
Ordinal;
852#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
860 inline ArrayRCP (ENull null_arg = null);
864 template<
class Dealloc_T>
867 inline explicit ArrayRCP (size_type
size,
const T& val = T ());
875 inline const T*
get()
const;
877 inline const T&
operator[] (size_type offset)
const;
888 inline iterator
begin()
const;
889 inline iterator
end()
const;
901 inline size_type
size()
const;
907 inline void resize (
const size_type n,
const T& val = T ());
908 inline void clear ();
931 size_type lowerOffset_;
932 size_type upperOffset_;
934 inline void debug_assert_not_null()
const {
935#ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
941 debug_assert_in_range (
size_type lowerOffset_in,
944 (void) lowerOffset_in; (void) size_in;
945#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
950 inline void debug_assert_valid_ptr()
const {
958#ifndef DOXYGEN_COMPILE
965 const T* access_private_ptr()
const;
966 RCPNodeHandle& nonconst_access_private_node();
967 const RCPNodeHandle& access_private_node()
const;
983 typedef Teuchos_Ordinal
Ordinal;
1008 typedef Teuchos_Ordinal
Ordinal;
1052 bool owns_mem =
true
1061template<
class T,
class Dealloc_T>
1066 Dealloc_T dealloc,
bool owns_mem
1119template<
class T,
class Embedded>
1125 const Embedded &embedded,
1126 bool owns_mem =
true
1140template<
class T,
class Embedded>
1146 const Embedded &embedded,
1147 bool owns_mem =
true
1162template<
class T,
class Embedded>
1168 const Embedded &embedded,
1169 bool owns_mem =
true
1260template<
class T1,
class T2>
1268template<
class T1,
class T2>
1276template<
class T1,
class T2>
1284template<
class T1,
class T2>
1292template<
class T1,
class T2>
1300template<
class T1,
class T2>
1326template<
class T2,
class T1>
1342template<
class T2,
class T1>
1362template<
class T2,
class T1>
1391template<
class T2,
class T1>
1454template<
class T1,
class T2>
1456 const T1 &extra_data,
const std::string& name,
1458 bool force_unique =
true );
1480template<
class T1,
class T2>
1509template<
class T1,
class T2>
1537template<
class T1,
class T2>
1570template<
class T1,
class T2>
1584template<
class Dealloc_T,
class T>
1605template<
class Dealloc_T,
class T>
1623template<
class Dealloc_T,
class T>
1648template<
class Dealloc_T,
class T>
1658template<
class TOrig,
class Embedded,
class T>
1668template<
class TOrig,
class Embedded,
class T>
Reference-counted pointer class and non-member templated function implementations.
ArrayRCP< const T > getConst() const
Return const reference to the array.
ArrayRCP()
Default constructor; thows an exception.
Reference-counted smart pointer for managing arrays.
T1 * get_optional_extra_data(ArrayRCP< T2 > &p, const std::string &name)
Get a pointer to non-const extra data (if it exists) associated with a ArrayRCP object.
ArrayRCP< T > create_weak() const
Create a new weak reference from another (strong) reference.
T & reference
Type of a (nonconstant) reference to an array element.
Embedded & getNonconstEmbeddedObj(const ArrayRCP< T > &p)
Get a const reference to an embedded object that was set by calling arcpWithEmbeddedObjPreDestroy(),...
ArrayRCP< T > arcpWithEmbeddedObjPostDestroy(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, const Embedded &embedded, bool owns_mem=true)
Create an ArrayRCP with and also put in an embedded object.
void set_has_ownership()
Give this and other ArrayRCP<> objects ownership of the underlying referenced array to delete it.
T1 & get_extra_data(ArrayRCP< T2 > &p, const std::string &name)
Get a non-const reference to extra data associated with a ArrayRCP object.
size_type upperOffset() const
Return the upper offset to valid data.
ArrayRCP< T > & operator++()
Prefix increment of pointer (i.e. ++ptr).
const T & const_reference
Type of a (constant) reference to an array element.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
Ordinal difference_type
Type representing the difference between two size_type values.
ArrayRCP< T > arcp(typename ArrayRCP< T >::size_type size)
Allocate a new array just given a dimension.
std::random_access_iterator_tag iterator_category
Category of ArrayRCP's iterator type.
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to deallocate it.
bool operator!=(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare two ArrayRCP objects for inequality (by pointers).
Teuchos_Ordinal Ordinal
Integer index type used throughout ArrayRCP.
T * iterator
Nonconstant iterator type used if bounds checking is disabled.
ArrayRCP< T > arcpFromArrayView(const ArrayView< T > &av)
Get an ArrayRCP object out of an ArrayView object.
ArrayRCP< T > & operator+=(size_type offset)
Pointer integer increment (i.e. ptr+=offset).
ArrayRCP(ENull null_arg=null)
Default constructor; initialize to an empty array.
bool is_null() const
True if the underlying pointer is null, else false.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
ArrayRCP< const T > getConst() const
Return object for only const access to data.
const Dealloc_T * get_optional_dealloc(const ArrayRCP< T > &p)
Return a pointer to the underlying non-const deallocator object if it exists.
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
const Dealloc_T & get_dealloc(const ArrayRCP< T > &p)
Return a const reference to the underlying deallocator object.
T & operator*() const
Dereference the underlying object for the current pointer position.
const ArrayRCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
bool operator==(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare two ArrayRCP objects for equality (by pointers).
T * release()
Release the ownership of the underlying array.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
bool operator>=(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare the two ArrayRCP objects' pointers using >=.
void clear()
Resize to zero.
T value_type
Type of each array element.
T * get() const
Get the raw C++ pointer to the underlying object.
ArrayRCP< T2 > arcp_const_cast(const ArrayRCP< T1 > &p1)
Const cast of underlying ArrayRCP type from const T* to T*.
size_type size() const
The total number of entries in the array.
Dealloc_T * get_optional_nonconst_dealloc(const ArrayRCP< T > &p)
Return a pointer to the underlying const deallocator object if it exists.
T & operator[](size_type offset) const
Random object access.
ArrayRCP< T > create_strong() const
Create a new strong RCP object from another (weak) RCP object.
ArrayRCP< T > arcp(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, Dealloc_T dealloc, bool owns_mem)
Wraps a preallocated array of data and uses a templated deallocation strategy object to define deleti...
void deepCopy(const ArrayView< const T > &av)
Deep copy the elements from one ArrayView object into this object.
const T1 & get_extra_data(const ArrayRCP< T2 > &p, const std::string &name)
Get a const reference to extra data associated with a ArrayRCP object.
bool shares_resource(const ArrayRCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted object.
size_type lowerOffset() const
Return the lower offset to valid data.
ArrayRCP< T > operator-(size_type offset) const
Pointer integer decrement (i.e. ptr-offset).
ArrayRCP< T > arcpWithEmbeddedObj(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, const Embedded &embedded, bool owns_mem=true)
Create an ArrayRCP with and also put in an embedded object.
const T * const_iterator
Constant iterator type used if bounds checking is disabled.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
T element_type
Type of each array element.
bool operator<(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare the two ArrayRCP objects' pointers using <.
ArrayRCP< T > & operator--()
Prefix decrement of pointer (i.e. –ptr).
ArrayRCP< T > arcp(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, bool owns_mem=true)
Wraps a preallocated array of data with the assumption to call the array version of delete.
ArrayView< T > operator()() const
Return a nonpersisting view of *this.
ArrayView< T > view(size_type lowerOffset, size_type size) const
Return a nonpersisting view of a contiguous range of elements.
const ArrayRCP< T > & assert_in_range(size_type lowerOffset, size_type size) const
Throws NullReferenceError if this->get()==NULL orthis->get()!=NULL, throws RangeError if (lowerOffset...
std::ostream & operator<<(std::ostream &out, const ArrayRCP< T > &p)
Output stream inserter.
bool operator==(const ArrayRCP< T > &p, ENull)
Returns true if p.get()==NULL.
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
ArrayRCP< T > persistingView(size_type lowerOffset, size_type size) const
Return a persisting view of a contiguous range of elements.
bool is_valid_ptr() const
Return whether the underlying object pointer is still valid.
RCP< const std::vector< T > > get_std_vector(const ArrayRCP< const T > &ptr)
Get a const std::vector<T> object out of an ArrayRCP<const T> object that was created using the arcp(...
void resize(const size_type n, const T &val=T())
Resize and append new elements if necessary.
ArrayRCP< T > arcpCloneNode(const ArrayRCP< T > &a)
Allocate a new ArrayRCP object with a new RCPNode with memory pointing to the initial node.
ArrayRCP< T > & operator=(const ArrayRCP< T > &r_ptr)
Assignment operator: Makes *this reference the input array.
ArrayRCP< T > operator+(size_type offset) const
Pointer integer increment (i.e. ptr+offset).
ArrayRCP< T2 > arcp_reinterpret_cast_nonpod(const ArrayRCP< T1 > &p1, const T2 &val=T2())
Reinterpret cast of underlying ArrayRCP type from T1* to T2* where T2 is a non-POD (non-plain-old-dat...
T * iterator_type
Type of an ArrayRCP's iterator.
void assign(size_type n, const T &val)
Resize and assign n elements of val.
iterator begin() const
Return an iterator to beginning of the array of data.
T * operator->() const
Pointer (->) access to members of underlying object for current position.
~ArrayRCP()
Destructor, that decrements the reference count.
ERCPStrength strength() const
Strength of the pointer.
ArrayRCP< T > arcpClone(const ArrayView< const T > &v)
Allocate a new array by cloning data from an input array view.
Dealloc_T & get_nonconst_dealloc(const ArrayRCP< T > &p)
Return a non-const reference to the underlying deallocator object.
ArrayRCP< T >::difference_type operator-(const ArrayRCP< T > &p1, const ArrayRCP< T > &p2)
Return the difference of two ArrayRCP objects.
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.
T * pointer
Type of a (raw) (nonconstant) pointer to an array element.
iterator end() const
Return an iterator to past the end of the array of data.
RCP< std::vector< T > > get_std_vector(const ArrayRCP< T > &ptr)
Get an std::vector<T> object out of an ArrayRCP<T> object that was created using the arcp() function ...
bool operator>(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare the two ArrayRCP objects' pointers using >.
ArrayRCP< T2 > arcp_implicit_cast(const ArrayRCP< T1 > &p1)
Implicit case the underlying ArrayRCP type from T1* to T2*.
ArrayRCP< T > arcpWithEmbeddedObjPreDestroy(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, const Embedded &embedded, bool owns_mem=true)
Create an ArrayRCP with and also put in an embedded object.
T * const_pointer
Type of a (raw) (constant) pointer to an array element.
const ArrayRCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
const T1 * get_optional_extra_data(const ArrayRCP< T2 > &p, const std::string &name)
Get a pointer to const extra data (if it exists) associated with a ArrayRCP object.
ArrayRCP< const T > arcp(const RCP< const std::vector< T > > &v)
Wrap a const std::vector<T> object as an ArrayRCP<const T> object.
ArrayRCP< T > arcp(const RCP< std::vector< T > > &v)
Wrap an std::vector<T> object as an ArrayRCP<T> object.
ArrayRCP< T > & operator-=(size_type offset)
Pointer integer increment (i.e. ptr-=offset).
bool operator<=(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
Compare the two ArrayRCP objects' pointers using <=.
bool operator!=(const ArrayRCP< T > &p, ENull)
Returns true if p.get()!=NULL.
int weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
const Embedded & getEmbeddedObj(const ArrayRCP< T > &p)
Get a const reference to an embedded object that was set by calling arcpWithEmbeddedObjPreDestroy(),...
int total_count() const
Total count (strong_count() + weak_count()).
Base traits class for getting a properly initialized null pointer.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Handle class that manages the RCPNode's reference counting.
Smart reference counting pointer class for automatic garbage collection.
ERCPStrength
Used to specify if the pointer is weak or strong.
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...