00001 #ifndef __FIBER_REFERENCINGMEMARRAY_HPP
00002 #define __FIBER_REFERENCINGMEMARRAY_HPP "Created 3.12.2007"
00003
00004 #include "FieldAPI.h"
00005 #include "MemArrayBase.hpp"
00006 #include "TypedArray.hpp"
00007
00008 namespace Fiber
00009 {
00010
00016 template <int N, class T>
00017 class ReferencingMemArray : public MemArrayBase<N>, public MultiArray<N, T>,
00018 public TypedArray<T>
00019 {
00020 protected:
00021 RefPtr<MemCore::ChunkBase> Storage;
00022
00023 public:
00024 typedef RefPtr<MemCore::Chunk<T> > MemChunk;
00025 typedef MultiArray<N, T> MultiArray_t;
00026
00028 ReferencingMemArray( const Iterator<T>&data, const MultiIndex<N>&Sz,
00029 const RefPtr<MemCore::ChunkBase>&MemStorage,
00030 const WeakPtr<CreativeArrayBase>&theCreator)
00031 : MemBase(theCreator)
00032 , MemArrayBase<N>(theCreator)
00033 , MultiArray<N, T>(data, Sz)
00034 , TypedArray<T>(theCreator)
00035 , Storage(MemStorage)
00036 {}
00037
00039 ReferencingMemArray( const RefPtr<Chunk<T> > &data, const MultiIndex<N>&Sz, const WeakPtr<CreativeArrayBase>&theCreator)
00040 : MemBase(theCreator)
00041 , MemArrayBase<N>(theCreator)
00042 , MultiArray<N, T>( Iterator<T>( data?data->size():0, data?(*data)():0), Sz)
00043 , TypedArray<T>(theCreator)
00044 , Storage(data)
00045 {}
00046
00056 ReferencingMemArray(const RefPtr<MemCore::ChunkBase>&Storage, const MultiArray<N,T>&M, const WeakPtr<CreativeArrayBase>&theCreator)
00057 : MemBase(theCreator)
00058 , MemArrayBase<N>(theCreator)
00059 , MultiArray<N, T>( M )
00060 , TypedArray<T>(theCreator)
00061 , Storage(Storage)
00062 {}
00063
00064 ~ReferencingMemArray()
00065 {}
00066
00068 override RefPtr<MemCore::TypedChunk<T> > myChunk() const
00069 {
00070 return this->StoragePtr();
00071 }
00072
00077 override MemCore::memsize_t memsize() const
00078 {
00079 return Storage->memsize();
00080 }
00081
00082 override index_t nElements() const
00083 {
00084 return MultiArray<N, T>::nElements();
00085 }
00086
00087 override void DeferredConstructor()
00088 {
00089 MemCore::SaveRegistry<MemBase>::addInterfaces(this);
00090 }
00091
00093 override const type_info&getType() const
00094 {
00095 return typeid(T);
00096 }
00097
00099 override const type_info&getBaseType() const
00100 {
00101 return typeid(typename MemCore::TypedChunk<T>::base_vector_type::value_type);
00102 }
00103
00104 override const FiberTypeBase&getFiberType() const
00105 {
00106 return MemArrayAllocator<T>::getFiberType();
00107 }
00108
00109 override HyperslabParameters&getHyperslabParameters()
00110 {
00111 return *this;
00112 }
00113
00114 override void*getPtr()
00115 {
00116 return this->ptr();
00117 }
00118
00119 override const void*OriginPtr() const
00120 {
00121 return 0;
00122 }
00123
00124 override const void*DeltaPtr() const
00125 {
00126 return 0;
00127 }
00128
00129 override T first() const
00130 {
00131 return MultiArray_t::first();
00132 }
00133
00134 override T last() const
00135 {
00136 return MultiArray_t::last();
00137 }
00138
00139 override CreativeIterator<T>* creativeIterator()
00140 {
00141 return this;
00142 }
00143
00144 override const CreativeIterator<T>* creativeIterator() const
00145 {
00146 return this;
00147 }
00148
00149 const RefPtr<MemCore::ChunkBase>&StoragePtr() const
00150 {
00151 return Storage;
00152 }
00153
00154
00155 const RefPtr<MemCore::ChunkBase>&getStorage() const
00156 {
00157 return Storage;
00158 }
00159
00160 RefPtr<MemCore::TypedChunk<T> > getTypedStorage() const
00161 {
00162 return Storage;
00163 }
00164 };
00165
00166
00167 }
00168
00169 #endif
00170