FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
MemBase.hpp
1#ifndef __FIBER_MEMBASE_HPP
2#define __FIBER_MEMBASE_HPP
3
4#include "FieldAPI.h"
5#include <memcore/RefPtr.hpp>
6#include <memcore/Interface.hpp>
7#include <memcore/Persistencer.hpp>
8#include <memcore/Cacheable.hpp>
9#include <memcore/Cache.hpp>
10#include <memcore/Creator.hpp>
11#include <memcore/Chunk.hpp>
12
13#include <fiber/vector/MultiArray.hpp>
14
15#include <typeinfo>
16#include "FiberType.hpp"
17#include "DynamicSize.hpp"
18
19namespace Fiber
20{
21class FIELD_API MemBase;
22
23
24// template forward declaration, defined in MemArray.hpp
25template <Dims_t N, class T>
26class MemArray;
27
28}
29
30namespace MemCore
31{
32
33template <>
35{
36static void call(Fiber::MemBase*ma);
37};
38
39}
40
41namespace Fiber
42{
43 using std::type_info;
44
45 using MemCore::RefPtr;
47 using MemCore::Chunk;
48
49
59class FIELD_API CreativeArrayBase;
60
62 WeakPtrCreativeArrayBase_t;
63
64
70{
71// set<MemCore::WeakPtr<MemArrayBase> > > Sources;
72
73 FiberTypeIndex myFiberTypeIndex;
74
75public:
77
79 MemBase(const FiberTypeIndex&theFiberTypeIndex, const Creator_t&theCreator);
80
82 ~MemBase();
83
84 MemBase(const MemBase&) = delete;
85 MemBase() = delete;
86
87 MemCore::WeakPtr<MemBase> membase() const
88 {
89 return self();
90 }
91
95 virtual void DeferredConstructor() override = 0;
96// { puts("MemArrayBase:: DeferredConstructor() called..."); }
97
99 virtual Fiber::Dims_t rank() const = 0;
100
102 virtual DynamicSize getSize() const = 0;
103
105 virtual index_t nElements() const
107 return getSize().nElements();
108 }
109
110 auto NumberOfElements() const
111 {
112 return nElements();
113 }
114
115 auto getNumberOfElements() const
116 {
117 return nElements();
118 }
119
121 virtual const type_info&getType() const = 0;
122
123 virtual HyperslabParameters&getHyperslabParameters() = 0;
124
126 virtual std::string getElementAsString(size_t index) const = 0;
127
129
131 virtual void*getPtr() = 0;
132
135
137 virtual const void*OriginPtr() const = 0;
139 virtual const void*DeltaPtr() const = 0;
140
141
144 {
145 if (RefPtr<MemCore::ChunkBase> C = getChunk() )
146 return C->memsize();
147
148 return 0;
149 }
150
152
153 MemCore::WeakPtr<FiberTypeBase> getFiberType() const
154 {
155 return FiberTypeBase::find( myFiberTypeIndex );
156 }
157
158 MemCore::memsize_t element_memsize() const
159 {
160 return myFiberTypeIndex.mem_size;
161 }
162
169
170 virtual RefPtr<MemBase> getComponentArray(int member, const MemBase::Creator_t&C) = 0;
171
172 virtual RefPtr<MemBase> createSubArray(const DynamicSize&Offset, const DynamicSize&CopySize, const MemBase::Creator_t&C) const = 0;
173
181
182 virtual bool copyFrom(const RefPtr<MemCore::ChunkBase>&theChunk) = 0;
183
189 {
190 if (!Mb) return false;
191 return copyFrom( Mb->getChunk() );
192 }
193
198 virtual RefPtr<MemBase> copy(const MemBase::Creator_t&C = nullptr) const = 0;
199
200#ifdef HAVE_OLD_MEMARRAY
201 /*
202 Create new array of the same type as the current one, but with the specified dimensions.
203 No initializations are performed here.
204 */
205 virtual RefPtr<MemBase> newMemArray(const DynamicSize&newSize, const MemBase::Creator_t&C) const = 0;
206
211 RefPtr<MemBase> newMemArray(const MemBase::Creator_t&C) const
212 {
213 return newMemArray( getSize(), C);
214 }
215#endif
216
217#ifdef HAVE_MEMARRAY_INDIRECTION
226 const MemBase::Creator_t&theCreator) const = 0;
227#endif
228
233// virtual RefPtr<MemBase> createIndirection(const DynamicSize&newSize,
234// const std::vector<unsigned int>&Indirection,
235// const MemBase::Creator_t&theCreator) const = 0;
236
242 class FIELD_API Allocator : public MemCore::Interface<Allocator>
243 {
244 public:
245 Allocator();
246 ~Allocator();
247
248 virtual RefPtr<MemBase> create(const DynamicSize&) const = 0;
249 };
250
251
259static RefPtr<MemBase> create(const RefPtr<FiberTypeBase>&FT,
260 const DynamicSize&DS,
261 const type_info&layout = typeid(void) );
262
267 const type_info&layout = typeid(void) ) const
268 {
269 return create(FT, getSize(), layout);
270 }
271
275 template <class T>
276 RefPtr<MemBase> create(const type_info&layout = typeid(void) ) const
277 {
279 return create(FT, getSize(), layout);
280 }
281
285 RefPtr<MemBase> create(const DynamicSize&DS,
286 const type_info&layout = typeid(void) ) const;
287
291 RefPtr<MemBase> create(const type_info&layout = typeid(void) ) const;
292
293
294static bool registerCreator(const RefPtr<Allocator>&A,
295 const RefPtr<FiberTypeBase>&FT);
296
297static /*FIELD_API*/ int RegisteredTypes;
298
299};
300
301
302inline RefPtr<MemCore::ChunkBase> getChunk(const MemCore::WeakPtr<MemBase>&MemData)
303{
304 if (MemData)
305 return MemData->getChunk();
306
307 return MemCore::NullPtr();
308}
309
313template <class T>
315{
316public:
317 RefPtr<MemBase> create(const DynamicSize&DS) const override;
318
319static MemCore::WeakPtr<FiberTypeBase> getFiberType()
320 {
322 }
323
324static bool registerMe()
325 {
327#ifdef VERBOSE
328 printf("MemArrayAllocator<%s>::registerMe()\n", typeid(T).name() );
329#endif
330 return MemBase::registerCreator( A, getFiberType() );
331 }
332
333static bool isRegistered()
334 {
335 static bool b = registerMe();
336#ifdef VERBOSE
337 printf(b?"isRegistered is TRUE\n":"isRegistered is FALSE\n");
338#endif
339 return b||true;
340 }
341};
342
343
345{
346 return getChunk( Mem );
347}
348
349
350} // namespace Fiber
351
352namespace MemCore
353{
354inline void DeferredInitializationTrait<Fiber::MemBase>::call(Fiber::MemBase*ma)
355 {
357 }
358}
359
360#endif /* __FIBER_MEMARRAY_HPP */
basic_string< char > string
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A class describing an n-dimensional space at runtime.
Definition field/DynamicSize.hpp:29
static WeakPtr_t getFiberType()
Get the fiber type information for the current type.
Definition FiberType.hpp:126
A set of integer values which describes how to iterate over a certain set of values.
Definition HyperslabParameters.hpp:34
Allocating array types through registry of types.
Definition MemBase.hpp:315
Same as above but using a unsinged int vector.
Definition MemBase.hpp:243
Base class for multidimensional arrays with MemCore memory management.
Definition MemBase.hpp:70
RefPtr< MemBase > create(const type_info &layout=typeid(void)) const
Create a new mem array of the same dimensions but different type.
Definition MemBase.hpp:276
virtual DynamicSize getSize() const =0
Return the size of this dataset.
virtual Fiber::Dims_t rank() const =0
Return the number of dimensions.
RefPtr< MemBase > create(const RefPtr< FiberTypeBase > &FT, const type_info &layout=typeid(void)) const
Create a new mem array of the same dimensions but different type.
Definition MemBase.hpp:266
virtual const void * OriginPtr() const =0
Get pointer to origin of linearly procedural array, if it is linear.
virtual void * getPtr()=0
Special Array Storage.
virtual index_t nElements() const
return the number of elements in this array
Definition MemBase.hpp:105
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...
virtual RefPtr< MemBase > makeMemArray(const MemBase::Creator_t &C) const =0
Provide a MemArray, even though the actual data is a procedural array.
virtual void DeferredConstructor() override=0
Virtual deferred reference pointer construction pointer Don't overload if you don't know exactly what...
Definition MemBase.cpp:24
virtual const type_info & getType() const =0
Return the element type of the certain array.
virtual const void * DeltaPtr() const =0
Get pointer to delta of linearly procedural array, if it is linear.
virtual RefPtr< MemCore::ChunkBase > getChunk() const =0
Get chunk to underlying data, if this is a contiguous array.
bool copyFrom(const RefPtr< MemBase > &Mb)
Copy all data values from the given MemBase.
Definition MemBase.hpp:188
virtual RefPtr< MemBase > copy(const MemBase::Creator_t &C=nullptr) const =0
Create a copy of the current array, duplicating all data and allocating new memory for it.
MemCore::memsize_t memsize() const override
How much memory is occupied here at all in case it's stored in a chunk?
Definition MemBase.hpp:143
MemSizeConfig< sizeof(void *)>::memsize_t memsize_t
point operator-(const point &P, const vector &v)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
Definition FiberTypeIndex.hpp:12