FragmentID.hpp

00001 #ifndef __FIBER_FIELD_FRAGMENTID_HPP
00002 #define __FIBER_FIELD_FRAGMENTID_HPP
00003 
00004 #include "FieldAPI.h"
00005 #include <memcore/Interface.hpp>
00006 #include <string>
00007 #include "CreativeArray.hpp"
00008 #include "FragmentSelector.hpp"
00009 
00010 namespace Fiber
00011 {
00012         using MemCore::ReferenceBase;
00013         using MemCore::Intercube;
00014         using MemCore::Interface;
00015         using MemCore::interface_cast;
00016         using MemCore::StrongPtr;
00017         using MemCore::NullPtr;
00018         using std::string;
00019         using std::map;
00020 
00021 
00022 class   FIELD_API FragmentIDContainer;
00023 
00024 
00039 class   FIELD_API FragmentID : public ReferenceBase<FragmentID>, public Intercube
00040 {
00041 
00042         string  name;
00043 
00044 public:
00045 
00047         FragmentID(const string&Name);
00048 
00050         ~FragmentID();
00051 
00053         const string&Name() const
00054         {
00055                 return name;
00056         } 
00057 
00061         typedef FragmentIDContainer Container;
00062 
00063 };
00064 
00068 template <int Dims>
00069 class FragmentLocation : public Interface<FragmentLocation<Dims> >
00070 {
00071 public:
00072         MultiIndex<Dims> Offset,
00073                          OverlapStart,
00074                          OverlapEnd;
00075 };
00076 
00081 class   FIELD_API FragmentIterator
00082 {
00083 public:
00085         virtual ~FragmentIterator();
00086 
00088         virtual bool apply(const RefPtr<FragmentID>&, const RefPtr<CreativeArrayBase>&) = 0;
00089 };
00090 
00091 typedef FragmentIterator FieldFragmentIterator;
00092 
00095 struct  CompareFragmentIDs
00096 {
00097         bool operator()(const RefPtr<FragmentID>&A, const RefPtr<FragmentID>&B) const
00098         {
00099                 if (A == B) return false;
00100                 if (!A) return false;
00101                 if (!B) return true;
00102 
00103                 return A->Name() < B->Name();
00104         }
00105 };
00106 
00107 
00110 class   FIELD_API FragmentIDContainer
00111 {
00112         typedef std::set<RefPtr<FragmentID>, CompareFragmentIDs> FragmentIDset_t; 
00113 
00114         FragmentIDset_t FragmentIDset;
00115 
00116 public: 
00118         FragmentIDContainer();
00119 
00121         FragmentIDContainer(const FragmentIDContainer&);
00122 
00124         FragmentIDContainer&operator=(const FragmentIDContainer&);
00125 
00127         ~FragmentIDContainer(); 
00128 
00130         RefPtr<FragmentID>      findFragmentID(const string&name) const;
00131 
00133         RefPtr<FragmentID>      createFragmentID(const string&name); 
00134 
00136         bool                    removeFragmentID(const string&name);
00137 
00139         struct  Iterator
00140         {
00142                 virtual ~Iterator();
00143 
00145                 virtual bool apply(const RefPtr<FragmentID>&) = 0;
00146         }; 
00147 
00149         int iterate(Iterator&) const;
00150 };
00151 
00152 
00153 } /* namespace Fiber */ 
00154 
00155 #endif /* __FIBER_FIELD__FRAGMENTID_HPP */
00156