731template<
class T>
inline
738 debug_assert_valid_ptr();
740#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
749template<
class T>
inline
755template<
class T>
inline
763template<
class T>
inline
767 return view(lowerOffset_, size());
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);
818 if (
new_n != size ()) {
821 std::copy (first,
last, begin ());
825template<
class T>
inline
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;
872 *
this = arcp_const_cast<const T> (nonconstThis);
878template<
class T>
inline
883template<
class T>
inline
892template<
class T>
inline
895 if (
av.size() == 0) {
899 assign(
av.begin(),
av.end());
906template<
class T>
inline
911template<
class T>
inline
917template<
class T>
inline
925template<
class T>
inline
934template<
class T>
inline
940template<
class T>
inline
947template<
class T>
inline
953template<
class T>
inline
960template<
class T>
inline
966template<
class T>
inline
973template<
class T>
inline
979template<
class T>
inline
986template<
class T>
inline
992template<
class T>
inline
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 ();
1022template<
class T>
inline
1024 debug_assert_valid_ptr ();
1029template<
class T>
inline
1031 debug_assert_valid_ptr ();
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
1073 throw_null_ptr_error(
typeName(*
this));
1077template<
class T>
inline
1082 throw_null_ptr_error (typeName (*
this));
1088template<
class T>
inline
1097template<
class T>
inline
1107template<
class T>
inline
1119 typeName(*
this)<<
"::assert_in_range:"
1120 " Error, [lowerOffset,lowerOffset+size-1] = ["
1122 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1127template<
class T>
inline
1140 typeName (*
this) <<
"::assert_in_range:"
1141 " Error, [lowerOffset,lowerOffset+size-1] = ["
1143 " range ["<<lowerOffset_<<
","<<upperOffset_<<
"]!"
1152template<
class T>
inline
1153ArrayRCP<T>::ArrayRCP(
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,
1166 const RCPNodeHandle& node
1170 lowerOffset_(lowerOffset_in),
1171 upperOffset_(size_in + lowerOffset_in - 1)
1175template<
class T>
inline
1176T* ArrayRCP<T>::access_private_ptr()
const
1181template<
class T>
inline
1182const T* ArrayRCP<const T>::access_private_ptr ()
const
1188template<
class T>
inline
1189RCPNodeHandle& ArrayRCP<T>::nonconst_access_private_node()
1194template<
class T>
inline
1195RCPNodeHandle& ArrayRCP<const T>::nonconst_access_private_node()
1201template<
class T>
inline
1202const RCPNodeHandle& ArrayRCP<T>::access_private_node()
const
1207template<
class T>
inline
1208const RCPNodeHandle& ArrayRCP<const T>::access_private_node()
const
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
1281Teuchos::arcp(
typename ArrayRCP<T>::size_type size )
1289 return ArrayRCP<T>(
new T[size], 0, size,
true);
1293template<
class T>
inline
1295Teuchos::arcpCloneNode(
const ArrayRCP<T> &a)
1300 return arcpWithEmbeddedObj(a.getRawPtr(), a.lowerOffset(), a.size(),
1305template<
class T>
inline
1307Teuchos::arcpClone(
const ArrayView<const T> &v )
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>
1317Teuchos::arcpWithEmbeddedObjPreDestroy(
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>
1335Teuchos::arcpWithEmbeddedObjPostDestroy(
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>
1353Teuchos::arcpWithEmbeddedObj(
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
1368Teuchos::arcp(
const RCP<std::vector<T> > &v )
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
1381Teuchos::arcp(
const RCP<
const std::vector<T> > &v )
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
1394Teuchos::arcpFromArrayView(
const ArrayView<T> &av)
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
1406Teuchos::get_std_vector(
const ArrayRCP<T> &ptr )
1408 return getEmbeddedObj<T, RCP<std::vector<T> > >(ptr);
1412template<
class T>
inline
1414Teuchos::get_std_vector(
const ArrayRCP<const T> &ptr )
1416 return getEmbeddedObj<const T, RCP<const std::vector<T> > >(ptr);
1420template<
class T>
inline
1427template<
class T>
inline
1434template<
class T>
inline
1435bool Teuchos::operator==(
const ArrayRCP<T> &p, ENull )
1441template<
class T>
inline
1442bool Teuchos::operator!=(
const ArrayRCP<T> &p, ENull )
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>
1458bool Teuchos::operator!=(
const ArrayRCP<T1> &p1,
const ArrayRCP<T2> &p2 )
1460 return p1.access_private_ptr() != p2.access_private_ptr();
1464template<
class T1,
class T2>
1468 return p1.access_private_ptr() < p2.access_private_ptr();
1472template<
class T1,
class T2>
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>
1511Teuchos::arcp_reinterpret_cast(
const ArrayRCP<T1>& p1)
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>
1529Teuchos::arcp_reinterpret_cast_nonpod(
const ArrayRCP<T1>& p1,
const T2& val)
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);
1536 return arcpWithEmbeddedObj(
1537 arcp2.getRawPtr(), 0, arcp2.size(),
1538 ArcpReinterpretCastEmbeddedObj<T2, T1>(p1),
1546template<
class T2,
class T1>
1549Teuchos::arcp_const_cast(
const ArrayRCP<T1>& p1)
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>
1563Teuchos::arcp_implicit_cast(
const ArrayRCP<T1>& p1)
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>
1576void Teuchos::set_extra_data(
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>
1590T1& Teuchos::get_extra_data( ArrayRCP<T2>& p,
const std::string& name )
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>
1603const T1& Teuchos::get_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
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>
1616T1* Teuchos::get_optional_extra_data( ArrayRCP<T2>& p,
const std::string& name )
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>
1628const T1* Teuchos::get_optional_extra_data(
const ArrayRCP<T2>& p,
const std::string& name )
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>
1641Teuchos::get_dealloc(
const ArrayRCP<T>& p )
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>
1672Teuchos::get_optional_dealloc(
const ArrayRCP<T>& p )
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());
1693template<
class TOrig,
class Embedded,
class T>
1694const Embedded& Teuchos::getEmbeddedObj(
const ArrayRCP<T>& p )
1696 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1697 return get_dealloc<Dealloc_t>(p).getObj();
1701template<
class TOrig,
class Embedded,
class T>
1702Embedded& Teuchos::getNonconstEmbeddedObj(
const ArrayRCP<T>& p )
1704 typedef EmbeddedObjDealloc<TOrig,Embedded,DeallocArrayDelete<TOrig> > Dealloc_t;
1705 return get_nonconst_dealloc<Dealloc_t>(p).getNonconstObj();
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 ()