10#ifndef TEUCHOS_ARRAY_RCP_HPP
11#define TEUCHOS_ARRAY_RCP_HPP
14#include "Teuchos_ArrayRCPDecl.hpp"
15#include "Teuchos_ArrayView.hpp"
16#include "Teuchos_Assert.hpp"
17#include "Teuchos_dyn_cast.hpp"
27template<
class T>
inline
28RCPNode* ArrayRCP_createNewRCPNodeRawPtr( T* p,
bool has_ownership_in )
36template<
class T,
class Dealloc_T>
38RCPNode* ArrayRCP_createNewDeallocRCPNodeRawPtr(
39 T* p, Dealloc_T dealloc,
bool has_ownership_in
46template<
class T2,
class T1>
47class ArcpReinterpretCastEmbeddedObj
51 ArcpReinterpretCastEmbeddedObj()
54 ArcpReinterpretCastEmbeddedObj(
const ArrayRCP<T1> &arcp_pod)
58 ~ArcpReinterpretCastEmbeddedObj()
60 ArcpReinterpretCastEmbeddedObj&
61 operator=(
const ArcpReinterpretCastEmbeddedObj& arceo)
63 assert(
is_null(arceo.arcp_pod_));
68 ArrayRCP<T1> arcp_pod_;
72 if (arcp_pod_.strong_count() == 1) {
74 for (itr_t itr = arcp2.begin(); itr != arcp2.end(); ++itr) {
85template<
class T>
inline
87 : ptr_(NULL), lowerOffset_(0), upperOffset_(-1)
90template<
class T>
inline
92 : ptr_(NULL), lowerOffset_(0), upperOffset_(-1)
96template<
class T>
inline
98 : ptr_(0), lowerOffset_(0), upperOffset_(-1)
101 std::fill_n(
begin(), n, val);
104template<
class T>
inline
106 : ptr_(0), lowerOffset_(0), upperOffset_(-1)
115template<
class T>
inline
122 node_(ArrayRCP_createNewRCPNodeRawPtr(p, has_ownership_in)),
124 lowerOffset_(lowerOffset_in),
125 upperOffset_(size_in + lowerOffset_in - 1)
130 if (!has_ownership_in && rcpNodeLookup==RCP_ENABLE_NODE_LOOKUP) {
133 if (existing_RCPNode) {
149 (void) rcpNodeLookup;
153template<
class T>
inline
155ArrayRCP (
const T* p, size_type lowerOffset_in, size_type size_in,
159 node_(ArrayRCP_createNewRCPNodeRawPtr(p, has_ownership_in)),
161 lowerOffset_(lowerOffset_in),
162 upperOffset_(size_in + lowerOffset_in - 1)
167 if (! has_ownership_in && rcpNodeLookup == RCP_ENABLE_NODE_LOOKUP) {
170 if (existing_RCPNode) {
172 node_ = RCPNodeHandle(existing_RCPNode, RCP_WEAK,
false);
176 RCPNodeThrowDeleter nodeDeleter (ArrayRCP_createNewRCPNodeRawPtr (p, has_ownership_in));
177 node_ = RCPNodeHandle(
182 nodeDeleter.release ();
186 (void) rcpNodeLookup;
192template<
class Dealloc_T>
196 Dealloc_T dealloc,
bool has_ownership_in
200 node_(ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in)),
202 lowerOffset_(lowerOffset_in),
203 upperOffset_(size_in + lowerOffset_in - 1)
208 ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in),
218template<
class Dealloc_T>
221 const T* p, size_type lowerOffset_in, size_type size_in,
222 Dealloc_T dealloc,
bool has_ownership_in
226 node_(ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in)),
228 lowerOffset_(lowerOffset_in),
229 upperOffset_(size_in + lowerOffset_in - 1)
234 ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in),
244template<
class T>
inline
248 lowerOffset_(r_ptr.lowerOffset_),
249 upperOffset_(r_ptr.upperOffset_)
252template<
class T>
inline
256 lowerOffset_(r_ptr.lowerOffset_),
257 upperOffset_(r_ptr.upperOffset_)
261template<
class T>
inline
264template<
class T>
inline
268template<
class T>
inline
273 node_ = r_ptr.access_private_node();
275 lowerOffset_ = r_ptr.lowerOffset_;
276 upperOffset_ = r_ptr.upperOffset_;
282template<
class T>
inline
286 if (
this == &r_ptr) {
289 node_ = r_ptr.access_private_node ();
291 lowerOffset_ = r_ptr.lowerOffset_;
292 upperOffset_ = r_ptr.upperOffset_;
302template<
class T>
inline
307template<
class T>
inline
313template<
class T>
inline
316 debug_assert_valid_ptr();
317 debug_assert_in_range(0,1);
321template<
class T>
inline
324 debug_assert_valid_ptr();
325 debug_assert_in_range(0,1);
330template<
class T>
inline
333 debug_assert_valid_ptr();
334 debug_assert_in_range(0,1);
338template<
class T>
inline
341 debug_assert_valid_ptr();
342 debug_assert_in_range(0,1);
347template<
class T>
inline
351 debug_assert_valid_ptr();
352 debug_assert_in_range(0,1);
357template<
class T>
inline
361 debug_assert_valid_ptr();
362 debug_assert_in_range(0,1);
368template<
class T>
inline
373template<
class T>
inline
379template<
class T>
inline
382 debug_assert_valid_ptr();
383 debug_assert_in_range(offset,1);
387template<
class T>
inline
390 debug_assert_valid_ptr();
391 debug_assert_in_range(offset,1);
399template<
class T>
inline
402 debug_assert_valid_ptr();
409template<
class T>
inline
412 debug_assert_valid_ptr();
420template<
class T>
inline
423 debug_assert_valid_ptr();
429template<
class T>
inline
432 debug_assert_valid_ptr();
439template<
class T>
inline
442 debug_assert_valid_ptr();
449template<
class T>
inline
452 debug_assert_valid_ptr();
460template<
class T>
inline
463 debug_assert_valid_ptr();
469template<
class T>
inline
472 debug_assert_valid_ptr();
479template<
class T>
inline
482 debug_assert_valid_ptr();
484 lowerOffset_ -= offset;
485 upperOffset_ -= offset;
489template<
class T>
inline
492 debug_assert_valid_ptr();
494 lowerOffset_ -= offset;
495 upperOffset_ -= offset;
500template<
class T>
inline
503 debug_assert_valid_ptr();
505 lowerOffset_ += offset;
506 upperOffset_ += offset;
510template<
class T>
inline
513 debug_assert_valid_ptr();
515 lowerOffset_ += offset;
516 upperOffset_ += offset;
521template<
class T>
inline
529template<
class T>
inline
538template<
class T>
inline
541 ArrayRCP<T> r_ptr = *
this;
546template<
class T>
inline
549 ArrayRCP<const T> r_ptr = *
this;
558template<
class T>
inline
561 debug_assert_valid_ptr();
562#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
569template<
class T>
inline
572 debug_assert_valid_ptr();
573#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
581template<
class T>
inline
584 debug_assert_valid_ptr();
585#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
586 return *
this + (upperOffset_ + 1);
588 return ptr_ + (upperOffset_ + 1);
592template<
class T>
inline
595 debug_assert_valid_ptr();
596#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
597 return *
this + (upperOffset_ + 1);
599 return ptr_ + (upperOffset_ + 1);
607template<
class T>
inline
611 debug_assert_valid_ptr();
612 const T *cptr = ptr_;
613 return ArrayRCP<const T>(cptr, lowerOffset_,
size(), node_);
618template<
class T>
inline
625template<
class T>
inline
632 debug_assert_valid_ptr();
633 debug_assert_in_range(lowerOffset_in, size_in);
635 ptr.ptr_ =
ptr.ptr_ + lowerOffset_in;
636 ptr.lowerOffset_ = 0;
637 ptr.upperOffset_ = size_in - 1;
641template<
class T>
inline
648 debug_assert_valid_ptr();
649 debug_assert_in_range(lowerOffset_in, size_in);
650 ArrayRCP<const T>
ptr = *
this;
651 ptr.ptr_ =
ptr.ptr_ + lowerOffset_in;
653 ptr.upperOffset_ = size_in - 1;
661template<
class T>
inline
665 debug_assert_valid_ptr();
669template<
class T>
inline
673 debug_assert_valid_ptr();
678template<
class T>
inline
682 debug_assert_valid_ptr();
686template<
class T>
inline
690 debug_assert_valid_ptr();
695template<
class T>
inline
699 debug_assert_valid_ptr();
700 return upperOffset_ - lowerOffset_ + 1;
703template<
class T>
inline
707 debug_assert_valid_ptr();
708 return upperOffset_ - lowerOffset_ + 1;
715template<
class T>
inline
721 debug_assert_valid_ptr();
722 debug_assert_in_range(lowerOffset_in,size_in);
723#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
726 return arrayView(ptr_ + lowerOffset_in, size_in);
731template<
class T>
inline
738 debug_assert_valid_ptr();
739 debug_assert_in_range(lowerOffset_in,size_in);
740#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
749template<
class T>
inline
752 return view(lowerOffset_in, size_in);
755template<
class T>
inline
759 return view (lowerOffset_in, size_in);
763template<
class T>
inline
772template<
class T>
inline
776 return view(lowerOffset_, size());
785template<
class T>
inline
806template<
class T>
inline
809 std::fill_n (this->
begin (), n, val);
817 const size_type new_n = std::distance (first, last);
818 if (new_n !=
size ()) {
821 std::copy (first, last,
begin ());
825template<
class T>
inline
839 const size_type small_n = std::min(n, orig_n);
848template<
class T>
inline
858 const size_type orig_n = size ();
860 ArrayRCP<const T> tmp = *
this;
864 ArrayRCP<T> nonconstThis =
arcp<T> (n);
865 const size_type small_n = std::min (n, orig_n);
866 for (size_type i = 0; i < small_n; ++i) {
867 nonconstThis[i] = tmp[i];
869 for (size_type i = orig_n; i < n; ++i) {
870 nonconstThis[i] = val;
878template<
class T>
inline
883template<
class T>
inline
892template<
class T>
inline
895 if (av.
size() == 0) {
906template<
class T>
inline
908 return node_.strength();
911template<
class T>
inline
913 return node_.strength();
917template<
class T>
inline
921 return node_.is_valid_ptr();
925template<
class T>
inline
929 return node_.is_valid_ptr();
934template<
class T>
inline
937 return node_.strong_count();
940template<
class T>
inline
943 return node_.strong_count();
947template<
class T>
inline
950 return node_.weak_count();
953template<
class T>
inline
956 return node_.weak_count();
960template<
class T>
inline
963 return node_.total_count();
966template<
class T>
inline
969 return node_.total_count();
973template<
class T>
inline
976 node_.has_ownership(
true);
979template<
class T>
inline
982 node_.has_ownership(
true);
986template<
class T>
inline
989 return node_.has_ownership();
992template<
class T>
inline
995 return node_.has_ownership();
999template<
class T>
inline
1002 debug_assert_valid_ptr();
1003 node_.has_ownership(
false);
1007template<
class T>
inline
1010 debug_assert_valid_ptr();
1011 node_.has_ownership(
false);
1016template<
class T>
inline
1018 debug_assert_valid_ptr ();
1019 return ArrayRCP<T> (ptr_, lowerOffset_,
size (), node_.create_weak ());
1022template<
class T>
inline
1024 debug_assert_valid_ptr ();
1029template<
class T>
inline
1031 debug_assert_valid_ptr ();
1032 return ArrayRCP<T> (ptr_, lowerOffset_,
size (), node_.create_strong ());
1035template<
class T>
inline
1037 debug_assert_valid_ptr ();
1047 return node_.same_node (r_ptr.access_private_node ());
1058 return node_.same_node (r_ptr.access_private_node ());
1068template<
class T>
inline
1077template<
class T>
inline
1088template<
class T>
inline
1092 node_.assert_valid_ptr (*
this);
1097template<
class T>
inline
1101 node_.assert_valid_ptr (*
this);
1107template<
class T>
inline
1114 (lowerOffset_ <= lowerOffset_in && lowerOffset_in+size_in-1 <= upperOffset_)
1119 typeName(*
this)<<
"::assert_in_range:"
1120 " Error, [lowerOffset,lowerOffset+size-1] = ["
1121 <<lowerOffset_in<<
","<<(lowerOffset_in+size_in-1)<<
"] does not lie in the"
1122 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1127template<
class T>
inline
1135 (lowerOffset_ <= lowerOffset_in && lowerOffset_in+size_in-1 <= upperOffset_)
1140 typeName (*
this) <<
"::assert_in_range:"
1141 " Error, [lowerOffset,lowerOffset+size-1] = ["
1142 <<lowerOffset_in<<
","<<(lowerOffset_in+size_in-1)<<
"] does not lie in the"
1143 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1152template<
class T>
inline
1154 T* p, size_type lowerOffset_in, size_type size_in,
1155 const RCPNodeHandle& node
1159 lowerOffset_(lowerOffset_in),
1160 upperOffset_(size_in + lowerOffset_in - 1)
1163template<
class T>
inline
1165 const T* p, size_type lowerOffset_in, size_type size_in,
1170 lowerOffset_(lowerOffset_in),
1171 upperOffset_(size_in + lowerOffset_in - 1)
1175template<
class T>
inline
1181template<
class T>
inline
1188template<
class T>
inline
1194template<
class T>
inline
1201template<
class T>
inline
1207template<
class T>
inline
1237namespace Utilities {
1238template<
class T1,
class T2>
1239inline void assert_shares_resource(
1240 const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2
1243#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1245 !p1.shares_resource(p2), IncompatibleIteratorsError,
1246 "Error, these iterators are *not* pointing to the same valid memory!"
1254template<
class T>
inline
1257T* p,
typename ArrayRCP<T>::size_type lowerOffset
1258 ,
typename ArrayRCP<T>::size_type size_in
1262 return ArrayRCP<T>(p, lowerOffset, size_in, owns_mem);
1266template<
class T,
class Dealloc_T>
1270T* p,
typename ArrayRCP<T>::size_type lowerOffset
1271 ,
typename ArrayRCP<T>::size_type size_in
1272 ,Dealloc_T dealloc,
bool owns_mem
1275 return ArrayRCP<T>(p, lowerOffset, size_in, dealloc, owns_mem);
1279template<
class T>
inline
1289 return ArrayRCP<T>(
new T[size], 0, size,
true);
1293template<
class T>
inline
1305template<
class T>
inline
1309 const ArrayRCP<T> new_arcp = arcp<T>(v.size());
1310 std::copy( v.begin(), v.end(), new_arcp.begin() );
1315template<
class T,
class Embedded>
1319 typename ArrayRCP<T>::size_type lowerOffset,
1320 typename ArrayRCP<T>::size_type size,
1321 const Embedded &embedded,
1326 p, lowerOffset, size,
1327 embeddedObjDeallocArrayDelete<T>(embedded, PRE_DESTROY),
1333template<
class T,
class Embedded>
1337 typename ArrayRCP<T>::size_type lowerOffset,
1338 typename ArrayRCP<T>::size_type size,
1339 const Embedded &embedded,
1344 p, lowerOffset, size,
1345 embeddedObjDeallocArrayDelete<T>(embedded, POST_DESTROY),
1351template<
class T,
class Embedded>
1355 typename ArrayRCP<T>::size_type lowerOffset,
1356 typename ArrayRCP<T>::size_type size,
1357 const Embedded &embedded,
1361 return arcpWithEmbeddedObjPostDestroy<T,Embedded>(
1362 p, lowerOffset, size, embedded, owns_mem );
1366template<
class T>
inline
1370 if (
is_null(v) || !v->size() )
1372 return arcpWithEmbeddedObjPostDestroy<T,RCP<std::vector<T> > >(
1373 &(*v)[0], 0, v->size(),
1379template<
class T>
inline
1383 if (
is_null(v) || !v->size() )
1385 return arcpWithEmbeddedObjPostDestroy<const T,RCP<const std::vector<T> > >(
1386 &(*v)[0], 0, v->size(),
1392template<
class T>
inline
1396#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1397 return av.access_private_arcp();
1399 return arcp(av.getRawPtr(), 0, av.size(),
false);
1404template<
class T>
inline
1408 return getEmbeddedObj<T, RCP<std::vector<T> > >(
ptr);
1412template<
class T>
inline
1416 return getEmbeddedObj<const T, RCP<const std::vector<T> > >(
ptr);
1420template<
class T>
inline
1427template<
class T>
inline
1430 return !p.is_null();
1434template<
class T>
inline
1435bool Teuchos::operator==(
const ArrayRCP<T> &p, ENull )
1441template<
class T>
inline
1444 return !p.is_null();
1448template<
class T1,
class T2>
1450bool Teuchos::operator==(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1452 return p1.access_private_ptr() == p2.access_private_ptr();
1456template<
class T1,
class T2>
1460 return p1.access_private_ptr() != p2.access_private_ptr();
1464template<
class T1,
class T2>
1466bool Teuchos::operator<(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1468 return p1.access_private_ptr() < p2.access_private_ptr();
1472template<
class T1,
class T2>
1474bool Teuchos::operator<=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1476 Utilities::assert_shares_resource(p1,p2);
1477 return p1.access_private_ptr() <= p2.access_private_ptr();
1481template<
class T1,
class T2>
1483bool Teuchos::operator>(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1485 Utilities::assert_shares_resource(p1,p2);
1486 return p1.access_private_ptr() > p2.access_private_ptr();
1490template<
class T1,
class T2>
1492bool Teuchos::operator>=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1494 Utilities::assert_shares_resource(p1,p2);
1495 return p1.access_private_ptr() >= p2.access_private_ptr();
1501Teuchos::operator-(
const ArrayRCP<T> &p1,
const ArrayRCP<T> &p2 )
1503 Utilities::assert_shares_resource(p1,p2);
1504 return p1.access_private_ptr() - p2.access_private_ptr();
1508template<
class T2,
class T1>
1513 typedef typename ArrayRCP<T1>::size_type size_type;
1514 const int sizeOfT1 =
sizeof(T1);
1515 const int sizeOfT2 =
sizeof(T2);
1516 size_type lowerOffset2 = (p1.lowerOffset()*sizeOfT1) / sizeOfT2;
1517 size_type upperOffset2 = ((p1.upperOffset()+1)*sizeOfT1) / sizeOfT2 - 1;
1518 T2 *ptr2 =
reinterpret_cast<T2*
>(p1.get());
1519 return ArrayRCP<T2>(
1520 ptr2, lowerOffset2, upperOffset2 - lowerOffset2 + 1,
1521 p1.access_private_node()
1527template<
class T2,
class T1>
1531 typedef typename ArrayRCP<T2>::iterator itr_t;
1532 ArrayRCP<T2> arcp2 = arcp_reinterpret_cast<T2>(p1);
1533 for (itr_t itr = arcp2.begin(); itr != arcp2.end(); ++itr) {
1534 new (&*itr) T2(val);
1537 arcp2.getRawPtr(), 0, arcp2.size(),
1538 ArcpReinterpretCastEmbeddedObj<T2, T1>(p1),
1546template<
class T2,
class T1>
1551 T2 *ptr2 =
const_cast<T2*
>(p1.get());
1552 return ArrayRCP<T2>(
1553 ptr2, p1.lowerOffset(), p1.size(),
1554 p1.access_private_node()
1560template<
class T2,
class T1>
1565 T2 * raw_ptr2 = p1.
get();
1566 return ArrayRCP<T2>(
1567 raw_ptr2, p1.lowerOffset(), p1.size(),
1568 p1.access_private_node()
1574template<
class T1,
class T2>
1577 const T1 &extra_data,
const std::string& name,
1578 const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when,
1582 p->assert_not_null();
1583 p->nonconst_access_private_node().set_extra_data( any(extra_data), name, destroy_when,
1588template<
class T1,
class T2>
1592 p.assert_not_null();
1593 return any_cast<T1>(
1594 p.nonconst_access_private_node().get_extra_data(
1595 TypeNameTraits<T1>::name(), name
1601template<
class T1,
class T2>
1605 p.assert_not_null();
1606 return any_cast<T1>(
1607 p.access_private_node().get_extra_data(
1608 TypeNameTraits<T1>::name() ,name
1614template<
class T1,
class T2>
1618 p.assert_not_null();
1619 any *extra_data = p.nonconst_access_private_node().get_optional_extra_data(
1620 TypeNameTraits<T1>::name(), name);
1621 if( extra_data )
return &any_cast<T1>(*extra_data);
1626template<
class T1,
class T2>
1630 p.assert_not_null();
1631 any *extra_data = p.access_private_node().get_optional_extra_data(
1632 TypeNameTraits<T1>::name(), name);
1633 if( extra_data )
return &any_cast<T1>(*extra_data);
1638template<
class Dealloc_T,
class T>
1643 return get_nonconst_dealloc<Dealloc_T>(p);
1647template<
class Dealloc_T,
class T>
1652 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T> requested_type;
1654 RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1655 *dnode =
dynamic_cast<RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>*
>(
1656 p.access_private_node().node_ptr());
1658 dnode==NULL, NullReferenceError
1659 ,
"get_dealloc<" << TypeNameTraits<Dealloc_T>::name()
1660 <<
"," << TypeNameTraits<T>::name() <<
">(p): "
1661 <<
"Error, requested type \'" << TypeNameTraits<requested_type>::name()
1662 <<
"\' does not match actual type of the node \'"
1663 <<
typeName(*p.access_private_node().node_ptr()) <<
"!"
1665 return dnode->get_nonconst_dealloc();
1669template<
class Dealloc_T,
class T>
1674 return get_optional_dealloc<Dealloc_T>(p);
1678template<
class Dealloc_T,
class T>
1684 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1686 RCPNT *dnode =
dynamic_cast<RCPNT*
>(p.access_private_node().node_ptr());
1688 return &dnode->get_nonconst_dealloc();
1693template<
class TOrig,
class Embedded,
class T>
1696 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1697 return get_dealloc<Dealloc_t>(p).getObj();
1701template<
class TOrig,
class Embedded,
class T>
1704 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1705 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
1710std::ostream& Teuchos::operator<<( std::ostream& out,
const ArrayRCP<T>& p )
1718 << TypeNameTraits<ArrayRCP<T> >::name() <<
"{"
1720 if (p.access_private_ptr () == NULL) {
1723 out << (
const void*) (p.access_private_ptr ());
1726 <<
",lowerOffset="<<p.lowerOffset()
1727 <<
",upperOffset="<<p.upperOffset()
1728 <<
",size="<<p.size()
1729 <<
",node=" << p.access_private_node ()
1730 <<
",strong_count="<<p.strong_count()
1731 <<
",weak_count="<<p.weak_count()
Definition of Teuchos::as, for conversions between types.
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< T1 > create_weak() const
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).
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.
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to deallocate it.
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.
T * release()
Release the ownership of the underlying array.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
void clear()
Resize to zero.
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*.
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.
void deepCopy(const ArrayView< const T > &av)
Deep copy the elements from one ArrayView object into this 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.
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
ArrayRCP< T > & operator--()
Prefix decrement of pointer (i.e. –ptr).
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...
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.
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...
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.
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 ...
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.
const ArrayRCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
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...
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()).
iterator end() const
Return an iterator to past the end of the array of data.
iterator begin() const
Return an iterator to beginning of the array of data.
size_type size() const
The total number of items in the managed array.
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
Deallocator class that uses delete [] to delete memory allocated uisng new [].
T & get(ParameterList &l, const std::string &name)
A shorter name for getParameter().
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
Handle class that manages the RCPNode's reference counting.
Deletes a (non-owning) RCPNode but not it's underlying object in case of a throw.
void release()
Releaes the RCPNode pointer before the destructor is called.
Templated implementation class of RCPNode that has the responsibility for deleting the reference-coun...
static RCPNode * getExistingRCPNode(T *p)
Return a raw pointer to an existing owning RCPNode given the address to the underlying object if it e...
Node class to keep track of address and the reference count for a reference-counted utility class and...
TEUCHOSCORE_LIB_DLL_EXPORT void throw_null_ptr_error(const std::string &type_name)
Throw that a pointer passed into an RCP object is null.
Smart reference counting pointer class for automatic garbage collection.
bool is_null() const
Returns true if the underlying pointer is null.
Range error exception class.
bool operator!=(const any &a, const any &b)
Returns true if two any objects do not have the same value.
#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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#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...
#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 ...
bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object.
ERCPStrength
Used to specify if the pointer is weak or strong.
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...