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

/home/pete/Work/TSE3.svn/tse3/src/tse3/FileBlockParser.h

Go to the documentation of this file.
00001 /*
00002  * @(#)FileBlockParser.h 3.00 24 Nov 1999
00003  *
00004  * Copyright (c) 2000 Pete Goodliffe (pete@cthree.org)
00005  *
00006  * This file is part of TSE3 - the Trax Sequencer Engine version 3.00.
00007  *
00008  * This library is modifiable/redistributable under the terms of the GNU
00009  * General Public License.
00010  *
00011  * You should have received a copy of the GNU General Public License along
00012  * with this program; see the file COPYING. If not, write to the Free Software
00013  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00014  *
00015  */
00016 
00017 #ifndef TSE3_FILEBLOCKPARSER_H
00018 #define TSE3_FILEBLOCKPARSER_H
00019 
00020 #include "tse3/Serializable.h"
00021 
00022 #include <map>
00023 #include <string>
00024 #include <strstream>
00025 
00026 namespace TSE3
00027 {
00028     class FileItemParser;
00029     class Clock;
00030 
00050     class FileBlockParser
00051     {
00052         public:
00053 
00058             FileBlockParser();
00059 
00075             void add(const std::string &name, Serializable *block);
00076 
00090             void add(const std::string &name, FileItemParser *item);
00091 
00104             void add(FileItemParser *item);
00105 
00126             void parse(std::istream &in, SerializableLoadInfo &info);
00127 
00128         private:
00129 
00138             void skipChunk(std::istream &i);
00139 
00140             std::map<std::string, FileItemParser*>  items;
00141             std::map<std::string, Serializable*>    blocks;
00142             FileItemParser                         *catchAll;
00143     };
00144 
00158     class FileItemParser
00159     {
00160         public:
00161 
00162             FileItemParser() {} // XXX Compiler warning without this
00163             virtual ~FileItemParser() = 0;
00164 
00172             virtual void parse(const std::string &data) = 0;
00173 
00174         private:
00175 
00176             FileItemParser &operator=(const FileItemParser &);
00177             FileItemParser(const FileItemParser &);
00178     };
00179 
00191     template <class T>
00192     class FileItemParser_OnOff : public FileItemParser
00193     {
00194         public:
00195             typedef void (T::*fn_t)(bool);
00196             FileItemParser_OnOff(T *obj, fn_t mfun)
00197             : obj(obj), mfun(mfun) {}
00201             void parse(const std::string &data)
00202             {
00203                 (obj->*mfun)(data == "On" || data == "Yes");
00204             }
00205         private:
00206             T    *obj;
00207             fn_t  mfun;
00208     };
00209 
00222     template<class T, class reason>
00223     class FileItemParser_ReasonOnOff : public FileItemParser
00224     {
00225         public:
00226             typedef void (T::*fn_t)(reason, bool);
00227             FileItemParser_ReasonOnOff(T *obj, fn_t mfun, reason r)
00228             : obj(obj), r(r) , mfun(mfun){}
00232             void parse(const std::string &data)
00233             {
00234                 (obj->*mfun)(r, (data == "On" || data == "Yes"));
00235             }
00236         private:
00237             T      *obj;
00238             reason  r;
00239             fn_t    mfun;
00240     };
00241 
00254     template <class T>
00255     class FileItemParser_Number : public FileItemParser
00256     {
00257         public:
00258             typedef void (T::*fn_t)(int);
00259             FileItemParser_Number(T *obj, fn_t mfun)
00260             : obj(obj), mfun(mfun) {}
00264             void parse(const std::string &data)
00265             {
00266                 int i;
00267                 std::istrstream si(data.c_str());
00268                 si >> i;
00269                 (obj->*mfun)(i);
00270             }
00271         private:
00272             T    *obj;
00273             fn_t  mfun;
00274     };
00275 
00290     template <class T>
00291     class FileItemParser_Clock : public FileItemParser
00292     {
00293         public:
00294             typedef void (T::*fn_t)(Clock);
00295             FileItemParser_Clock(T *obj, fn_t mfun)
00296             : obj(obj), mfun(mfun) {}
00300             void parse(const std::string &data)
00301             {
00302                 int i;
00303                 std::istrstream si(data.c_str());
00304                 si >> i;
00305                 (obj->*mfun)(i);
00306             }
00307         private:
00308             T    *obj;
00309             fn_t  mfun;
00310     };
00311 
00323     template <class T>
00324     class FileItemParser_String : public FileItemParser
00325     {
00326         public:
00327             typedef void (T::*fn_t)(const std::string &);
00328             FileItemParser_String(T *obj, fn_t mfun)
00329             : obj(obj), mfun(mfun) {}
00333             void parse(const std::string &data)
00334             {
00335                 (obj->*mfun)(data);
00336             }
00337         private:
00338             T    *obj;
00339             fn_t  mfun;
00340     };
00341 }
00342 
00343 #endif

Generated on Wed May 25 14:45:06 2005 for TSE3 by doxygen 1.3.2