Slice.hpp

00001 #ifndef __SLICE_HPP
00002 #define __SLICE_HPP  "Created 25.08.2004"
00003 
00004 #include "GridID.hpp"
00005 #include "GridList.hpp"
00006 #include <memcore/stringlist.hpp>
00007 
00008 namespace Fiber
00009 {
00010 
00015 class   BUNDLE_API GridIterator
00016 {
00017 public:
00019         virtual ~GridIterator();
00020 
00021 
00023         virtual bool apply(GridID&id, Grid&g) = 0;
00024 };
00025 
00032 class   BUNDLE_API Slice : public ReferenceBase<Slice>
00033 {
00034         typedef map<RefPtr<GridID>, RefPtr<Grid> > grids_t;
00035         grids_t grids;
00036 
00037         // Reference to something that contains grid, which 
00038         // is basically the entire bundle
00039         WeakPtr<GridList>       IDList;
00040         RefPtr<GlobalCharts>    Atlas;
00041 
00042 public:
00043 
00048         class   BUNDLE_API Loader : public ReferenceBase<Loader>
00049         {
00050         public:
00052                 Loader()
00053                 : ReferenceBase<Loader>(this)
00054                 {}
00055 
00057                 ~Loader();
00058 
00062                 virtual bool load(const WeakPtr<Slice>&Self) = 0;
00063         };
00064 
00069         RefPtr<Loader>  DeferredLoader; 
00070 
00075         bool    accessSlice()
00076         {
00077                 if (DeferredLoader)
00078                 {
00079                 RefPtr<Loader>  DL = DeferredLoader; 
00080                         DeferredLoader = NullPtr();
00081                         DL->load( self() );
00082                 }
00083 
00084                 return true;    
00085         }
00086 
00087         bool    isNotYetLoaded() const
00088         {
00089                 return DeferredLoader;
00090         }
00091 
00092         bool    isLoaded() const
00093         {
00094                 return !isNotYetLoaded();
00095         }
00096 
00100         Slice(const WeakPtr<GridList>&IDList, const RefPtr<GlobalCharts>&Atlas);
00101 
00105         ~Slice(); 
00106 
00110         Grid&newGrid(const string&gridname); 
00111 
00118         Grid&newGrid(const string&gridname, const string&ParentGridName);
00119 
00124         bool    insert(const string&gridname, const RefPtr<Grid>&G);
00125 
00134         Grid&operator[](const string&gridname);
00135 
00137         Grid&operator[](const RefPtr<GridID>&gridname);
00138 
00140         RefPtr<GridID> makeGridID(const string&gridname);
00141 
00143         RefPtr<GridID> findGridID(const string&gridname);
00144 
00148         RefPtr<Grid> operator()(const string&gridname); 
00149 
00151         RefPtr<Grid> operator()(const RefPtr<GridID>&gridname); 
00152 
00161         int iterate(GridIterator&GI, 
00162                     const RefPtr<MemCore::StringList>&TheseGridsOnly = NullPtr() ); 
00163 
00164 
00168         int     getMemoryUsage(memsize_t&UsedMemory, memsize_t&WantedMemory) const;
00169 };
00170 
00171 
00176 class   BUNDLE_API SliceList
00177 {
00178         typedef set<WeakPtr<Slice> >    Slices_t;
00179         Slices_t        Slices;
00180 public: 
00181 
00183         SliceList();
00184 
00186         ~SliceList();
00187 
00188         struct  BUNDLE_API iterator
00189         {
00190                 virtual ~iterator();
00191 
00192                 virtual bool apply(const WeakPtr<Slice>&S) = 0;
00193         };
00194 
00195 static  void addSlice(const WeakPtr<Slice>&S, const RefPtr<GridID>&G); 
00196 
00197         int     iterate(iterator&it); 
00198 
00199 static  int     iterate(const RefPtr<GridID>&G, iterator&it);
00200 
00201 };
00202 
00206 class   BUNDLE_API SlicePtr : public RefPtr<Slice>
00207 {
00208 public:
00210         SlicePtr(const RefPtr<Slice>&RS)
00211         : RefPtr<Slice>(RS)
00212         {} 
00213 
00215         SlicePtr(const MemCore::NullPtr&)
00216         : RefPtr<Slice>(MemCore::NullPtr() )
00217         {} 
00218 
00222         RefPtr<Grid> operator()(const string&gridname) const
00223         {
00224                 if (!*this) return NullPtr(); 
00225                 return (**this)(gridname);
00226         }
00227 
00229         RefPtr<Grid> operator()(const RefPtr<GridID>&gridname) const
00230         {
00231                 if (!*this) return NullPtr(); 
00232                 return (**this)(gridname);
00233         }
00234 };
00235 
00236 
00237 } /* namespace Fiber */ 
00238 
00239 #endif /* __SLICE_HPP */
00240