42 #ifndef TEUCHOS_ARRAY_RCP_HPP 43 #define TEUCHOS_ARRAY_RCP_HPP 46 #include "Teuchos_ArrayRCPDecl.hpp" 47 #include "Teuchos_ArrayView.hpp" 48 #include "Teuchos_Assert.hpp" 49 #include "Teuchos_dyn_cast.hpp" 59 template<
class T>
inline 60 RCPNode* ArrayRCP_createNewRCPNodeRawPtr( T* p,
bool has_ownership_in )
62 return new RCPNodeTmpl<T,DeallocArrayDelete<T> >(
63 p, DeallocArrayDelete<T>(), has_ownership_in
68 template<
class T,
class Dealloc_T>
70 RCPNode* ArrayRCP_createNewDeallocRCPNodeRawPtr(
71 T* p, Dealloc_T dealloc,
bool has_ownership_in
74 return new RCPNodeTmpl<T,Dealloc_T>(p, dealloc, has_ownership_in);
78 template<
class T2,
class T1>
79 class ArcpReinterpretCastEmbeddedObj
83 ArcpReinterpretCastEmbeddedObj()
86 ArcpReinterpretCastEmbeddedObj(
const ArrayRCP<T1> &arcp_pod)
87 : arcp_pod_(arcpCloneNode(arcp_pod))
90 ~ArcpReinterpretCastEmbeddedObj()
92 ArcpReinterpretCastEmbeddedObj&
93 operator=(
const ArcpReinterpretCastEmbeddedObj& arceo)
95 assert(
is_null(arceo.arcp_pod_));
100 ArrayRCP<T1> arcp_pod_;
104 if (arcp_pod_.strong_count() == 1) {
105 ArrayRCP<T2> arcp2 = arcp_reinterpret_cast<T2>(arcp_pod_);
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 124 : ptr_(NULL), lowerOffset_(0), upperOffset_(-1)
128 template<
class T>
inline 130 : ptr_(0), lowerOffset_(0), upperOffset_(-1)
133 std::fill_n(begin(), n, val);
136 template<
class T>
inline 138 : ptr_(0), lowerOffset_(0), upperOffset_(-1)
143 *
this = arcp_const_cast<
const T> (nonconstArray);
147 template<
class T>
inline 153 #ifndef TEUCHOS_DEBUG
154 node_(ArrayRCP_createNewRCPNodeRawPtr(p, has_ownership_in)),
156 lowerOffset_(lowerOffset_in),
157 upperOffset_(size_in + lowerOffset_in - 1)
162 if (!has_ownership_in && rcpNodeLookup==RCP_ENABLE_NODE_LOOKUP) {
163 existing_RCPNode = RCPNodeTracer::getExistingRCPNode(p);
165 if (existing_RCPNode) {
180 #else // NOT TEUCHOS_DEBUG 181 (void) rcpNodeLookup;
182 #endif // TEUCHOS_DEBUG 185 template<
class T>
inline 187 ArrayRCP (
const T* p, size_type lowerOffset_in, size_type size_in,
190 #ifndef TEUCHOS_DEBUG
191 node_(ArrayRCP_createNewRCPNodeRawPtr(p, has_ownership_in)),
193 lowerOffset_(lowerOffset_in),
194 upperOffset_(size_in + lowerOffset_in - 1)
199 if (! has_ownership_in && rcpNodeLookup == RCP_ENABLE_NODE_LOOKUP) {
200 existing_RCPNode = RCPNodeTracer::getExistingRCPNode (p);
202 if (existing_RCPNode) {
204 node_ = RCPNodeHandle(existing_RCPNode, RCP_WEAK,
false);
208 RCPNodeThrowDeleter nodeDeleter (ArrayRCP_createNewRCPNodeRawPtr (p, has_ownership_in));
209 node_ = RCPNodeHandle(
214 nodeDeleter.release ();
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
232 node_(ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in)),
234 lowerOffset_(lowerOffset_in),
235 upperOffset_(size_in + lowerOffset_in - 1)
240 ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in),
246 #endif // TEUCHOS_DEBUG 250 template<
class Dealloc_T>
253 const T* p, size_type lowerOffset_in, size_type size_in,
254 Dealloc_T dealloc,
bool has_ownership_in
257 #ifndef TEUCHOS_DEBUG
258 node_(ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in)),
260 lowerOffset_(lowerOffset_in),
261 upperOffset_(size_in + lowerOffset_in - 1)
266 ArrayRCP_createNewDeallocRCPNodeRawPtr(p, dealloc, has_ownership_in),
272 #endif // TEUCHOS_DEBUG 276 template<
class T>
inline 280 lowerOffset_(r_ptr.lowerOffset_),
281 upperOffset_(r_ptr.upperOffset_)
284 template<
class T>
inline 288 lowerOffset_(r_ptr.lowerOffset_),
289 upperOffset_(r_ptr.upperOffset_)
293 template<
class T>
inline 296 template<
class T>
inline 300 template<
class T>
inline 305 node_ = r_ptr.access_private_node();
307 lowerOffset_ = r_ptr.lowerOffset_;
308 upperOffset_ = r_ptr.upperOffset_;
314 template<
class T>
inline 318 if (
this == &r_ptr) {
321 node_ = r_ptr.access_private_node ();
323 lowerOffset_ = r_ptr.lowerOffset_;
324 upperOffset_ = r_ptr.upperOffset_;
334 template<
class T>
inline 339 template<
class T>
inline 345 template<
class T>
inline 348 debug_assert_valid_ptr();
349 debug_assert_in_range(0,1);
353 template<
class T>
inline 356 debug_assert_valid_ptr();
357 debug_assert_in_range(0,1);
362 template<
class T>
inline 365 debug_assert_valid_ptr();
366 debug_assert_in_range(0,1);
370 template<
class T>
inline 373 debug_assert_valid_ptr();
374 debug_assert_in_range(0,1);
379 template<
class T>
inline 383 debug_assert_valid_ptr();
384 debug_assert_in_range(0,1);
389 template<
class T>
inline 393 debug_assert_valid_ptr();
394 debug_assert_in_range(0,1);
400 template<
class T>
inline 405 template<
class T>
inline 411 template<
class T>
inline 414 debug_assert_valid_ptr();
415 debug_assert_in_range(offset,1);
419 template<
class T>
inline 422 debug_assert_valid_ptr();
423 debug_assert_in_range(offset,1);
431 template<
class T>
inline 434 debug_assert_valid_ptr();
441 template<
class T>
inline 444 debug_assert_valid_ptr();
452 template<
class T>
inline 455 debug_assert_valid_ptr();
461 template<
class T>
inline 464 debug_assert_valid_ptr();
471 template<
class T>
inline 474 debug_assert_valid_ptr();
481 template<
class T>
inline 484 debug_assert_valid_ptr();
492 template<
class T>
inline 495 debug_assert_valid_ptr();
501 template<
class T>
inline 504 debug_assert_valid_ptr();
511 template<
class T>
inline 514 debug_assert_valid_ptr();
516 lowerOffset_ -= offset;
517 upperOffset_ -= offset;
521 template<
class T>
inline 524 debug_assert_valid_ptr();
526 lowerOffset_ -= offset;
527 upperOffset_ -= offset;
532 template<
class T>
inline 535 debug_assert_valid_ptr();
537 lowerOffset_ += offset;
538 upperOffset_ += offset;
542 template<
class T>
inline 545 debug_assert_valid_ptr();
547 lowerOffset_ += offset;
548 upperOffset_ += offset;
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 593 debug_assert_valid_ptr();
594 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 601 template<
class T>
inline 604 debug_assert_valid_ptr();
605 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 613 template<
class T>
inline 616 debug_assert_valid_ptr();
617 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 618 return *
this + (upperOffset_ + 1);
620 return ptr_ + (upperOffset_ + 1);
624 template<
class T>
inline 627 debug_assert_valid_ptr();
628 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 629 return *
this + (upperOffset_ + 1);
631 return ptr_ + (upperOffset_ + 1);
639 template<
class T>
inline 643 debug_assert_valid_ptr();
644 const T *cptr = ptr_;
650 template<
class T>
inline 657 template<
class T>
inline 664 debug_assert_valid_ptr();
665 debug_assert_in_range(lowerOffset_in, size_in);
667 ptr.ptr_ =
ptr.ptr_ + lowerOffset_in;
668 ptr.lowerOffset_ = 0;
669 ptr.upperOffset_ = size_in - 1;
673 template<
class T>
inline 680 debug_assert_valid_ptr();
681 debug_assert_in_range(lowerOffset_in, size_in);
682 ArrayRCP<const T>
ptr = *
this;
683 ptr.ptr_ =
ptr.ptr_ + lowerOffset_in;
684 ptr.lowerOffset_ = 0;
685 ptr.upperOffset_ = size_in - 1;
693 template<
class T>
inline 694 typename ArrayRCP<T>::size_type
697 debug_assert_valid_ptr();
701 template<
class T>
inline 705 debug_assert_valid_ptr();
710 template<
class T>
inline 711 typename ArrayRCP<T>::size_type
714 debug_assert_valid_ptr();
718 template<
class T>
inline 722 debug_assert_valid_ptr();
727 template<
class T>
inline 728 typename ArrayRCP<T>::size_type
731 debug_assert_valid_ptr();
732 return upperOffset_ - lowerOffset_ + 1;
735 template<
class T>
inline 739 debug_assert_valid_ptr();
740 return upperOffset_ - lowerOffset_ + 1;
747 template<
class T>
inline 753 debug_assert_valid_ptr();
754 debug_assert_in_range(lowerOffset_in,size_in);
755 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 756 return ArrayView<T>(persistingView(lowerOffset_in, size_in).create_weak());
758 return arrayView(ptr_ + lowerOffset_in, size_in);
763 template<
class T>
inline 770 debug_assert_valid_ptr();
771 debug_assert_in_range(lowerOffset_in,size_in);
772 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 773 return ArrayView<const T>(persistingView(lowerOffset_in, size_in).create_weak());
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 799 return view(lowerOffset_,
size());
804 template<
class T>
inline 808 return view(lowerOffset_,
size());
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 890 const size_type orig_n =
size ();
892 ArrayRCP<const T> tmp = *
this;
896 ArrayRCP<T> nonconstThis = arcp<T> (n);
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];
901 for (size_type i = orig_n; i < n; ++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) {
931 assign(av.begin(), av.end());
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 1034 debug_assert_valid_ptr();
1035 node_.has_ownership(
false);
1039 template<
class T>
inline 1042 debug_assert_valid_ptr();
1043 node_.has_ownership(
false);
1048 template<
class T>
inline 1050 debug_assert_valid_ptr ();
1051 return ArrayRCP<T> (ptr_, lowerOffset_,
size (), node_.create_weak ());
1054 template<
class T>
inline 1056 debug_assert_valid_ptr ();
1061 template<
class T>
inline 1063 debug_assert_valid_ptr ();
1064 return ArrayRCP<T> (ptr_, lowerOffset_,
size (), node_.create_strong ());
1067 template<
class T>
inline 1069 debug_assert_valid_ptr ();
1079 return node_.same_node (r_ptr.access_private_node ());
1090 return node_.same_node (r_ptr.access_private_node ());
1100 template<
class T>
inline 1109 template<
class T>
inline 1120 template<
class T>
inline 1129 template<
class T>
inline 1139 template<
class T>
inline 1146 (lowerOffset_ <= lowerOffset_in && lowerOffset_in+size_in-1 <= upperOffset_)
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" 1154 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!" 1159 template<
class T>
inline 1167 (lowerOffset_ <= lowerOffset_in && lowerOffset_in+size_in-1 <= upperOffset_)
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" 1175 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!" 1184 template<
class T>
inline 1186 return node_.
count();
1189 template<
class T>
inline 1191 return node_.
count();
1198 template<
class T>
inline 1199 ArrayRCP<T>::ArrayRCP(
1200 T* p, size_type lowerOffset_in, size_type size_in,
1201 const RCPNodeHandle& node
1205 lowerOffset_(lowerOffset_in),
1206 upperOffset_(size_in + lowerOffset_in - 1)
1209 template<
class T>
inline 1210 ArrayRCP<const T>::ArrayRCP(
1211 const T* p, size_type lowerOffset_in, size_type size_in,
1212 const RCPNodeHandle& node
1216 lowerOffset_(lowerOffset_in),
1217 upperOffset_(size_in + lowerOffset_in - 1)
1221 template<
class T>
inline 1222 T* ArrayRCP<T>::access_private_ptr()
const 1227 template<
class T>
inline 1228 const T* ArrayRCP<const T>::access_private_ptr ()
const 1234 template<
class T>
inline 1235 RCPNodeHandle& ArrayRCP<T>::nonconst_access_private_node()
1240 template<
class T>
inline 1241 RCPNodeHandle& ArrayRCP<const T>::nonconst_access_private_node()
1247 template<
class T>
inline 1248 const RCPNodeHandle& ArrayRCP<T>::access_private_node()
const 1253 template<
class T>
inline 1254 const RCPNodeHandle& ArrayRCP<const T>::access_private_node()
const 1283 namespace Utilities {
1284 template<
class T1,
class T2>
1285 inline void assert_shares_resource(
1286 const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2
1289 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 1291 !p1.shares_resource(p2), IncompatibleIteratorsError,
1292 "Error, these iterators are *not* pointing to the same valid memory!" 1300 template<
class T>
inline 1303 T* p,
typename ArrayRCP<T>::size_type lowerOffset
1304 ,
typename ArrayRCP<T>::size_type size_in
1308 return ArrayRCP<T>(p, lowerOffset, size_in, owns_mem);
1312 template<
class T,
class Dealloc_T>
1316 T* p,
typename ArrayRCP<T>::size_type lowerOffset
1317 ,
typename ArrayRCP<T>::size_type size_in
1318 ,Dealloc_T dealloc,
bool owns_mem
1321 return ArrayRCP<T>(p, lowerOffset, size_in, dealloc, owns_mem);
1325 template<
class T>
inline 1327 Teuchos::arcp(
typename ArrayRCP<T>::size_type
size )
1329 #ifdef TEUCHOS_DEBUG 1335 return ArrayRCP<T>(
new T[
size], 0,
size,
true);
1339 template<
class T>
inline 1341 Teuchos::arcpCloneNode(
const ArrayRCP<T> &a)
1351 template<
class T>
inline 1353 Teuchos::arcpClone(
const ArrayView<const T> &v )
1355 const ArrayRCP<T> new_arcp = arcp<T>(v.size());
1356 std::copy( v.begin(), v.end(), new_arcp.begin() );
1361 template<
class T,
class Embedded>
1363 Teuchos::arcpWithEmbeddedObjPreDestroy(
1365 typename ArrayRCP<T>::size_type lowerOffset,
1366 typename ArrayRCP<T>::size_type
size,
1367 const Embedded &embedded,
1372 p, lowerOffset,
size,
1373 embeddedObjDeallocArrayDelete<T>(embedded, PRE_DESTROY),
1379 template<
class T,
class Embedded>
1381 Teuchos::arcpWithEmbeddedObjPostDestroy(
1383 typename ArrayRCP<T>::size_type lowerOffset,
1384 typename ArrayRCP<T>::size_type
size,
1385 const Embedded &embedded,
1390 p, lowerOffset,
size,
1391 embeddedObjDeallocArrayDelete<T>(embedded, POST_DESTROY),
1397 template<
class T,
class Embedded>
1399 Teuchos::arcpWithEmbeddedObj(
1401 typename ArrayRCP<T>::size_type lowerOffset,
1402 typename ArrayRCP<T>::size_type
size,
1403 const Embedded &embedded,
1407 return arcpWithEmbeddedObjPostDestroy<T,Embedded>(
1408 p, lowerOffset,
size, embedded, owns_mem );
1412 template<
class T>
inline 1414 Teuchos::arcp(
const RCP<std::vector<T> > &v )
1416 if (
is_null(v) || !v->size() )
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 )
1429 if (
is_null(v) || !v->size() )
1431 return arcpWithEmbeddedObjPostDestroy<const T,RCP<const std::vector<T> > >(
1432 &(*v)[0], 0, v->size(),
1438 template<
class T>
inline 1440 Teuchos::arcpFromArrayView(
const ArrayView<T> &av)
1442 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 1443 return av.access_private_arcp();
1445 return arcp(av.getRawPtr(), 0, av.size(),
false);
1450 template<
class T>
inline 1452 Teuchos::get_std_vector(
const ArrayRCP<T> &
ptr )
1454 return getEmbeddedObj<T, RCP<std::vector<T> > >(
ptr);
1458 template<
class T>
inline 1460 Teuchos::get_std_vector(
const ArrayRCP<const T> &
ptr )
1462 return getEmbeddedObj<const T, RCP<const std::vector<T> > >(
ptr);
1466 template<
class T>
inline 1473 template<
class T>
inline 1476 return !p.is_null();
1480 template<
class T>
inline 1481 bool Teuchos::operator==(
const ArrayRCP<T> &p,
ENull )
1487 template<
class T>
inline 1488 bool Teuchos::operator!=(
const ArrayRCP<T> &p,
ENull )
1490 return !p.is_null();
1494 template<
class T1,
class T2>
1496 bool Teuchos::operator==(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1498 return p1.access_private_ptr() == p2.access_private_ptr();
1502 template<
class T1,
class T2>
1504 bool Teuchos::operator!=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
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 )
1522 Utilities::assert_shares_resource(p1,p2);
1523 return p1.access_private_ptr() <= p2.access_private_ptr();
1527 template<
class T1,
class T2>
1529 bool Teuchos::operator>(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1531 Utilities::assert_shares_resource(p1,p2);
1532 return p1.access_private_ptr() > p2.access_private_ptr();
1536 template<
class T1,
class T2>
1538 bool Teuchos::operator>=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1540 Utilities::assert_shares_resource(p1,p2);
1541 return p1.access_private_ptr() >= p2.access_private_ptr();
1547 Teuchos::operator-(
const ArrayRCP<T> &p1,
const ArrayRCP<T> &p2 )
1549 Utilities::assert_shares_resource(p1,p2);
1550 return p1.access_private_ptr() - p2.access_private_ptr();
1554 template<
class T2,
class T1>
1557 Teuchos::arcp_reinterpret_cast(
const ArrayRCP<T1>& p1)
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());
1565 return ArrayRCP<T2>(
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)
1577 typedef typename ArrayRCP<T2>::iterator itr_t;
1579 for (itr_t itr = arcp2.begin(); itr != arcp2.end(); ++itr) {
1580 new (&*itr) T2(val);
1583 arcp2.getRawPtr(), 0, arcp2.size(),
1584 ArcpReinterpretCastEmbeddedObj<T2, T1>(p1),
1592 template<
class T2,
class T1>
1595 Teuchos::arcp_const_cast(
const ArrayRCP<T1>& p1)
1597 T2 *ptr2 =
const_cast<T2*
>(p1.get());
1598 return ArrayRCP<T2>(
1599 ptr2, p1.lowerOffset(), p1.size(),
1600 p1.access_private_node()
1606 template<
class T2,
class T1>
1609 Teuchos::arcp_implicit_cast(
const ArrayRCP<T1>& p1)
1611 T2 * raw_ptr2 = p1.
get();
1612 return ArrayRCP<T2>(
1613 raw_ptr2, p1.lowerOffset(), p1.size(),
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,
1628 p->assert_not_null();
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 )
1638 p.assert_not_null();
1640 p.nonconst_access_private_node().get_extra_data(
1641 TypeNameTraits<T1>::name(), name
1647 template<
class T1,
class T2>
1649 const T1& Teuchos::get_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
1651 p.assert_not_null();
1653 p.access_private_node().get_extra_data(
1654 TypeNameTraits<T1>::name() ,name
1660 template<
class T1,
class T2>
1662 T1* Teuchos::get_optional_extra_data( ArrayRCP<T2>& p,
const std::string& name )
1664 p.assert_not_null();
1665 any *extra_data = p.nonconst_access_private_node().get_optional_extra_data(
1666 TypeNameTraits<T1>::name(), 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 )
1676 p.assert_not_null();
1677 any *extra_data = p.access_private_node().get_optional_extra_data(
1678 TypeNameTraits<T1>::name(), name);
1679 if( extra_data )
return &
any_cast<T1>(*extra_data);
1684 template<
class Dealloc_T,
class T>
1687 Teuchos::get_dealloc(
const ArrayRCP<T>& p )
1689 return get_nonconst_dealloc<Dealloc_T>(p);
1693 template<
class Dealloc_T,
class T>
1698 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T> requested_type;
1700 RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1701 *dnode =
dynamic_cast<RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>*
>(
1702 p.access_private_node().node_ptr());
1704 dnode==NULL, NullReferenceError
1705 ,
"get_dealloc<" << TypeNameTraits<Dealloc_T>::name()
1706 <<
"," << TypeNameTraits<T>::name() <<
">(p): " 1707 <<
"Error, requested type \'" << TypeNameTraits<requested_type>::name()
1708 <<
"\' does not match actual type of the node \'" 1709 <<
typeName(*p.access_private_node().node_ptr()) <<
"!" 1711 return dnode->get_nonconst_dealloc();
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>
1730 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1732 RCPNT *dnode =
dynamic_cast<RCPNT*
>(p.access_private_node().node_ptr());
1734 return &dnode->get_nonconst_dealloc();
1739 template<
class TOrig,
class Embedded,
class T>
1740 const Embedded& Teuchos::getEmbeddedObj(
const ArrayRCP<T>& p )
1742 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1743 return get_dealloc<Dealloc_t>(p).getObj();
1747 template<
class TOrig,
class Embedded,
class T>
1748 Embedded& Teuchos::getNonconstEmbeddedObj(
const ArrayRCP<T>& p )
1750 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1751 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
1756 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayRCP<T>& p )
1764 << TypeNameTraits<ArrayRCP<T> >::name() <<
"{" 1766 if (p.access_private_ptr () == NULL) {
1769 out << (
const void*) (p.access_private_ptr ());
1774 <<
",size="<<p.
size()
1775 <<
",node=" << p.access_private_node ()
1787 #endif // TEUCHOS_ARRAY_RCP_HPP T * get() const
Get the raw C++ pointer to the underlying object.
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
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.
Partial specialization of ArrayRCP for const T.
Ordinal difference_type
Type representing the difference between two size_type values.
size_type size() const
The total number of entries in the array.
bool nonnull(const std::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.
#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...
ValueType & any_cast(any &operand)
Used to extract the templated value held in Teuchos::any to a given value type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
const ArrayRCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
void release()
Releaes the RCPNode pointer before the destructor is called.
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object...
TEUCHOS_DEPRECATED int count() const
Returns strong_count() [deprecated].
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
const ArrayRCP< T > & assert_valid_ptr() const
If the object pointer is non-null, assert that it is still valid.
Node class to keep track of address and the reference count for a reference-counted utility class and...
bool has_ownership() const
Returns true if this has ownership of object pointed to by this->get() in order to deallocate it...
int total_count() const
Total count (strong_count() + weak_count()).
bool is_valid_ptr() const
Return whether the underlying object pointer is still valid.
ERCPStrength
Used to specify if the pointer is weak or strong.
size_type upperOffset() const
Return the upper offset to valid data.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
int weak_count() const
Return the number of active RCP<> objects that have a "weak" reference to the underlying reference-co...
ERCPStrength strength() const
Strength of the pointer.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Handle class that manages the RCPNode's reference counting.
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
EPrePostDestruction
Used to specify a pre or post destruction of extra data.
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*.
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.
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.
Partial specialization of ArrayView for const T.
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 ...
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
size_type lowerOffset() const
Return the lower offset to valid data.
Definition of Teuchos::as, for conversions between types.
#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...
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
Reference-counted smart pointer for managing arrays.