Bundle.hpp

00001 #ifndef __FIBER_BUNDLE_HPP
00002 #define __FIBER_BUNDLE_HPP "Created 27.02.2001 21:42:27 by werner"
00003 
00004 #include "BundleAPI.h"
00005 #include <grid/Grid.hpp>
00006 #include <memcore/Persistencer.hpp>
00007 #include <memcore/Loader.hpp>
00008 #include <list>
00009 #include "GridID.hpp"
00010 #include "Slice.hpp"
00011 #include "ParameterSpace.hpp"
00012 #include "FindInfo.hpp"
00013 
00014 namespace Fiber
00015 {
00016         using std::list;
00017         using std::string;
00018         using MemCore::SaveRegistry;
00019 
00029 template <class ObjectLevel>
00030         class BUNDLE_API EvolutionIterator;
00031 
00034 struct  BUNDLE_API GridSaveParameters : MemCore::SaveParameters
00035 {
00036         RefPtr<MemCore::StringList>     SaveableGridNames; 
00037 
00038         GridSaveParameters(const string&url,
00039                            const RefPtr<MemCore::StringList>&GridNames)
00040         : MemCore::SaveParameters(url)
00041         , SaveableGridNames(GridNames)
00042         {}
00043 };
00044 
00045 
00050 template <>
00051 class   BUNDLE_API EvolutionIterator<Slice>
00052 {
00053 public:
00054         virtual ~EvolutionIterator<Slice>();
00055 
00056         virtual bool apply(ParameterSet&P, Slice&S) = 0;
00057 };
00058 
00064 template <>
00065 class   BUNDLE_API EvolutionIterator<Grid>
00066 {
00067 public:
00068         virtual ~EvolutionIterator<Grid>();
00069 
00070         virtual bool apply(double t, GridID&id, Grid&g) = 0;
00071 };
00072 
00078 template <>
00079 class   BUNDLE_API EvolutionIterator<Skeleton>
00080 {
00081 public:
00082         virtual ~EvolutionIterator<Skeleton>();
00083 
00084         virtual bool apply(double t, const RefPtr<Skeleton>&S) = 0;
00085 };
00086 
00087 template <>
00088 class   BUNDLE_API EvolutionIterator<Field>
00089 {
00090 public:
00091         ~EvolutionIterator<Field>();
00092 };
00093 
00098 class   BUNDLE_API BundleLoaderProgress : public LoaderProgress 
00099 {
00100 public:
00101         BundleLoaderProgress ();
00102 
00106         virtual bool OpenFile(const string&fname);
00107 
00111         virtual bool CreateSlice(double t);
00112 
00116         virtual bool CreateGrid(const RefPtr<GridID>&gname, Grid&G, double t);
00117 
00121         virtual bool CreateField(const RefPtr<GridID>&gname, Grid&G, double t, const string&fieldname);
00122 };
00123 
00136 class   BUNDLE_API Bundle : public GridList, public Intercube, public Attributes
00137 {
00138         ParameterList   AvailableParameters;
00139         RefPtr<GlobalCharts>    Atlas;
00140 
00141 //public:
00142         typedef RefPtr<Slice>                   P0D_t;
00143         typedef map<double, RefPtr<Slice> >             P1D_t;
00144         typedef map<double, map<double,RefPtr<Slice> > >        P2D_t;
00145 
00146         P0D_t   P0D;
00147         P1D_t   P1D;
00148         P2D_t   P2D;
00149 
00150 //      map<ParameterSet, ParameterSpace>       ParameterSpaces;
00151 
00152 public:
00153         typedef MemCore::LoaderRegistry<Bundle> Loader;
00154 
00166 static  RefPtr<Bundle> load(bool&success, const RefPtr<LoaderParameters>&ld, const RefPtr<Bundle>&B = NullPtr() );
00167 
00168 static  RefPtr<Bundle> load(bool&success, const string&url, 
00169                             const RefPtr<Bundle>&B = NullPtr(),
00170                             const RefPtr<LoaderProgress>&Progress = NullPtr(),
00171                             bool detect_sequence = false)
00172         {
00173         RefPtr<LoaderParameters> LP = new LoaderParameters( url, detect_sequence ); 
00174                 if (Progress)
00175                         LP->setProgressCallbacks( Progress ); 
00176 
00177                 return load(success, LP, B);
00178         }
00179 
00180 
00184 //static        bool loadable(const string&URL);
00185 
00191         bool merge(const RefPtr<LoaderParameters>&LP);
00192 
00194         Bundle();
00195 
00197         void DeferredConstructor();
00198 
00200         ~Bundle();
00201 
00202         using GridList::operator ();
00203         using GridList::operator []; 
00204         using GridList::getGridnames;
00205 
00206 
00210         double minTime() const;
00211 
00215         double maxTime() const; 
00216 
00218         typedef Info<Slice> SliceInfo_t; 
00219 
00221         typedef Info<Grid> GridInfo_t; 
00222 
00224         typedef Info<Skeleton> SkeletonInfo_t;
00225 
00227         SliceInfo_t firstSlice() const;
00228 
00234         bool    accessFirstSlice() const
00235         {
00236         SliceInfo_t SI = firstSlice(); 
00237                 if (SI.second)
00238                         return SI.second->accessSlice();
00239 
00240                 return false;   
00241         }
00242 
00244         Slice&operator[](double time);
00245 
00247         Slice&operator[](const ParameterSet&);
00248 
00250         SlicePtr operator()(double&time) const;
00251 
00252         SlicePtr findPrev(double&time) const;
00253         SlicePtr findNext(double&time) const; 
00254 
00256         SliceInfo_t prev(double time) const
00257         {
00258         SliceInfo_t retval; 
00259                 retval.first = time; 
00260                 retval.second = findPrev(retval.first); 
00261                 return retval;
00262         }
00263 
00265         SliceInfo_t next(double time) const
00266         {
00267         SliceInfo_t retval; 
00268                 retval.first = time; 
00269                 retval.second = findNext(retval.first); 
00270                 return retval;
00271         }
00272 
00276         RefPtr<Grid> operator()(double time, const string&gridname) const
00277         {
00278         RefPtr<Slice> S = (*this)(time);
00279                 if (S) 
00280                         return (*S)(gridname);
00281                 return NullPtr();
00282         } 
00283 
00290         RefPtr<Grid> newGrid() const
00291         {
00292                 return new Grid( self(), Atlas);
00293         }
00294 
00299         GridInfo_t findMostRecentGrid(double time, const string&gridname) const;
00300 
00305         GridInfo_t findMostRecentGrid(double time, const RefPtr<GridID>&gridid) const;
00306 
00312         Info<Grid> findPrev(double time, const string&gridname) const; 
00313         Info<Grid> findPrev(double time, const RefPtr<GridID>&gridname) const;
00314 
00320         Info<Grid> findNext(double time, const string&gridname) const; 
00321         Info<Grid> findNext(double time, const RefPtr<GridID>&gridname) const;
00322 
00331         int     iterateBackward(double&time, const string&gridname, EvolutionIterator<Grid>&GEI, bool IterateOnlyLoadedSlices) const;
00332 
00341         int     iterateForward (double&time, const string&gridname, 
00342                                 EvolutionIterator<Grid>&GEI, 
00343                                 bool IterateOnlyLoadedSlices) const;
00344 
00345         SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level,
00346                                                    EvolutionIterator<Skeleton>*EIS, int IndexDepth);
00347 
00352         SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level, int IndexDepth = 0)
00353         {
00354                 return findPreviousRefinementLevel(T,gridname,Level,0,IndexDepth);
00355         } 
00356 
00357         SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level,
00358                                                    EvolutionIterator<Skeleton>&EIS, int IndexDepth=0)
00359         {
00360                 return findPreviousRefinementLevel(T,gridname,Level,&EIS,IndexDepth);
00361         }
00362 
00363 private:
00364         SkeletonInfo_t  findNextRefinementLevel(P1D_t::const_iterator&it, const string&gridname, int Level, int IndexDepth);
00365 
00366 public:
00367         SkeletonInfo_t  findNextRefinementLevel(double&T, const string&gridname, int Level, int IndexDepth = 0);
00368 
00369 
00373         RefPtr<Grid> operator()(double time, const RefPtr<GridID>&gridname) const
00374         {
00375         RefPtr<Slice> S = (*this)(time);
00376                 if (S) 
00377                         return (*S)(gridname);
00378                 return NullPtr();
00379         }
00380 
00381 
00383         RefPtr<Slice> operator()(const ParameterSet&) const;
00384 
00389         int sizeP1D() const
00390         {
00391                 return P1D.size();
00392         }
00393 
00394         const ParameterList&AllParameters() const
00395         {
00396                 return  AvailableParameters;
00397         }
00398 
00399         int iterate(const ParameterList&PL, EvolutionIterator<Slice>&SI) const; 
00400 
00401         typedef std::pair<double,double> Range_t; 
00402 
00403         Range_t getTimeRange(const string&Gridname, bool OnlyInspectAlreadyLoadedSlices=false);
00404 
00411         int     getMemoryUsage(memsize_t&UsedMemory, memsize_t&WantedMemory) const;
00412 };
00413 
00420 class   BUNDLE_API BundlePtr : public RefPtr<Bundle>
00421 {
00422 public:
00423         using RefPtr<Bundle>::operator void*;
00424         using RefPtr<Bundle>::operator !;
00425 
00427         BundlePtr();
00428 
00430         BundlePtr(const RefPtr<Bundle>&);
00431 
00432         BundlePtr(Bundle*);
00433 
00435         ~BundlePtr();
00436 
00442         Bundle& operator*();
00443 
00447         Slice&operator[](double time)
00448         {
00449         Bundle&B = (**this);
00450                 return B[time];
00451         } 
00452 
00457         SlicePtr operator()(double&time)
00458         {
00459                 if (!*this) return NullPtr(); 
00460                 return (**this)(time);
00461         }
00462 
00474         int     save(const string&url);
00475 
00479         int     saveGrids(const string&url, const RefPtr<MemCore::StringList>&SaveableGridNames);
00480 };
00481 
00482 } /* namespace Fiber */ 
00483 
00484 #endif /* __FIBER_BUNDLE_HPP */
00485