10#ifndef TEUCHOS_ARRAY_RCP_DECL_HPP
11#define TEUCHOS_ARRAY_RCP_DECL_HPP
15#include "Teuchos_Exceptions.hpp"
16#include "Teuchos_ArrayViewDecl.hpp"
132#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
208 template<
class Dealloc_T>
559 inline void assign(Iter first, Iter last);
757 inline void debug_assert_not_null ()
const {
758#ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
764 debug_assert_in_range (
size_type lowerOffset_in,
767 (void) lowerOffset_in;
769#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
774 inline void debug_assert_valid_ptr()
const {
782#ifndef DOXYGEN_COMPILE
788 const RCPNodeHandle& node );
789 T* access_private_ptr()
const;
790 RCPNodeHandle& nonconst_access_private_node();
791 const RCPNodeHandle& access_private_node()
const;
805class ArrayRCP<const T> {
807 typedef Teuchos_Ordinal Ordinal;
808 typedef Ordinal size_type;
809 typedef Ordinal difference_type;
810 typedef std::random_access_iterator_tag iterator_category;
811 typedef const T* iterator_type;
812 typedef const T value_type;
813 typedef const T& reference;
814 typedef const T& const_reference;
815 typedef const T* pointer;
816 typedef const T* const_pointer;
817 typedef const T element_type;
819#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
820 typedef ArrayRCP<const T> iterator;
821 typedef ArrayRCP<const T> const_iterator;
823 typedef const T* iterator;
824 typedef const T* const_iterator;
827 inline ArrayRCP (ENull null_arg = null);
828 inline ArrayRCP (
const T* p, size_type lowerOffset,
829 size_type size,
bool has_ownership,
831 template<
class Dealloc_T>
832 inline ArrayRCP (
const T* p, size_type lowerOffset, size_type size,
833 Dealloc_T dealloc,
bool has_ownership);
834 inline explicit ArrayRCP (size_type size,
const T& val = T ());
835 inline ArrayRCP (
const ArrayRCP<const T>& r_ptr);
838 inline ArrayRCP<const T>&
operator= (
const ArrayRCP<const T>& r_ptr);
842 inline const T*
get()
const;
844 inline const T&
operator[] (size_type offset)
const;
850 inline ArrayRCP<const T>&
operator+= (size_type offset);
851 inline ArrayRCP<const T>&
operator-= (size_type offset);
852 inline ArrayRCP<const T>
operator+ (size_type offset)
const;
853 inline ArrayRCP<const T>
operator- (size_type offset)
const;
855 inline iterator
begin()
const;
856 inline iterator
end()
const;
864 inline ArrayRCP<const T>
persistingView (size_type lowerOffset, size_type size)
const;
868 inline size_type
size()
const;
874 inline void resize (
const size_type n,
const T& val = T ());
875 inline void clear ();
892 inline const ArrayRCP<const T>&
assert_in_range (size_type lowerOffset, size_type size)
const;
898 size_type lowerOffset_;
899 size_type upperOffset_;
901 inline void debug_assert_not_null()
const {
902#ifdef TEUCHOS_REFCOUNTPTR_ASSERT_NONNULL
908 debug_assert_in_range (
size_type lowerOffset_in,
911 (void) lowerOffset_in; (void) size_in;
912#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
917 inline void debug_assert_valid_ptr()
const {
925#ifndef DOXYGEN_COMPILE
932 const T* access_private_ptr()
const;
933 RCPNodeHandle& nonconst_access_private_node();
934 const RCPNodeHandle& access_private_node()
const;
950 typedef Teuchos_Ordinal Ordinal;
951 typedef Ordinal size_type;
952 typedef Ordinal difference_type;
953 typedef std::random_access_iterator_tag iterator_category;
954 typedef void* iterator_type;
955 typedef void value_type;
961 typedef void* const_pointer;
962 typedef void element_type;
975 typedef Teuchos_Ordinal Ordinal;
976 typedef Ordinal size_type;
977 typedef Ordinal difference_type;
978 typedef std::random_access_iterator_tag iterator_category;
979 typedef const void* iterator_type;
980 typedef const void value_type;
986 typedef const void* const_pointer;
987 typedef const void element_type;
1019 bool owns_mem =
true
1028template<
class T,
class Dealloc_T>
1033 Dealloc_T dealloc,
bool owns_mem
1086template<
class T,
class Embedded>
1092 const Embedded &embedded,
1093 bool owns_mem =
true
1107template<
class T,
class Embedded>
1113 const Embedded &embedded,
1114 bool owns_mem =
true
1129template<
class T,
class Embedded>
1135 const Embedded &embedded,
1136 bool owns_mem =
true
1227template<
class T1,
class T2>
1235template<
class T1,
class T2>
1243template<
class T1,
class T2>
1251template<
class T1,
class T2>
1259template<
class T1,
class T2>
1267template<
class T1,
class T2>
1293template<
class T2,
class T1>
1309template<
class T2,
class T1>
1329template<
class T2,
class T1>
1358template<
class T2,
class T1>
1421template<
class T1,
class T2>
1423 const T1 &extra_data,
const std::string& name,
1425 bool force_unique =
true );
1447template<
class T1,
class T2>
1476template<
class T1,
class T2>
1504template<
class T1,
class T2>
1537template<
class T1,
class T2>
1551template<
class Dealloc_T,
class T>
1572template<
class Dealloc_T,
class T>
1590template<
class Dealloc_T,
class T>
1615template<
class Dealloc_T,
class T>
1625template<
class TOrig,
class Embedded,
class T>
1635template<
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.
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
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< T > operator++(int)
Postfix increment of pointer (i.e. ptr++).
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 >=.
ArrayRCP< T > operator--(int)
Postfix decrement of pointer (i.e. ptr–).
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*.
ArrayRCP(size_type size, const T &val=T())
Construct an array with the given number of elements.
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
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.
ArrayRCP(T *p, size_type lowerOffset, size_type size, bool has_ownership, const ERCPNodeLookup rcpNodeLookup=RCP_ENABLE_NODE_LOOKUP)
Construct from a raw pointer and a valid range.
T element_type
Type of each array element.
ArrayRCP(T *p, size_type lowerOffset, size_type size, Dealloc_T dealloc, bool has_ownership)
Construct from a raw pointer, a valid range, and a deallocator.
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.
ArrayRCP(const ArrayRCP< T > &r_ptr)
Initialize from another ArrayRCP<T> object.
ArrayView< T > operator()(size_type lowerOffset, size_type size) const
Return a nonpersisting view of a contiguous range of elements.
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.
void assign(Iter first, Iter last)
Resize and assign to iterator sequence [first, last).
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.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
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,...