ArrayList.hpp

00001 
00002 //
00003 // $Id: ArrayList.hpp,v 1.2 2005/01/17 14:47:28 werner Exp $
00004 // $Log: ArrayList.hpp,v $
00005 // Revision 1.2  2005/01/17 14:47:28  werner
00006 // Improved documentation.
00007 //
00008 // Revision 1.1  2004/08/31 14:10:42  werner
00009 // On-demand loading array classes separated from Field class, and introduced
00010 // transparent multidimensional arrays with on-demand loaded slices.
00011 //
00013 
00014 #ifndef __FIELD_ARRAYLIST_HPP
00015 #define __FIELD_ARRAYLIST_HPP
00016 
00017 #include <vecal/ipol/CopyMultiArray.hpp>
00018 #include <vecal/ipol/ViewMultiArray.hpp>
00019 #include "MemArray.hpp"
00020 #include "CreativeArray.hpp"
00021 
00022 namespace Fiber
00023 {
00024 using namespace VecAl;
00025 
00026 
00027 template <class T, class S=T*>
00028 class ArrayList
00029 {
00030 public:
00032         typedef MultiArray<1, T,  S>  M1D;
00033 
00034 
00036         typedef MultiArray<2, T,  S>  M2D;
00037 
00039         typedef MultiArray<2, T, CreativeArray<2, T, S, S> >  M2D_1D;
00040 
00041 
00043         typedef MultiArray<3, T, S>   M3D;
00044 
00046         typedef MultiArray<3, T, CreativeArray<3, T, S, S> > M3D_2D;
00047 
00049         typedef MultiArray<3, T, CreativeArray<3, T, S, CreativeArray<2, T, S, S> > > M3D_2D_1D;
00050 
00051 
00053         typedef MultiArray<4, T, S>   M4D;
00054 
00056         typedef MultiArray<4, T, CreativeArray<4, T, S, S> > M4D_3D;
00057 
00059         typedef MultiArray<4, T, CreativeArray<4, T, S, CreativeArray<3, T, S, S> > > M4D_3D_2D;
00060 
00062         typedef MultiArray<4, T, CreativeArray<4, T, S, CreativeArray<3, T, S, CreativeArray<2, T, S, S> > > > M4D_3D_2D_1D;
00063 
00064 };
00065 
00066 #if 0
00067 template <class SrcMemArrayType>
00068 struct  CopyMemArraySourceTypeIterator
00069 {
00070         SrcMemArrayType&Src;
00071         
00072         enum { Dims = SrcMemArrayType::Dims };
00073 
00074         const MultiIndex<Dims>        &DstOffset;
00075         const RefPtr<MemArray<Dims> > &Dst;
00076         const MultiIndex<Dims>        &SrcOffset;
00077 
00078         CopyMemArraySourceTypeIterator(const RefPtr<MemArray<Dims> > &pDst,
00079                                        const MultiIndex<Dims>        &pDstOffset,
00080                                        SrcMemArrayType&S,
00081                                        const MultiIndex<Dims>        &pSrcOffset)
00082         : Src(S), Dst(pDst)
00083         , DstOffset(pDstOffset), SrcOffset(pSrcOffset)
00084         {}
00085 
00086         template <typename T>
00087                 struct exec
00088                 {
00089                         template <typename Storage>
00090                                 struct  DstStorage
00091                         {
00092                         static  bool CouldCopy(CopyMemArraySourceTypeIterator&It)
00093                                 {
00094                                         if (RefPtr<MemArrayStorage<Dims, T, Storage> > D = It.Dst)
00095                                         {
00096                                                 Xerox<MultiArray<Dims, T, Storage>, SrcMemArrayType>::
00097 							Copy( D->myArray(), It.DstOffset, It.Src, It.SrcOffset);
00098                                                 return true; // copy done.
00099                                         }
00100                                         return false; // continue traversal
00101                                 }
00102                         };
00103 
00104                         // return true if the traversal of the list 
00105                         // should be stopped
00106                 static inline bool Break(CopyMemArraySourceTypeIterator&It)
00107                         {
00108                                 if (DstStorage<        T*  >::CouldCopy(It) ) return true;
00109                                 if (DstStorage<ViewPtr<T>  >::CouldCopy(It) ) return true;
00110                         //      if (DstStorage<vector <T>  >::CouldCopy(It) ) return true;
00111                                 if (DstStorage<vector <T*> >::CouldCopy(It) ) return true;
00112 
00113 
00114                         /*
00115                                 if (RefPtr<MemArrayStorage<Dims, T, T*> > D = It.Dst)
00116                                 {
00117                                         Xerox<MultiArray<Dims, T, T*>, SrcMemArrayType, Dims>::
00118                                                 Copy( D->myArray(), It.DstOffset, It.Src, It.SrcOffset);
00119                                         return true; // copy done.
00120                                 }
00121                         */
00122                                 return false; // continue traversal
00123                         }
00124                 };
00125 };
00126 
00127 
00128 
00129 template <int Dims>
00130 struct  CopyMemArrayIterator
00131 {
00132         const RefPtr<MemArray<Dims> >   &Dst;
00133         const MultiIndex<Dims>          &DstOffset;
00134         const RefPtr<MemArray<Dims> >   &Src; 
00135         const MultiIndex<Dims>          &SrcOffset;
00136 
00137 
00138         CopyMemArrayIterator(const RefPtr<MemArray<Dims> >&pDst, const MultiIndex<Dims>&pDstOffset,
00139                              const RefPtr<MemArray<Dims> >&pSrc, const MultiIndex<Dims>&pSrcOffset)
00140         : Dst(pDst), DstOffset(pDstOffset)
00141         , Src(pSrc), SrcOffset(pSrcOffset)
00142         {}
00143 
00144         template <typename T>
00145                 struct exec
00146                 {
00147                         template <typename Storage>
00148                                 struct  SrcStorage
00149                         {
00150                         static  bool CouldCopy(CopyMemArrayIterator&It)
00151                                 {
00152                                         if (RefPtr<MemArrayStorage<Dims, T, Storage> > Src = It.Src)
00153                                         {
00154                                         typedef MultiArray<Dims, T, Storage> SrcMultiArray_t;
00155 
00156                                         CopyMemArraySourceTypeIterator<SrcMultiArray_t> 
00157                                                 cm( It.Dst, It.DstOffset, Src->myArray(), It.SrcOffset );
00158 
00159                                         bool    ok = FOREACH<CopyMemArraySourceTypeIterator<SrcMultiArray_t>,
00160                                                              FloatTypeList>::exec( cm );
00161 
00162                                                 return ok;
00163                                         }
00164                                         return false;
00165                                 }
00166                         };
00167 
00168                         // return true if the traversal of the list 
00169                         // should be stopped
00170                 static inline bool Break(CopyMemArrayIterator&It)
00171                         {
00172                                 if (SrcStorage<const T*         >::CouldCopy(It) ) return true;
00173                                 if (SrcStorage<      T*         >::CouldCopy(It) ) return true;
00174                                 if (SrcStorage<ViewPtr<const T> >::CouldCopy(It) ) return true;
00175                                 if (SrcStorage<ViewPtr<      T> >::CouldCopy(It) ) return true;
00176                                 if (SrcStorage<vector <      T> >::CouldCopy(It) ) return true;
00177                                 if (SrcStorage<vector <     T*> >::CouldCopy(It) ) return true;
00178 
00179 
00180 
00181 /*                      The above code is identical to the explicit version as here,
00182                         but leaving the storage type open for iteration.
00183 
00184                                 if (RefPtr<MemArrayStorage<Dims, T, T*> > Src = It.Src)
00185                                 {
00186                                 CopyMemArraySourceTypeIterator<MultiArray<Dims, T, T*> > 
00187                                         cm( It.Dst, It.DstOffset, Src->myArray(), It.SrcOffset );
00188 
00189                                 bool    ok = FOREACH<CopyMemArraySourceTypeIterator<MultiArray<Dims, T, T*> >,
00190                                                      FloatTypeList>::exec( cm );
00191 
00192                                         return ok;
00193                                 }
00194 */
00195                                 return false; // continue traversal
00196                         }
00197                 };
00198 };
00199 #endif
00200 
00201 } /* namespace VecAl */ 
00202 
00203 
00204 #endif // __FIELD_ARRAYLIST_HPP