Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

Dispatcher.h

00001 #ifndef ERIS_DISPATCH_H
00002 #define ERIS_DISPATCH_H
00003 
00004 #include <string>
00005 #include <map>
00006 #include <deque>
00007 #include <list>
00008 
00009 namespace Atlas { namespace Message { class Element; } }
00010 
00011 namespace Eris {
00012 
00013 class StdBranchDispatcher;      
00014 class ClassDispatcher;
00015         
00016 // need a descriptive comment here      
00017 typedef std::deque<Atlas::Message::Element> DispatchContextDeque;               
00018         
00020 
00024 class Dispatcher
00025 {
00026 public:
00027         explicit Dispatcher(const std::string &nm);
00028         virtual ~Dispatcher();
00029 
00030         virtual Dispatcher* addSubdispatch(Dispatcher *sub, const std::string data = std::string()) = 0;
00031         virtual void rmvSubdispatch(Dispatcher *sub) = 0;
00032         
00034         virtual Dispatcher* getSubdispatch(const std::string &nm) = 0;
00035         
00037         virtual bool dispatch(DispatchContextDeque &dq) = 0;
00038 
00039         virtual bool empty() = 0;
00040 
00041         const std::string& getName() const
00042         { return _name; }
00043 
00044         virtual const std::string& getData() const
00045         { return _name; }
00046         
00047         static std::string getAnonymousSuffix(Dispatcher *d);
00048         
00049         static void enter();
00050         static void exit();
00051 protected:
00052         friend class StdBranchDispatcher;
00053         friend class ClassDispatcher;
00054                 
00055         virtual void purge() = 0;
00056         
00057         const std::string _name;
00058 public:
00059         void addRef()
00060         {++_refcount;}
00061         
00062         void decRef()
00063         {if (!(--_refcount)) delete this; }     
00064 private:        
00065         unsigned int _refcount;
00066 
00067     static bool global_inDispatch;
00068     static std::list<Dispatcher*> global_needsPurging;
00069 };
00070 
00073 class LeafDispatcher : public Dispatcher
00074 {
00075 public:
00076         explicit LeafDispatcher(const std::string &nm);
00077         virtual ~LeafDispatcher() {;}
00078                 
00079         virtual bool dispatch(DispatchContextDeque &dq);
00080 
00081         virtual Dispatcher* addSubdispatch(Dispatcher*, const std::string);
00082                 
00083         virtual void rmvSubdispatch(Dispatcher*);
00084 
00085         virtual Dispatcher* getSubdispatch(const std::string &nm);
00086         
00087         virtual bool empty();
00088         
00089 protected:
00090         virtual void purge();
00091 };
00092 
00093 class StdBranchDispatcher:  public Dispatcher
00094 {
00095 public: 
00096         explicit StdBranchDispatcher(const std::string nm = "__branch");
00097         virtual ~StdBranchDispatcher();
00098         
00099         virtual bool dispatch(DispatchContextDeque &dq)
00100         { return subdispatch(dq); }
00101 
00102         virtual Dispatcher* addSubdispatch(Dispatcher *sub, const std::string data);
00103         virtual void rmvSubdispatch(Dispatcher *sub);
00104         virtual Dispatcher* getSubdispatch(const std::string &nm);
00105 
00106         virtual bool empty()
00107         { return _subs.empty(); }
00108 protected:
00109         typedef std::map<std::string, Dispatcher*> DispatcherDict;
00110 
00112         bool subdispatch(DispatchContextDeque &dq);
00113         void safeSubErase(const DispatcherDict::iterator &d);
00114 
00115         virtual void purge();
00116 
00117         DispatcherDict _subs;
00118 };
00119 
00120 }
00121 
00122 #endif

Generated on Wed Nov 10 20:56:36 2004 for Eris by  doxygen 1.3.9.1