Skip to content

Commit 781b9ca

Browse files
committed
misc cleanup DistArray typedefs + dox
1 parent adb2717 commit 781b9ca

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/TiledArray/dist_array.h

+23-10
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ template <typename Tile = Tensor<double>, typename Policy = DensePolicy>
6060
class DistArray : public madness::archive::ParallelSerializableObject {
6161
public:
6262
typedef TiledArray::detail::ArrayImpl<Tile, Policy>
63-
impl_type; ///< The type of the PIMPL
63+
impl_type; ///< The type of the implementation object
64+
using pimpl_type =
65+
std::shared_ptr<impl_type>; ///< shared_ptr to implementation object
66+
using const_pimpl_type =
67+
std::shared_ptr<const impl_type>; ///< shared_ptr to const implementation
68+
///< object
6469
typedef typename impl_type::policy_type policy_type; ///< Policy type
6570

6671
/// Type used to hold the components of the tensors in the array. For
@@ -132,7 +137,7 @@ class DistArray : public madness::archive::ParallelSerializableObject {
132137
std::is_same_v<std::decay_t<Value>, value_type>;
133138

134139
private:
135-
std::shared_ptr<impl_type> pimpl_; ///< Array implementation pointer
140+
pimpl_type pimpl_; ///< managed ptr to Array implementation
136141
bool defer_deleter_to_next_fence_ =
137142
false; ///< if true, the impl object is scheduled to be destroyed in the
138143
///< next fence
@@ -202,11 +207,12 @@ class DistArray : public madness::archive::ParallelSerializableObject {
202207

203208
/// \param world The world where the array will live.
204209
/// \param trange The tiled range object that will be used to set the array
205-
/// tiling. \param shape The array shape that defines zero and non-zero tiles
210+
/// tiling.
211+
/// \param shape The array shape that defines zero and non-zero tiles
206212
/// \param pmap The tile index -> process map
207-
static std::shared_ptr<impl_type> init(
208-
World& world, const trange_type& trange, const shape_type& shape,
209-
std::shared_ptr<const pmap_interface> pmap) {
213+
static pimpl_type init(World& world, const trange_type& trange,
214+
const shape_type& shape,
215+
std::shared_ptr<const pmap_interface> pmap) {
210216
// User level validation of input
211217

212218
if (!pmap) {
@@ -239,8 +245,7 @@ class DistArray : public madness::archive::ParallelSerializableObject {
239245
"not equal to "
240246
"the tiles range.");
241247

242-
return std::shared_ptr<impl_type>(new impl_type(world, trange, shape, pmap),
243-
lazy_deleter);
248+
return pimpl_type(new impl_type(world, trange, shape, pmap), lazy_deleter);
244249
}
245250

246251
public:
@@ -441,6 +446,14 @@ class DistArray : public madness::archive::ParallelSerializableObject {
441446
*this = foreach<Tile>(other, std::forward<Op>(op));
442447
}
443448

449+
/// PIMPL "constructor"
450+
451+
/// "Constructs" an array from a shared_ptr to its implementation object.
452+
/// Since the implementation object already exists, this is a "shallow" ctor,
453+
/// in other words this object will refer to an already existing
454+
/// (possibly shared) implementation
455+
DistArray(pimpl_type pimpl) : pimpl_(std::move(pimpl)) {}
456+
444457
/// Destructor
445458

446459
/// This is a distributed lazy destructor. The object will only be deleted
@@ -481,12 +494,12 @@ class DistArray : public madness::archive::ParallelSerializableObject {
481494
/// Accessor for the (shared_ptr to) implementation object
482495

483496
/// \return std::shared_ptr to the const implementation object
484-
std::shared_ptr<const impl_type> pimpl() const { return pimpl_; }
497+
const_pimpl_type pimpl() const { return pimpl_; }
485498

486499
/// Accessor for the (shared_ptr to) implementation object
487500

488501
/// \return std::shared_ptr to the nonconst implementation object
489-
std::shared_ptr<impl_type> pimpl() { return pimpl_; }
502+
pimpl_type pimpl() { return pimpl_; }
490503

491504
/// Accessor for the (weak_ptr to) implementation object
492505

0 commit comments

Comments
 (0)