42 #ifndef TEUCHOS_ARRAY_RCP_HPP 43 #define TEUCHOS_ARRAY_RCP_HPP 59 template<
class T>
inline 68 template<
class T,
class Dealloc_T>
71 T* p, Dealloc_T dealloc,
bool has_ownership_in
78 template<
class T2,
class T1>
106 for (itr_t itr = arcp2.
begin(); itr != arcp2.
end(); ++itr) {
117 template<
class T>
inline 119 : ptr_(NULL), lowerOffset_(0), upperOffset_(-1)
122 template<
class T>
inline 128 template<
class T>
inline 133 std::fill_n(
begin(), n, val);
136 template<
class T>
inline 147 template<
class T>
inline 153 #ifndef TEUCHOS_DEBUG
165 if (existing_RCPNode) {
180 #else // NOT TEUCHOS_DEBUG 181 (void) rcpNodeLookup;
182 #endif // TEUCHOS_DEBUG 185 template<
class T>
inline 190 #ifndef TEUCHOS_DEBUG
202 if (existing_RCPNode) {
217 #else // NOT TEUCHOS_DEBUG 218 (void) rcpNodeLookup;
219 #endif // TEUCHOS_DEBUG 224 template<
class Dealloc_T>
228 Dealloc_T dealloc,
bool has_ownership_in
231 #ifndef TEUCHOS_DEBUG
246 #endif // TEUCHOS_DEBUG 250 template<
class Dealloc_T>
254 Dealloc_T dealloc,
bool has_ownership_in
257 #ifndef TEUCHOS_DEBUG
272 #endif // TEUCHOS_DEBUG 276 template<
class T>
inline 284 template<
class T>
inline 293 template<
class T>
inline 296 template<
class T>
inline 300 template<
class T>
inline 305 node_ = r_ptr.access_private_node();
314 template<
class T>
inline 318 if (
this == &r_ptr) {
321 node_ = r_ptr.access_private_node ();
334 template<
class T>
inline 339 template<
class T>
inline 345 template<
class T>
inline 353 template<
class T>
inline 362 template<
class T>
inline 370 template<
class T>
inline 379 template<
class T>
inline 389 template<
class T>
inline 400 template<
class T>
inline 405 template<
class T>
inline 411 template<
class T>
inline 419 template<
class T>
inline 431 template<
class T>
inline 441 template<
class T>
inline 452 template<
class T>
inline 461 template<
class T>
inline 471 template<
class T>
inline 481 template<
class T>
inline 492 template<
class T>
inline 501 template<
class T>
inline 511 template<
class T>
inline 521 template<
class T>
inline 532 template<
class T>
inline 542 template<
class T>
inline 553 template<
class T>
inline 561 template<
class T>
inline 570 template<
class T>
inline 578 template<
class T>
inline 590 template<
class T>
inline 594 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 601 template<
class T>
inline 605 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 613 template<
class T>
inline 617 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 624 template<
class T>
inline 628 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 639 template<
class T>
inline 644 const T *cptr =
ptr_;
650 template<
class T>
inline 657 template<
class T>
inline 667 ptr.
ptr_ = ptr.
ptr_ + lowerOffset_in;
673 template<
class T>
inline 683 ptr.
ptr_ = ptr.
ptr_ + lowerOffset_in;
693 template<
class T>
inline 701 template<
class T>
inline 710 template<
class T>
inline 718 template<
class T>
inline 727 template<
class T>
inline 735 template<
class T>
inline 747 template<
class T>
inline 755 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 758 return arrayView(
ptr_ + lowerOffset_in, size_in);
763 template<
class T>
inline 772 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 775 return arrayView (
ptr_ + lowerOffset_in, size_in);
781 template<
class T>
inline 784 return view(lowerOffset_in, size_in);
787 template<
class T>
inline 791 return view (lowerOffset_in, size_in);
795 template<
class T>
inline 804 template<
class T>
inline 817 template<
class T>
inline 838 template<
class T>
inline 841 std::fill_n (this->
begin (), n, val);
849 const size_type new_n = std::distance (first, last);
850 if (new_n !=
size ()) {
851 *
this = arcp<T> (new_n);
853 std::copy (first, last,
begin ());
857 template<
class T>
inline 871 const size_type small_n = std::min(n, orig_n);
880 template<
class T>
inline 897 const size_type small_n = std::min (n, orig_n);
898 for (
size_type i = 0; i < small_n; ++i) {
899 nonconstThis[i] = tmp[i];
902 nonconstThis[i] = val;
910 template<
class T>
inline 915 template<
class T>
inline 924 template<
class T>
inline 927 if (av.
size() == 0) {
938 template<
class T>
inline 943 template<
class T>
inline 949 template<
class T>
inline 957 template<
class T>
inline 966 template<
class T>
inline 972 template<
class T>
inline 979 template<
class T>
inline 985 template<
class T>
inline 992 template<
class T>
inline 998 template<
class T>
inline 1005 template<
class T>
inline 1011 template<
class T>
inline 1018 template<
class T>
inline 1024 template<
class T>
inline 1031 template<
class T>
inline 1039 template<
class T>
inline 1048 template<
class T>
inline 1054 template<
class T>
inline 1061 template<
class T>
inline 1067 template<
class T>
inline 1100 template<
class T>
inline 1105 throw_null_ptr_error(
typeName(*
this));
1109 template<
class T>
inline 1114 throw_null_ptr_error (
typeName (*
this));
1120 template<
class T>
inline 1129 template<
class T>
inline 1139 template<
class T>
inline 1151 typeName(*
this)<<
"::assert_in_range:" 1152 " Error, [lowerOffset,lowerOffset+size-1] = [" 1153 <<lowerOffset_in<<
","<<(lowerOffset_in+size_in-1)<<
"] does not lie in the" 1159 template<
class T>
inline 1172 typeName (*
this) <<
"::assert_in_range:" 1173 " Error, [lowerOffset,lowerOffset+size-1] = [" 1174 <<lowerOffset_in<<
","<<(lowerOffset_in+size_in-1)<<
"] does not lie in the" 1184 template<
class T>
inline 1189 template<
class T>
inline 1198 template<
class T>
inline 1209 template<
class T>
inline 1221 template<
class T>
inline 1227 template<
class T>
inline 1234 template<
class T>
inline 1240 template<
class T>
inline 1247 template<
class T>
inline 1253 template<
class T>
inline 1283 namespace Utilities {
1284 template<
class T1,
class T2>
1289 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 1292 "Error, these iterators are *not* pointing to the same valid memory!" 1300 template<
class T>
inline 1312 template<
class T,
class Dealloc_T>
1318 ,Dealloc_T dealloc,
bool owns_mem
1325 template<
class T>
inline 1329 #ifdef TEUCHOS_DEBUG 1339 template<
class T>
inline 1351 template<
class T>
inline 1361 template<
class T,
class Embedded>
1363 Teuchos::arcpWithEmbeddedObjPreDestroy(
1367 const Embedded &embedded,
1372 p, lowerOffset, size,
1373 embeddedObjDeallocArrayDelete<T>(embedded,
PRE_DESTROY),
1379 template<
class T,
class Embedded>
1381 Teuchos::arcpWithEmbeddedObjPostDestroy(
1385 const Embedded &embedded,
1390 p, lowerOffset, size,
1391 embeddedObjDeallocArrayDelete<T>(embedded,
POST_DESTROY),
1397 template<
class T,
class Embedded>
1399 Teuchos::arcpWithEmbeddedObj(
1403 const Embedded &embedded,
1407 return arcpWithEmbeddedObjPostDestroy<T,Embedded>(
1412 template<
class T>
inline 1414 Teuchos::arcp(
const RCP<std::vector<T> > &v )
1418 return arcpWithEmbeddedObjPostDestroy<T,RCP<std::vector<T> > >(
1419 &(*v)[0], 0, v->size(),
1425 template<
class T>
inline 1427 Teuchos::arcp(
const RCP<
const std::vector<T> > &v )
1431 return arcpWithEmbeddedObjPostDestroy<const T,RCP<const std::vector<T> > >(
1432 &(*v)[0], 0, v->size(),
1438 template<
class T>
inline 1442 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 1443 return av.access_private_arcp();
1450 template<
class T>
inline 1454 return getEmbeddedObj<T, RCP<std::vector<T> > >(ptr);
1458 template<
class T>
inline 1462 return getEmbeddedObj<const T, RCP<const std::vector<T> > >(ptr);
1466 template<
class T>
inline 1473 template<
class T>
inline 1480 template<
class T>
inline 1487 template<
class T>
inline 1488 bool Teuchos::operator!=(
const ArrayRCP<T> &p, ENull )
1494 template<
class T1,
class T2>
1498 return p1.access_private_ptr() == p2.access_private_ptr();
1502 template<
class T1,
class T2>
1506 return p1.access_private_ptr() != p2.access_private_ptr();
1510 template<
class T1,
class T2>
1512 bool Teuchos::operator<( const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1514 return p1.access_private_ptr() < p2.access_private_ptr();
1518 template<
class T1,
class T2>
1520 bool Teuchos::operator<=( const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1523 return p1.access_private_ptr() <= p2.access_private_ptr();
1527 template<
class T1,
class T2>
1532 return p1.access_private_ptr() > p2.access_private_ptr();
1536 template<
class T1,
class T2>
1541 return p1.access_private_ptr() >= p2.access_private_ptr();
1550 return p1.access_private_ptr() - p2.access_private_ptr();
1554 template<
class T2,
class T1>
1560 const int sizeOfT1 =
sizeof(T1);
1561 const int sizeOfT2 =
sizeof(T2);
1562 size_type lowerOffset2 = (p1.
lowerOffset()*sizeOfT1) / sizeOfT2;
1563 size_type upperOffset2 = ((p1.
upperOffset()+1)*sizeOfT1) / sizeOfT2 - 1;
1564 T2 *ptr2 =
reinterpret_cast<T2*
>(p1.
get());
1566 ptr2, lowerOffset2, upperOffset2 - lowerOffset2 + 1,
1567 p1.access_private_node()
1573 template<
class T2,
class T1>
1575 Teuchos::arcp_reinterpret_cast_nonpod(
const ArrayRCP<T1>& p1,
const T2& val)
1579 for (itr_t itr = arcp2.
begin(); itr != arcp2.
end(); ++itr) {
1580 new (&*itr) T2(val);
1592 template<
class T2,
class T1>
1597 T2 *ptr2 =
const_cast<T2*
>(p1.
get());
1600 p1.access_private_node()
1606 template<
class T2,
class T1>
1611 T2 * raw_ptr2 = p1.
get();
1614 p1.access_private_node()
1620 template<
class T1,
class T2>
1622 void Teuchos::set_extra_data(
1623 const T1 &extra_data,
const std::string& name,
1629 p->nonconst_access_private_node().
set_extra_data(
any(extra_data), name, destroy_when,
1634 template<
class T1,
class T2>
1636 T1& Teuchos::get_extra_data(
ArrayRCP<T2>& p,
const std::string& name )
1639 return any_cast<T1>(
1647 template<
class T1,
class T2>
1649 const T1& Teuchos::get_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
1652 return any_cast<T1>(
1660 template<
class T1,
class T2>
1662 T1* Teuchos::get_optional_extra_data(
ArrayRCP<T2>& p,
const std::string& name )
1667 if( extra_data )
return &any_cast<T1>(*extra_data);
1672 template<
class T1,
class T2>
1674 const T1* Teuchos::get_optional_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
1679 if( extra_data )
return &any_cast<T1>(*extra_data);
1684 template<
class Dealloc_T,
class T>
1689 return get_nonconst_dealloc<Dealloc_T>(p);
1693 template<
class Dealloc_T,
class T>
1702 p.access_private_node().node_ptr());
1708 <<
"\' does not match actual type of the node \'" 1709 <<
typeName(*p.access_private_node().node_ptr()) <<
"!" 1715 template<
class Dealloc_T,
class T>
1718 Teuchos::get_optional_dealloc(
const ArrayRCP<T>& p )
1720 return get_optional_dealloc<Dealloc_T>(p);
1724 template<
class Dealloc_T,
class T>
1732 RCPNT *dnode =
dynamic_cast<RCPNT*
>(p.access_private_node().node_ptr());
1739 template<
class TOrig,
class Embedded,
class T>
1740 const Embedded& Teuchos::getEmbeddedObj(
const ArrayRCP<T>& p )
1743 return get_dealloc<Dealloc_t>(p).getObj();
1747 template<
class TOrig,
class Embedded,
class T>
1748 Embedded& Teuchos::getNonconstEmbeddedObj(
const ArrayRCP<T>& p )
1751 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
1756 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayRCP<T>& p )
1760 <<
"ptr="<<(
const void*)(p.access_private_ptr())
1763 <<
",size="<<p.
size()
1764 <<
",node="<<p.access_private_node()
1776 #endif // TEUCHOS_ARRAY_RCP_HPP Null reference error exception class.
size_type lowerOffset_
Lower offset to the data; 0 if this array is null.
TEUCHOS_DEPRECATED int count() const
Returns strong_count() [deprecated].
int weak_count() const
The weak count for this RCPNode, or 0 if the node is NULL.
ERCPStrength
Used to specify if the pointer is weak or strong.
ArrayRCP< T > create_weak() const
Create a new weak reference from another (strong) reference.
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.
ArcpReinterpretCastEmbeddedObj & operator=(const ArcpReinterpretCastEmbeddedObj &arceo)
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::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
ArrayRCP(ENull null_arg=null)
Default constructor; initialize to an empty array.
ArrayRCP< T > persistingView(size_type lowerOffset, size_type size) const
Return a persisting view of a contiguous range of elements.
RCPNode * ArrayRCP_createNewDeallocRCPNodeRawPtr(T *p, Dealloc_T dealloc, bool has_ownership_in)
T1 & get_extra_data(ArrayRCP< T2 > &p, const std::string &name)
Get a non-const reference to extra data associated with a ArrayRCP object.
Partial specialization of ArrayRCP for const T.
Ordinal difference_type
Type representing the difference between two size_type values.
ArrayRCP< T > & operator++()
Prefix increment of pointer (i.e. ++ptr).
ArrayRCP< T > & operator+=(size_type offset)
Pointer integer increment (i.e. ptr+=offset).
int weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
ArcpReinterpretCastEmbeddedObj()
#define TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2)
This macro is checks that an inequality between two numbers is satisified and if not then throws a go...
ArrayRCP< T > & operator-=(size_type offset)
Pointer integer increment (i.e. ptr-=offset).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Dealloc_T & get_nonconst_dealloc()
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
size_type size() const
The total number of items in the managed array.
size_type upperOffset() const
Return the upper offset to valid data.
ArrayRCP< T > & operator--()
Prefix decrement of pointer (i.e. –ptr).
T * release()
Release the ownership of the underlying array.
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
ArrayRCP< const T > getConst() const
Return object for only const access to data.
void release()
Releaes the RCPNode pointer before the destructor is called.
void clear()
Resize to zero.
A deallocator class that wraps a simple value object and delegates to another deallocator object...
Modified boost::any class, which is a container for a templated value.
size_type size() const
The total number of entries in the array.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
~ArrayRCP()
Destructor, that decrements the reference count.
ERCPStrength strength() const
Strength of the pointer.
void debug_assert_valid_ptr() const
RCPNodeHandle node_
Reference-counting machinery.
bool shares_resource(const ArrayRCP< T2 > &r_ptr) const
Returns true if the smart pointers share the same underlying reference-counted object.
bool is_valid_ptr() const
Return whether the underlying object pointer is still valid.
const ArrayRCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
T * operator->() const
Pointer (->) access to members of underlying object for current position.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
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.
void resize(const size_type n, const T &val=T())
Resize and append new elements if necessary.
Node class to keep track of address and the reference count for a reference-counted utility class and...
Deallocator class that uses delete [] to delete memory allocated uisng new []
Templated implementation class of RCPNode that has the responsibility for deleting the reference-coun...
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object...
void assert_valid_ptr(const RCPType &rcp_obj) const
ArrayRCP< T > create_strong() const
Create a new strong RCP object from another (weak) RCP object.
RCPNodeHandle create_strong() const
Return a strong handle.
ArrayRCP< T > operator+(size_type offset) const
Pointer integer increment (i.e. ptr+offset).
ERCPStrength strength() const
The strength of this handle.
void deepCopy(const ArrayView< const T > &av)
Deep copy the elements from one ArrayView object into this object.
size_type lowerOffset() const
Return the lower offset to valid data.
int total_count() const
Total count (strong_count() + weak_count()).
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
Incompatiable iterators error exception class.
T & operator*() const
Dereference the underlying object for the current pointer position.
static RCPNode * getExistingRCPNode(T *p)
Return a raw pointer to an existing owning RCPNode given the address to the underlying object if it e...
T * ptr_
Raw pointer to the array; NULL if this array is null.
bool nonnull(const boost::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool operator==(const TwoDArray< T > &a1, const TwoDArray< T > &a2)
Default traits class that just returns typeid(T).name().
void set_has_ownership()
Give this and other ArrayRCP<> objects ownership of the underlying referenced array to delete it...
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
Handle class that manages the RCPNode's reference counting.
int strong_count() const
The strong count for this RCPNode, or 0 if the node is NULL.
void has_ownership(bool has_ownership_in)
void debug_assert_in_range(size_type lowerOffset_in, size_type size_in) const
ArrayView< T > operator()() const
Return a nonpersisting view of *this.
int total_count() const
The sum of the weak and string counts.
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
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.
ArrayRCP< T2 > arcp_const_cast(const ArrayRCP< T1 > &p1)
Const cast of underlying ArrayRCP type from const T* to T*.
bool is_valid_ptr() const
Whether the underlying pointer is valid.
ArrayRCP< T > & operator=(const ArrayRCP< T > &r_ptr)
Assignment operator: Makes *this reference the input array.
void assert_shares_resource(const ArrayRCP< T1 > &p1, const ArrayRCP< T2 > &p2)
ArcpReinterpretCastEmbeddedObj(const ArrayRCP< T1 > &arcp_pod)
ArrayRCP< T > operator-(size_type offset) const
Pointer integer decrement (i.e. ptr-offset).
Smart reference counting pointer class for automatic garbage collection.
bool same_node(const RCPNodeHandle &node2) const
Whether the RCPNode for which node2 is a handle is the same RCPNode as this object's RCPNode...
T & operator[](size_type offset) const
Random object access.
Deletes a (non-owning) RCPNode but not it's underlying object in case of a throw. ...
T * iterator
Nonconstant iterator type used if bounds checking is disabled.
iterator end() const
Return an iterator to past the end of the array of data.
Partial specialization of ArrayView for const T.
RCPNode * ArrayRCP_createNewRCPNodeRawPtr(T *p, bool has_ownership_in)
Range error exception class.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
size_type upperOffset_
Upper offset to the data; -1 if this array is null.
RCPNodeHandle create_weak() const
Return a weak handle.
int count() const
The strong count; retained for backwards compatibility.
bool is_null() const
True if the underlying pointer is null, else false.
~ArcpReinterpretCastEmbeddedObj()
T * get() const
Get the raw C++ pointer to the underlying object.
Definition of Teuchos::as, for conversions between types.
const ArrayRCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
iterator begin() const
Return an iterator to beginning of the array of data.
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to deallocate it...
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
void assign(size_type n, const T &val)
Resize and assign n elements of val.
ArrayView< T > view(size_type lowerOffset, size_type size) const
Return a nonpersisting view of a contiguous range of elements.