arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

CallbackMap.h

Go to the documentation of this file.
00001 //
00002 //------------------------------------------------------------------------
00003 //
00004 // File   : CallbackMap.h
00005 // Author : Patrick McCormick (pat@acl.lanl.gov)
00006 //
00007 // $Date: 2003/08/01 22:10:47 $
00008 // $Revision: 1.5 $
00009 //
00010 //
00011 // This class implements a simple lookup map from a CallbackID to a 
00012 // callback (a function or a method).  Using the map you can then do
00013 // a quick lookup from ID to callback.  This code is really nothing 
00014 // more than a wrapper around the STL map class. 
00015 //
00016 // TODO:  As it stands it is only possible to call a single function
00017 // for each ID.  There might be situations where this limits your 
00018 // flexibility.  
00019 // 
00020 // This code is based on the VIF (Visualization Interconnection Framework)
00021 // that helped to drive TRex -- back when there were such beasts... 
00022 //
00023 //------------------------------------------------------------------------
00024 //
00025 #ifndef KOKO_CALLBACK_MAP_H_
00026 #define KOKO_CALLBACK_MAP_H_
00027 
00028 #include <map> // Should hack this to support systems with map.h as well... 
00029 
00030 #include "Callbacks.h"
00031 #include "koko.h"
00032 
00033 class KokoBuffer;
00034 
00035 class CallbackMap
00036 {
00037   public:
00038     CallbackMap(void);
00039     ~CallbackMap(void);
00040 
00041     bool Add(KokoTag tag, Callback *cb);
00042     inline bool Add(KokoTag tag, Callback &cb)
00043     { 
00044       Callback *cbp = cb.clone();
00045       this->Add(tag, cbp);
00046     };
00047           
00048     bool Remove(KokoTag tag);
00049     bool Invoke(KokoTag tag, KokoBuffer &databuf);     
00050 
00051   private:
00052     typedef std::pair<KokoTag, Callback *> CBPair;
00053     typedef std::map<KokoTag, Callback *>  CBMap;
00054     typedef CBMap::iterator                CBIterator;
00055     typedef std::pair<CBIterator, bool>    CBBool;
00056     CBMap                                  cbmap;
00057 };
00058 
00059 #endif

Send questions, comments, and bug reports to:
jmk