1#ifndef __FIBER_TYPEDARRAY_HPP
2#define __FIBER_TYPEDARRAY_HPP
5#include <memcore/Chunk.hpp>
6#include <eagle/PhysicalSpace.hpp>
11template <Dims_t N,
class T>
19Iterator<T> getComponentArrayIterator(
const TypedArray<T>&It,
int component)
21const CreativeIterator<T>*C = It.creativeIterator();
23 return Iterator<T>(0,0);
29template <
class T,
int Components>
30Iterator<T> getComponentArrayIterator(
const TypedArray<FixedArray<T, Components> >&It,
int component)
32const CreativeIterator<FixedArray<T, Components>>*C = It.creativeIterator();
34 return Iterator<T>(0,0);
36const Iterator<FixedArray<T, Components>>&iter = *C;
38 return Iterator<T>(iter, component);
75 virtual T
last()
const = 0;
107static RefPtr<MemBase> create(
const RefPtr<MemBase>&SourceLayout,
108 const type_info&layout =
typeid(
void) )
121 template <
class UnaryOperator>
143 template <
class result_t>
158 if (!
rC)
return nullptr;
166 result_t&out =
rIt[i];
187 if (!
rC)
return nullptr;
203 template <
class result_t>
218 if (!
rC)
return nullptr;
226 result_t&out =
rIt[i];
247 if (!
rC)
return nullptr;
263 template <
class result_t,
class SecondType>
267 if (!C)
return nullptr;
272 if (!
C2)
return nullptr;
281 if (!
rC)
return nullptr;
290 result_t&out =
rIt[i];
303 template <
class BinaryOperator>
336#ifdef HAVE_MEMARRAY_INDIRECTION
354 auto getComponent(
int Component) ->
decltype( getComponentArrayIterator(*
this, Component))
356 return getComponentArrayIterator(*
this, Component);
359 auto operator()(
int Component) ->
decltype( getComponentArrayIterator(*
this, Component))
361 return getComponentArrayIterator(*
this, Component);
364 ranged_for_iterator<T> begin()
366 CreativeIterator<T>*C = creativeIterator();
369 return ranged_for_iterator<T>(0,*C);
375 ranged_for_iterator<T> end()
377 CreativeIterator<T>*C = creativeIterator();
380 return ranged_for_iterator<T>(0,*C);
386 const_ranged_for_iterator<T> begin()
const
388 const CreativeIterator<T>*C = creativeIterator();
391 return const_ranged_for_iterator<T>(0,*C);
397 const_ranged_for_iterator<T> end()
const
399 const CreativeIterator<T>*C = creativeIterator();
402 return const_ranged_for_iterator<T>(0,*C);
408#ifdef HAVE_MEMARRAY_INDIRECTION
411 RefPtr<MemBase> createIndirection(
const DynamicSize&newSize,
412 const RefPtr<MemCore::ChunkBase>&Indirection,
413 const MemBase::Creator_t&theCreator)
const override
415 const CreativeIterator<T>*C = creativeIterator();
418 puts(
"TypedArray::createIndirection() C failed");
421 const CreativeIterator<T>&CI = *C;
422 const Iterator<T>&It = CI;
424#ifdef HAVE_OLD_MEMARRAY
425 RefPtr<MemBase> newData = this->newMemArray(newSize, theCreator);
427 RefPtr<MemBase> newData = this->create(newSize);
431 puts(
"TypedArray::createIndirection() newData failed");
434 RefPtr<TypedArray> dst = newData;
437 puts(
"TypedArray::createIndirection() dst failed");
440 const CreativeIterator<T>*Cdst = dst->creativeIterator();
443 puts(
"TypedArray::createIndirection() dst->creativeIterator() failed");
446 const CreativeIterator<T>&CIdst = *Cdst;
447 const Iterator<T>&Itdst = CIdst;
449 index_t mynElements = newSize.nElements();
455 puts(
"TypedArray::createIndirection() found uint32_t indirection chunk");
457 if( !doIndirection<uint32_t>(indirection32_chunk->get_vector(), It, Itdst, mynElements) )
459 puts(
"TypedArray::createIndirection() found uint32_t indirection chunk but FAILED");
467 puts(
"TypedArray::createIndirection() found uint64_t indirection chunk");
469 if( !doIndirection<uint64_t>(indirection64_chunk->get_vector(), It, Itdst, mynElements) )
471 puts(
"TypedArray::createIndirection() found uint64_t indirection chunk but FAILED");
477 puts(
"TypedArray::createIndirection() ERROR: no 32 or 64 uint found for indirection chunk");
491 // ugly copy paste code from function above (mr)
492 // Maybe a encapsulated container instead of the vector should be used?
493 RefPtr<MemBase> createIndirection(const DynamicSize&newSize, const std::vector<unsigned int>&Indirection, const MemBase::Creator_t&theCreator) const override
495 if (Indirection.size() != newSize.nElements() )
496 return MemCore::NullPtr();
498 const CreativeIterator<T>*C = creativeIterator();
500 return MemCore::NullPtr();
502 const CreativeIterator<T>&CI = *C;
503 const Iterator<T>&It = CI;
505 RefPtr<MemBase> newData = this->newMemArray(newSize, theCreator);
507 return MemCore::NullPtr();
509 RefPtr<TypedArray> dst = newData;
511 return MemCore::NullPtr();
513 const CreativeIterator<T>*Cdst = dst->creativeIterator();
515 return MemCore::NullPtr();
517 const CreativeIterator<T>&CIdst = *Cdst;
518 const Iterator<T>&Itdst = CIdst;
520 unsigned nElements = Indirection.size();
521 for(unsigned i=0; i<nElements; i++)
523 unsigned src_index = Indirection[ i ];
525 Itdst[i] = It[ src_index ];
566 if (SRC)
return true;
574 if (SRC)
return true;
583 if (SRC)
return true;
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Description of types, which is meta-information like what is the number of elements of some array-lik...
Definition FiberType.hpp:61
static WeakPtr_t getFiberType()
Get the fiber type information for the current type.
Definition FiberType.hpp:126
index_t count() const
Return the number of steps which can be traversed through this ElementIterator.
Definition HyperslabParameters.hpp:147
Base class for multidimensional arrays with MemCore memory management.
Definition MemBase.hpp:70
virtual DynamicSize getSize() const =0
Return the size of this dataset.
virtual RefPtr< MemBase > createEquallySizedMemArray(const RefPtr< MemCore::ChunkBase > &Storage, const MemBase::Creator_t &C) const =0
Create a memory array of the same dimensions as the current array, but with data as provided by the S...
static RefPtr< MemBase > create(const RefPtr< FiberTypeBase > &FT, const DynamicSize &DS, const type_info &layout=typeid(void))
Given a description of a certain data type for each element on array, allocate a multidimensional arr...
Definition MemBase.cpp:106
An intermediate class that allows to operate on the pure type information of some memory array.
Definition TypedArray.hpp:58
RefPtr< MemBase > applyFunction(const std::function< T(const T &, index_t I)> &theOperator) const
Apply a functor yielding the same type.
Definition TypedArray.hpp:233
virtual T last() const =0
Retrieve the last element.
RefPtr< MemBase > applyOperator(const BinaryOperator &theOperator, const RefPtr< MemBase > &rightValue, const MemBase::Creator_t &theCreator) const
Apply a binary operator on the data contained here, and provide a new memory array of the same size a...
Definition TypedArray.hpp:304
const type_info & getType() const override
Return the element type of the certain array.
Definition TypedArray.hpp:95
RefPtr< MemCore::ChunkBase > getChunk() const override
Implement the virtual getChunk() function.
Definition TypedArray.hpp:88
RefPtr< MemBase > applyFunction(const std::function< T(const T &)> &theOperator) const
Apply a functor yielding the same type.
Definition TypedArray.hpp:173
virtual RefPtr< MemCore::TypedChunk< T > > myChunk() const =0
Access to a chunk of contiguous data, if such exists.
virtual T first() const =0
Retrieve the first element.
RefPtr< MemBase > applyFunction(const TypedArray< SecondType > &R, const std::function< result_t(const T &, const SecondType &ST, index_t I)> &theOperator) const
Apply a binary functor, possibly yielding a different type.
Definition TypedArray.hpp:264
RefPtr< MemBase > applyFunction(const std::function< result_t(const T &, index_t I)> &theOperator) const
Apply a functor, possibly yielding a different type.
Definition TypedArray.hpp:204
RefPtr< MemBase > applyFunction(const std::function< result_t(const T &)> &theOperator) const
Apply a functor, possibly yielding a different type.
Definition TypedArray.hpp:144
RefPtr< MemBase > applyOperator(const UnaryOperator &theOperator, const MemBase::Creator_t &theCreator) const
Apply an unary operator on the data contained here, and provide a new memory array of the same size a...
Definition TypedArray.hpp:122
Definition TypedArray.hpp:544
TypedIterator()
Default constructor.
Definition TypedArray.hpp:549
TypedIterator(const RefPtr< MemBase > &src)
Construct from untyped array.
Definition TypedArray.hpp:553
bool operator=(const RefPtr< MemArray< N, T > > &src)
assign from typed array
Definition TypedArray.hpp:580
bool operator=(const RefPtr< MemBase > &src)
assign from untyped array
Definition TypedArray.hpp:563
TypedIterator(const RefPtr< TypedArray< T > > &src)
Construct from typed array.
Definition TypedArray.hpp:558
CreativeIterator< T > & operator*() const
Retrieve an iterator to the underlying data, if possible.
Definition TypedArray.hpp:618
const RefPtr< TypedArray< T > > & operator()() const
Retrieve the associated pointer to the typed array.
Definition TypedArray.hpp:606
bool operator=(const RefPtr< TypedArray< T > > &src)
assign from typed array
Definition TypedArray.hpp:571
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
StrongPtr< Object, ObjectBase > RefPtr
Implementing a binary operation on two fields with on-demand computation per fragment and discarding ...
Definition BinaryOperator.hpp:36
Implementing an unary operation on a fields with on-demand computation per fragment and discarding da...
Definition UnaryOperator.hpp:49