2018-02-14 21:37:18 +01:00
|
|
|
|
|
|
|
#include "ranges/anonymous_range.h"
|
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
/******************************
|
|
|
|
* AnonymousRangeFactory *
|
|
|
|
******************************/
|
2018-07-15 15:22:15 +02:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
AnonymousRangeFactory::AnonymousRangeFactory()
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange() );
|
|
|
|
}
|
|
|
|
|
2018-07-16 14:44:55 +02:00
|
|
|
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > AnonymousRangeFactory::mAleadyCreated;
|
|
|
|
|
2018-07-16 00:12:05 +02:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
2018-07-15 15:22:15 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<RangeBase> out;
|
|
|
|
bool check = false;
|
|
|
|
for(auto& x: mAleadyCreated){
|
|
|
|
if(x.second.size() == pvec.size()){
|
|
|
|
check = true;
|
2018-07-16 00:12:05 +02:00
|
|
|
for(size_t i = 0; i != x.second.size(); ++i){
|
|
|
|
if(x.second[i] != reinterpret_cast<std::intptr_t>( pvec[i].get() ) ){
|
2018-07-15 15:22:15 +02:00
|
|
|
check = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(check == true){
|
|
|
|
out = x.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(not check){
|
|
|
|
std::vector<std::intptr_t> app(pvec.size());
|
|
|
|
for(size_t i = 0; i != app.size(); ++i){
|
2018-07-16 00:12:05 +02:00
|
|
|
app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() );
|
2018-07-15 15:22:15 +02:00
|
|
|
}
|
|
|
|
mAleadyCreated[mProd] = app;
|
|
|
|
out = mProd;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
|
|
|
|
{
|
2018-07-16 00:12:05 +02:00
|
|
|
mProd = checkIfCreated(std::dynamic_pointer_cast<AnonymousRange>(mProd)->mOrig);
|
2018-07-15 15:22:15 +02:00
|
|
|
setSelf();
|
2018-07-16 14:44:55 +02:00
|
|
|
mProductCreated = true;
|
2018-02-14 21:37:18 +01:00
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
* AnonymousRange *
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
size_t AnonymousRange::get(size_t pos) const
|
|
|
|
{
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::getMeta(size_t metaPos) const
|
|
|
|
{
|
|
|
|
return metaPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::size() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::dim() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-19 21:27:09 +02:00
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
std::string AnonymousRange::stringMeta(size_t pos) const
|
|
|
|
{
|
|
|
|
std::string out = "[ ";
|
|
|
|
size_t xpos = pos;
|
|
|
|
for(size_t i = mOrig.size(); i != 0; --i) {
|
|
|
|
auto& x = mOrig[i-1];
|
|
|
|
const size_t redpos = pos % x->size();
|
|
|
|
out = ( (i == mOrig.size()) ? out : out + " , " ) + x->stringMeta(redpos);
|
|
|
|
xpos -= redpos;
|
|
|
|
}
|
|
|
|
out += " ]";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> AnonymousRange::data() const
|
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::ANON );
|
|
|
|
h.metaSize = mOrig.size();
|
|
|
|
h.multiple = 1;
|
|
|
|
std::vector<char> out;
|
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
|
|
|
for(auto& x: mOrig){
|
|
|
|
auto part = x->data();
|
|
|
|
out.insert(out.end(), part.begin(), part.end());
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:27:09 +02:00
|
|
|
size_t AnonymousRange::anonymousDim() const
|
|
|
|
{
|
|
|
|
return mOrig.size();
|
|
|
|
}
|
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
typename AnonymousRange::IndexType AnonymousRange::begin() const
|
|
|
|
{
|
|
|
|
AnonymousIndex i
|
2018-07-16 15:55:55 +02:00
|
|
|
(std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
( std::shared_ptr<RangeBase>(RB::mThis) ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
typename AnonymousRange::IndexType AnonymousRange::end() const
|
|
|
|
{
|
|
|
|
AnonymousIndex i
|
2018-07-16 15:55:55 +02:00
|
|
|
(std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
( std::shared_ptr<RangeBase>(RB::mThis) ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
2018-04-28 17:33:57 +02:00
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
|
2018-04-28 17:33:57 +02:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRange::sub(size_t num) const
|
|
|
|
{
|
|
|
|
return mOrig.at(num);
|
|
|
|
}
|
2018-02-14 21:37:18 +01:00
|
|
|
|
|
|
|
/*****************
|
|
|
|
* Functions *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
std::shared_ptr<AnonymousRange> defaultRange(size_t size )
|
|
|
|
{
|
|
|
|
AnonymousRangeFactory arf
|
2018-07-16 15:55:55 +02:00
|
|
|
( std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
(AnonymousRange::factory().create() ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
|
|
|
}
|
2018-07-16 00:12:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
} // end namespace MultiArrayTools
|