fix leak issue
This commit is contained in:
parent
d2a1286d17
commit
7a16f22f78
5 changed files with 159 additions and 124 deletions
|
@ -10,76 +10,6 @@ namespace MultiArrayTools
|
|||
using namespace MultiArrayHelper;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* ContainerRangeFactory *
|
||||
*****************************/
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRangeFactory<Ranges...>::ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
||||
{
|
||||
mProd = std::make_shared<ContainerRange<Ranges...> >( rs... );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRangeFactory<Ranges...>::
|
||||
ContainerRangeFactory(const typename ContainerRange<Ranges...>::SpaceType& space)
|
||||
{
|
||||
mProd = std::make_shared<ContainerRange<Ranges...> >( space );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> ContainerRangeFactory<Ranges...>::create()
|
||||
{
|
||||
setSelf();
|
||||
return mProd;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* ContainerRange *
|
||||
**********************/
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRange<Ranges...>::ContainerRange(const std::shared_ptr<Ranges>&... rs) :
|
||||
mSpace( std::make_tuple( rs... ) ) {}
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRange<Ranges...>::ContainerRange(const SpaceType& space) : mSpace( space ) {}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t ContainerRange<Ranges...>::dim() const
|
||||
{
|
||||
return sizeof...(Ranges);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t ContainerRange<Ranges...>::size() const
|
||||
{
|
||||
return PackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::end() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<IndexBase> ContainerRange<Ranges...>::index() const
|
||||
{
|
||||
return std::make_shared<ContainerIndex<typename Ranges::IndexType...> >
|
||||
( std::dynamic_pointer_cast<ContainerRange<Ranges...> >( RB::mThis ) );
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* ContainerIndex *
|
||||
|
@ -113,6 +43,9 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator++()
|
||||
{
|
||||
if(mExternControl){
|
||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
PackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++IB::mPos;
|
||||
return *this;
|
||||
|
@ -121,6 +54,9 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator--()
|
||||
{
|
||||
if(mExternControl){
|
||||
IB::mPos = PackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
}
|
||||
PackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--IB::mPos;
|
||||
return *this;
|
||||
|
@ -165,6 +101,19 @@ namespace MultiArrayTools
|
|||
return IB::mPos;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool ContainerIndex<Indices...>::first() const
|
||||
{
|
||||
return pos() == 0;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
bool ContainerIndex<Indices...>::last() const
|
||||
{
|
||||
return pos() == IB::mRangePtr->size() - 1;
|
||||
}
|
||||
|
||||
|
||||
template <class... Indices>
|
||||
ContainerIndex<Indices...>& ContainerIndex<Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
||||
{
|
||||
|
@ -173,4 +122,77 @@ namespace MultiArrayTools
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* ContainerRangeFactory *
|
||||
*****************************/
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRangeFactory<Ranges...>::ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
||||
{
|
||||
mProd = std::shared_ptr<ContainerRange<Ranges...> >( new ContainerRange<Ranges...>( rs... ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRangeFactory<Ranges...>::
|
||||
ContainerRangeFactory(const typename ContainerRange<Ranges...>::SpaceType& space)
|
||||
{
|
||||
mProd = std::shared_ptr<ContainerRange<Ranges...> >( new ContainerRange<Ranges...>( space ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> ContainerRangeFactory<Ranges...>::create()
|
||||
{
|
||||
setSelf();
|
||||
return mProd;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* ContainerRange *
|
||||
**********************/
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRange<Ranges...>::ContainerRange(const std::shared_ptr<Ranges>&... rs) :
|
||||
mSpace( std::make_tuple( rs... ) ) {}
|
||||
|
||||
template <class... Ranges>
|
||||
ContainerRange<Ranges...>::ContainerRange(const SpaceType& space) : mSpace( space ) {}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t ContainerRange<Ranges...>::dim() const
|
||||
{
|
||||
return sizeof...(Ranges);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t ContainerRange<Ranges...>::size() const
|
||||
{
|
||||
return PackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::begin() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
typename ContainerRange<Ranges...>::IndexType ContainerRange<Ranges...>::end() const
|
||||
{
|
||||
ContainerIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<IndexBase> ContainerRange<Ranges...>::index() const
|
||||
{
|
||||
return std::make_shared<ContainerIndex<typename Ranges::IndexType...> >
|
||||
( std::dynamic_pointer_cast<ContainerRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
}
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
|
|
@ -14,6 +14,47 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class... Indices>
|
||||
class ContainerIndex : public IndexInterface<std::tuple<decltype(Indices().meta())...> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef IndexInterface<std::tuple<decltype(Indices().meta())...> > IndexI;
|
||||
|
||||
protected:
|
||||
bool mExternControl = false;
|
||||
IndexPack mIPack;
|
||||
|
||||
public:
|
||||
ContainerIndex() = default;
|
||||
|
||||
ContainerIndex(const ContainerIndex& in);
|
||||
ContainerIndex& operator=(const ContainerIndex& in);
|
||||
|
||||
template <class MRange>
|
||||
ContainerIndex(const std::shared_ptr<MRange>& range);
|
||||
|
||||
virtual ContainerIndex& operator++() override;
|
||||
virtual ContainerIndex& operator--() override;
|
||||
virtual ContainerIndex& operator=(size_t pos) override;
|
||||
|
||||
virtual MetaType meta() const override;
|
||||
virtual ContainerIndex& at(const MetaType& metaPos) override;
|
||||
|
||||
virtual bool first() const override;
|
||||
virtual bool last() const override;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
virtual size_t pos() const override; // recalculate when externalControl == true
|
||||
|
||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class... Ranges>
|
||||
class ContainerRangeFactory : public RangeFactoryBase
|
||||
{
|
||||
|
@ -40,6 +81,17 @@ namespace MultiArrayTools
|
|||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
||||
typedef typename RangeInterface<ContainerIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||
|
||||
protected:
|
||||
ContainerRange() = default;
|
||||
ContainerRange(const ContainerRange& in) = delete;
|
||||
ContainerRange& operator=(const ContainerRange& in) = delete;
|
||||
|
||||
ContainerRange(const std::shared_ptr<Ranges>&... rs);
|
||||
ContainerRange(const SpaceType& space);
|
||||
|
||||
SpaceType mSpace;
|
||||
|
||||
public:
|
||||
static const size_t sdim = sizeof...(Ranges);
|
||||
|
||||
virtual size_t dim() const override;
|
||||
|
@ -52,51 +104,6 @@ namespace MultiArrayTools
|
|||
|
||||
friend ContainerRangeFactory<Ranges...>;
|
||||
|
||||
protected:
|
||||
|
||||
ContainerRange() = default;
|
||||
ContainerRange(const ContainerRange& in) = delete;
|
||||
|
||||
ContainerRange(const std::shared_ptr<Ranges>&... rs);
|
||||
ContainerRange(const SpaceType& space);
|
||||
|
||||
SpaceType mSpace;
|
||||
};
|
||||
|
||||
template <class... Indices>
|
||||
class ContainerIndex : public IndexInterface<std::tuple<decltype(Indices().meta())...> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef IndexBase IB;
|
||||
typedef std::tuple<decltype(Indices().meta())...> MetaType;
|
||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef IndexInterface<std::tuple<decltype(Indices().meta())...> > IndexI;
|
||||
|
||||
ContainerIndex() = default;
|
||||
|
||||
ContainerIndex(const ContainerIndex& in);
|
||||
ContainerIndex& operator=(const ContainerIndex& in);
|
||||
|
||||
template <class MRange>
|
||||
ContainerIndex(const std::shared_ptr<MRange>& range);
|
||||
|
||||
virtual ContainerIndex& operator++() override;
|
||||
virtual ContainerIndex& operator--() override;
|
||||
virtual ContainerIndex& operator=(size_t pos) override;
|
||||
|
||||
virtual MetaType meta() const override;
|
||||
virtual ContainerIndex& at(const MetaType& metaPos) override;
|
||||
|
||||
virtual size_t dim() const override;
|
||||
virtual size_t pos() const override; // recalculate when externalControl == true
|
||||
|
||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||
|
||||
protected:
|
||||
|
||||
bool mExternControl = false;
|
||||
IndexPack mIPack;
|
||||
};
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
|
|
|
@ -204,7 +204,8 @@ namespace MultiArrayTools
|
|||
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::begin() const
|
||||
{
|
||||
MultiIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
|
@ -212,7 +213,8 @@ namespace MultiArrayTools
|
|||
typename MultiRange<Ranges...>::IndexType MultiRange<Ranges...>::end() const
|
||||
{
|
||||
MultiIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
|
@ -220,6 +222,7 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<IndexBase> MultiRange<Ranges...>::index() const
|
||||
{
|
||||
return std::make_shared<MultiIndex<typename Ranges::IndexType...> >
|
||||
( std::dynamic_pointer_cast<MultiRange<Ranges...> >( RB::mThis ) );
|
||||
( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace MultiArrayTools
|
|||
protected:
|
||||
|
||||
RangeBase() = default;
|
||||
std::shared_ptr<RangeBase> mThis;
|
||||
std::weak_ptr<RangeBase> mThis;
|
||||
};
|
||||
|
||||
template <class Index>
|
||||
|
|
|
@ -122,14 +122,16 @@ namespace MultiArrayTools
|
|||
template <typename U, RangeType TYPE>
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
return i = 0;
|
||||
}
|
||||
|
||||
template <typename U, RangeType TYPE>
|
||||
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
|
||||
{
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
return i = size();
|
||||
}
|
||||
|
||||
|
@ -138,7 +140,8 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<IndexBase> SingleRange<U,TYPE>::index() const
|
||||
{
|
||||
return std::make_shared<SingleIndex<U,TYPE> >
|
||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >( RB::mThis ) );
|
||||
( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue