763template<
class T>
inline
770 debug_assert_valid_ptr();
772#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
781template<
class T>
inline
787template<
class T>
inline
795template<
class T>
inline
799 return view(lowerOffset_, size());
804template<
class T>
inline
808 return view(lowerOffset_, size());
817template<
class T>
inline
838template<
class T>
inline
841 std::fill_n (this->begin (), n,
val);
850 if (
new_n != size ()) {
853 std::copy (first,
last, begin ());
857template<
class T>
inline
880template<
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;
904 *
this = arcp_const_cast<const T> (nonconstThis);
910template<
class T>
inline
915template<
class T>
inline
924template<
class T>
inline
927 if (
av.size() == 0) {
931 assign(
av.begin(),
av.end());
938template<
class T>
inline
943template<
class T>
inline
949template<
class T>
inline
957template<
class T>
inline
966template<
class T>
inline
972template<
class T>
inline
979template<
class T>
inline
985template<
class T>
inline
992template<
class T>
inline
998template<
class T>
inline
1005template<
class T>
inline
1011template<
class T>
inline
1018template<
class T>
inline
1024template<
class T>
inline
1031template<
class T>
inline
1034 debug_assert_valid_ptr();
1035 node_.has_ownership(
false);
1039template<
class T>
inline
1042 debug_assert_valid_ptr();
1043 node_.has_ownership(
false);
1048template<
class T>
inline
1050 debug_assert_valid_ptr ();
1054template<
class T>
inline
1056 debug_assert_valid_ptr ();
1061template<
class T>
inline
1063 debug_assert_valid_ptr ();
1067template<
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 ());
1100template<
class T>
inline
1105 throw_null_ptr_error(
typeName(*
this));
1109template<
class T>
inline
1114 throw_null_ptr_error (typeName (*
this));
1120template<
class T>
inline
1129template<
class T>
inline
1139template<
class T>
inline
1151 typeName(*
this)<<
"::assert_in_range:"
1152 " Error, [lowerOffset,lowerOffset+size-1] = ["
1154 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1159template<
class T>
inline
1172 typeName (*
this) <<
"::assert_in_range:"
1173 " Error, [lowerOffset,lowerOffset+size-1] = ["
1175 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1184template<
class T>
inline
1185ArrayRCP<T>::ArrayRCP(
1186 T* p, size_type lowerOffset_in, size_type size_in,
1187 const RCPNodeHandle& node
1191 lowerOffset_(lowerOffset_in),
1192 upperOffset_(size_in + lowerOffset_in - 1)
1195template<
class T>
inline
1197 const T* p, size_type lowerOffset_in, size_type size_in,
1198 const RCPNodeHandle& node
1202 lowerOffset_(lowerOffset_in),
1203 upperOffset_(size_in + lowerOffset_in - 1)
1207template<
class T>
inline
1208T* ArrayRCP<T>::access_private_ptr()
const
1213template<
class T>
inline
1214const T* ArrayRCP<const T>::access_private_ptr ()
const
1220template<
class T>
inline
1221RCPNodeHandle& ArrayRCP<T>::nonconst_access_private_node()
1226template<
class T>
inline
1227RCPNodeHandle& ArrayRCP<const T>::nonconst_access_private_node()
1233template<
class T>
inline
1234const RCPNodeHandle& ArrayRCP<T>::access_private_node()
const
1239template<
class T>
inline
1240const RCPNodeHandle& ArrayRCP<const T>::access_private_node()
const
1269namespace Utilities {
1270template<
class T1,
class T2>
1271inline void assert_shares_resource(
1272 const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2
1275#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1277 !p1.shares_resource(p2), IncompatibleIteratorsError,
1278 "Error, these iterators are *not* pointing to the same valid memory!"
1286template<
class T>
inline
1289T* p,
typename ArrayRCP<T>::size_type lowerOffset
1290 ,
typename ArrayRCP<T>::size_type size_in
1294 return ArrayRCP<T>(p, lowerOffset, size_in, owns_mem);
1298template<
class T,
class Dealloc_T>
1302T* p,
typename ArrayRCP<T>::size_type lowerOffset
1303 ,
typename ArrayRCP<T>::size_type size_in
1304 ,Dealloc_T dealloc,
bool owns_mem
1307 return ArrayRCP<T>(p, lowerOffset, size_in, dealloc, owns_mem);
1311template<
class T>
inline
1313Teuchos::arcp(
typename ArrayRCP<T>::size_type size )
1321 return ArrayRCP<T>(
new T[size], 0, size,
true);
1325template<
class T>
inline
1327Teuchos::arcpCloneNode(
const ArrayRCP<T> &a)
1332 return arcpWithEmbeddedObj(a.getRawPtr(), a.lowerOffset(), a.size(),
1337template<
class T>
inline
1339Teuchos::arcpClone(
const ArrayView<const T> &v )
1341 const ArrayRCP<T> new_arcp = arcp<T>(v.size());
1342 std::copy( v.begin(), v.end(), new_arcp.begin() );
1347template<
class T,
class Embedded>
1349Teuchos::arcpWithEmbeddedObjPreDestroy(
1351 typename ArrayRCP<T>::size_type lowerOffset,
1352 typename ArrayRCP<T>::size_type size,
1353 const Embedded &embedded,
1358 p, lowerOffset, size,
1359 embeddedObjDeallocArrayDelete<T>(embedded, PRE_DESTROY),
1365template<
class T,
class Embedded>
1367Teuchos::arcpWithEmbeddedObjPostDestroy(
1369 typename ArrayRCP<T>::size_type lowerOffset,
1370 typename ArrayRCP<T>::size_type size,
1371 const Embedded &embedded,
1376 p, lowerOffset, size,
1377 embeddedObjDeallocArrayDelete<T>(embedded, POST_DESTROY),
1383template<
class T,
class Embedded>
1385Teuchos::arcpWithEmbeddedObj(
1387 typename ArrayRCP<T>::size_type lowerOffset,
1388 typename ArrayRCP<T>::size_type size,
1389 const Embedded &embedded,
1393 return arcpWithEmbeddedObjPostDestroy<T,Embedded>(
1394 p, lowerOffset, size, embedded, owns_mem );
1398template<
class T>
inline
1400Teuchos::arcp(
const RCP<std::vector<T> > &v )
1402 if (
is_null(v) || !v->size() )
1404 return arcpWithEmbeddedObjPostDestroy<T,RCP<std::vector<T> > >(
1405 &(*v)[0], 0, v->size(),
1411template<
class T>
inline
1413Teuchos::arcp(
const RCP<
const std::vector<T> > &v )
1415 if (
is_null(v) || !v->size() )
1417 return arcpWithEmbeddedObjPostDestroy<const T,RCP<const std::vector<T> > >(
1418 &(*v)[0], 0, v->size(),
1424template<
class T>
inline
1426Teuchos::arcpFromArrayView(
const ArrayView<T> &av)
1428#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
1429 return av.access_private_arcp();
1431 return arcp(av.getRawPtr(), 0, av.size(),
false);
1436template<
class T>
inline
1438Teuchos::get_std_vector(
const ArrayRCP<T> &ptr )
1440 return getEmbeddedObj<T, RCP<std::vector<T> > >(ptr);
1444template<
class T>
inline
1446Teuchos::get_std_vector(
const ArrayRCP<const T> &ptr )
1448 return getEmbeddedObj<const T, RCP<const std::vector<T> > >(ptr);
1452template<
class T>
inline
1459template<
class T>
inline
1466template<
class T>
inline
1467bool Teuchos::operator==(
const ArrayRCP<T> &p, ENull )
1473template<
class T>
inline
1474bool Teuchos::operator!=(
const ArrayRCP<T> &p, ENull )
1480template<
class T1,
class T2>
1482bool Teuchos::operator==(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1484 return p1.access_private_ptr() == p2.access_private_ptr();
1488template<
class T1,
class T2>
1490bool Teuchos::operator!=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1492 return p1.access_private_ptr() != p2.access_private_ptr();
1496template<
class T1,
class T2>
1500 return p1.access_private_ptr() < p2.access_private_ptr();
1504template<
class T1,
class T2>
1508 Utilities::assert_shares_resource(p1,p2);
1509 return p1.access_private_ptr() <= p2.access_private_ptr();
1513template<
class T1,
class T2>
1515bool Teuchos::operator>(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1517 Utilities::assert_shares_resource(p1,p2);
1518 return p1.access_private_ptr() > p2.access_private_ptr();
1522template<
class T1,
class T2>
1524bool Teuchos::operator>=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1526 Utilities::assert_shares_resource(p1,p2);
1527 return p1.access_private_ptr() >= p2.access_private_ptr();
1533Teuchos::operator-(
const ArrayRCP<T> &p1,
const ArrayRCP<T> &p2 )
1535 Utilities::assert_shares_resource(p1,p2);
1536 return p1.access_private_ptr() - p2.access_private_ptr();
1540template<
class T2,
class T1>
1543Teuchos::arcp_reinterpret_cast(
const ArrayRCP<T1>& p1)
1545 typedef typename ArrayRCP<T1>::size_type size_type;
1546 const int sizeOfT1 =
sizeof(T1);
1547 const int sizeOfT2 =
sizeof(T2);
1548 size_type lowerOffset2 = (p1.lowerOffset()*sizeOfT1) / sizeOfT2;
1549 size_type upperOffset2 = ((p1.upperOffset()+1)*sizeOfT1) / sizeOfT2 - 1;
1550 T2 *ptr2 =
reinterpret_cast<T2*
>(p1.get());
1551 return ArrayRCP<T2>(
1552 ptr2, lowerOffset2, upperOffset2 - lowerOffset2 + 1,
1553 p1.access_private_node()
1559template<
class T2,
class T1>
1561Teuchos::arcp_reinterpret_cast_nonpod(
const ArrayRCP<T1>& p1,
const T2& val)
1563 typedef typename ArrayRCP<T2>::iterator itr_t;
1564 ArrayRCP<T2> arcp2 = arcp_reinterpret_cast<T2>(p1);
1565 for (itr_t itr = arcp2.begin(); itr != arcp2.end(); ++itr) {
1566 new (&*itr) T2(val);
1568 return arcpWithEmbeddedObj(
1569 arcp2.getRawPtr(), 0, arcp2.size(),
1570 ArcpReinterpretCastEmbeddedObj<T2, T1>(p1),
1578template<
class T2,
class T1>
1581Teuchos::arcp_const_cast(
const ArrayRCP<T1>& p1)
1583 T2 *ptr2 =
const_cast<T2*
>(p1.get());
1584 return ArrayRCP<T2>(
1585 ptr2, p1.lowerOffset(), p1.size(),
1586 p1.access_private_node()
1592template<
class T2,
class T1>
1595Teuchos::arcp_implicit_cast(
const ArrayRCP<T1>& p1)
1597 T2 * raw_ptr2 = p1.
get();
1598 return ArrayRCP<T2>(
1599 raw_ptr2, p1.lowerOffset(), p1.size(),
1600 p1.access_private_node()
1606template<
class T1,
class T2>
1608void Teuchos::set_extra_data(
1609 const T1 &extra_data,
const std::string& name,
1610 const Ptr<ArrayRCP<T2> > &p, EPrePostDestruction destroy_when,
1614 p->assert_not_null();
1615 p->nonconst_access_private_node().set_extra_data( any(extra_data), name, destroy_when,
1620template<
class T1,
class T2>
1622T1& Teuchos::get_extra_data( ArrayRCP<T2>& p,
const std::string& name )
1624 p.assert_not_null();
1625 return any_cast<T1>(
1626 p.nonconst_access_private_node().get_extra_data(
1627 TypeNameTraits<T1>::name(), name
1633template<
class T1,
class T2>
1635const T1& Teuchos::get_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
1637 p.assert_not_null();
1638 return any_cast<T1>(
1639 p.access_private_node().get_extra_data(
1640 TypeNameTraits<T1>::name() ,name
1646template<
class T1,
class T2>
1648T1* Teuchos::get_optional_extra_data( ArrayRCP<T2>& p,
const std::string& name )
1650 p.assert_not_null();
1651 any *extra_data = p.nonconst_access_private_node().get_optional_extra_data(
1652 TypeNameTraits<T1>::name(), name);
1653 if( extra_data )
return &any_cast<T1>(*extra_data);
1658template<
class T1,
class T2>
1660const T1* Teuchos::get_optional_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
1662 p.assert_not_null();
1663 any *extra_data = p.access_private_node().get_optional_extra_data(
1664 TypeNameTraits<T1>::name(), name);
1665 if( extra_data )
return &any_cast<T1>(*extra_data);
1670template<
class Dealloc_T,
class T>
1673Teuchos::get_dealloc(
const ArrayRCP<T>& p )
1675 return get_nonconst_dealloc<Dealloc_T>(p);
1679template<
class Dealloc_T,
class T>
1684 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T> requested_type;
1686 RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1687 *dnode =
dynamic_cast<RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>*
>(
1688 p.access_private_node().node_ptr());
1690 dnode==NULL, NullReferenceError
1691 ,
"get_dealloc<" << TypeNameTraits<Dealloc_T>::name()
1692 <<
"," << TypeNameTraits<T>::name() <<
">(p): "
1693 <<
"Error, requested type \'" << TypeNameTraits<requested_type>::name()
1694 <<
"\' does not match actual type of the node \'"
1695 <<
typeName(*p.access_private_node().node_ptr()) <<
"!"
1697 return dnode->get_nonconst_dealloc();
1701template<
class Dealloc_T,
class T>
1704Teuchos::get_optional_dealloc(
const ArrayRCP<T>& p )
1706 return get_optional_dealloc<Dealloc_T>(p);
1710template<
class Dealloc_T,
class T>
1716 typedef RCPNodeTmpl<typename Dealloc_T::ptr_t,Dealloc_T>
1718 RCPNT *dnode =
dynamic_cast<RCPNT*
>(p.access_private_node().node_ptr());
1725template<
class TOrig,
class Embedded,
class T>
1726const Embedded& Teuchos::getEmbeddedObj(
const ArrayRCP<T>& p )
1728 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1729 return get_dealloc<Dealloc_t>(p).getObj();
1733template<
class TOrig,
class Embedded,
class T>
1734Embedded& Teuchos::getNonconstEmbeddedObj(
const ArrayRCP<T>& p )
1736 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1737 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
1750 << TypeNameTraits<ArrayRCP<T> >::name() <<
"{"
1752 if (p.access_private_ptr () == NULL) {
1755 out << (
const void*) (p.access_private_ptr ());
1758 <<
",lowerOffset="<<p.lowerOffset()
1759 <<
",upperOffset="<<p.upperOffset()
1760 <<
",size="<<p.size()
1761 <<
",node=" << p.access_private_node ()