Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ioblock.H

Go to the documentation of this file.
00001 #include "std/support.H"
00002 
00003 /*
00004    This class deals with reading in text bookended by:
00005 #BEGIN X
00006 #END Y
00007 */
00008 
00009 #define IOBlockList ARRAY<IOBlock *>
00010 #define CIOBlock const IOBlock
00011 class IOBlock {
00012    protected:
00013       str_ptr _name;
00014    public:
00015       IOBlock(Cstr_ptr &name) : _name(name) {}
00016       virtual ~IOBlock() {}
00017       
00018       // Callback for when #BEGIN NAME is encountered
00019       // (where NAME is what is contained in _name)
00020       virtual int consume_block(istream &, str_list &leftover) = 0;
00021 
00022       Cstr_ptr &name() const {return _name;}
00023       virtual int operator==(CIOBlock &b) {return b._name == _name;}
00024       static int consume(istream &is, const IOBlockList &list,
00025                          str_list &leftover);
00026 };
00027 
00028 template <class T>
00029 class IOBlockMeth: public IOBlock {
00030    public:
00031       typedef int (T::*METH)(istream &is, str_list &leftover);
00032    protected:
00033       METH  _meth;
00034       T    *_inst;
00035    public:
00036       IOBlockMeth(Cstr_ptr &name, METH meth, T *inst)
00037          : IOBlock(name), _meth(meth), _inst(inst) {}
00038       virtual int consume_block(istream &is, str_list &leftover)
00039          {return (_inst->*_meth)(is, leftover);}
00040       void set_obj(T *inst) { _inst = inst;}
00041 };
00042 
00043 template <class T>
00044 class IOBlockMethList : public ARRAY<IOBlockMeth<T> *> {
00045    public:
00046       IOBlockMethList(int num = 5) : ARRAY<IOBlockMeth<T> *>(num) {}
00047       void set_obj(T *inst) {
00048          for (int i = 0; i < ARRAY<IOBlockMeth<T>*>::num(); i++) {
00049             (*this)[i]->set_obj(inst);
00050          }
00051       }
00052 };

Generated on Mon Sep 18 11:39:31 2006 for jot by  doxygen 1.4.4