Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArFileParser.h

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #ifndef ARFILEPARSER_H
00027 #define ARFILEPARSER_H
00028 
00029 #include "ariaTypedefs.h"
00030 #include "ArArgumentParser.h"
00031 #include "ArFunctor.h"
00032 #include "ariaUtil.h"
00033 
00035 
00057 class ArFileParser
00058 {
00059 public:
00061   AREXPORT ArFileParser(const char *baseDirectory = "./");
00063   AREXPORT ~ArFileParser(void);
00065   AREXPORT bool addHandler(const char *keyword, 
00066                ArRetFunctor1<bool, ArArgumentBuilder *> *functor);
00068   AREXPORT bool addHandlerWithError(const char *keyword, 
00069                ArRetFunctor3<bool, ArArgumentBuilder *, 
00070                     char *, size_t> *functor);
00072   AREXPORT bool remHandler(const char *keyword, bool logIfCannotFind = true);
00074   AREXPORT bool remHandler(ArRetFunctor1<bool, ArArgumentBuilder *> *functor);
00076   AREXPORT bool remHandler(
00077       ArRetFunctor3<bool, ArArgumentBuilder *, char *, size_t> *functor);
00078   /* this shouldn't be needed and would be inelegant with the new scheme, 
00079      if someone needs it let us know and I'll update it somehow
00081   AREXPORT ArRetFunctor1<bool, ArArgumentBuilder *> *getHandler(const char *keyword);
00082   */
00083   
00085   AREXPORT bool parseFile(const char *fileName, bool continueOnErrors = true,
00086               bool noFileNotFoundMessage = false,
00087               char *errorBuffer = NULL, size_t errorBufferLen = 0);
00088 
00090 
00097   AREXPORT bool parseFile(FILE *file, char *buffer, int bufferLength, 
00098               bool continueOnErrors = true, 
00099               char *errorBuffer = NULL, size_t errorBufferLen = 0);
00100 
00102   AREXPORT const char *getBaseDirectory(void) const;
00104   AREXPORT void setBaseDirectory(const char *baseDirectory);
00106   AREXPORT bool parseLine(char *line, char *errorBuffer = NULL, 
00107               size_t errorBufferLen = 0);
00109   AREXPORT void resetCounters(void);
00110 protected:
00111   class HandlerCBType
00112   {
00113     public:
00114     HandlerCBType(
00115         ArRetFunctor3<bool, ArArgumentBuilder *, char *, size_t> *functor)
00116     {
00117       myCallbackWithError = functor;
00118       myCallback = NULL;
00119     }
00120     HandlerCBType(ArRetFunctor1<bool, ArArgumentBuilder *> *functor)
00121     {
00122       myCallbackWithError = NULL;
00123       myCallback = functor;
00124     }
00125     ~HandlerCBType() {}
00126     bool call(ArArgumentBuilder *arg, char *errorBuffer, 
00127           size_t errorBufferLen) 
00128     { 
00129       if (myCallbackWithError != NULL) 
00130     return myCallbackWithError->invokeR(arg, errorBuffer, errorBufferLen);
00131       else if (myCallback != NULL) 
00132     return myCallback->invokeR(arg); 
00133       // if we get here there's a problem
00134       ArLog::log(ArLog::Terse, "ArFileParser: Horrible problem with process callbacks");
00135       return false;
00136     }
00137     bool haveFunctor(
00138         ArRetFunctor3<bool, ArArgumentBuilder *, char *, size_t> *functor)
00139     { 
00140       if (myCallbackWithError == functor) 
00141     return true; 
00142       else 
00143     return false; 
00144     }
00145     bool haveFunctor(ArRetFunctor1<bool, ArArgumentBuilder *> *functor)
00146     { 
00147       if (myCallback == functor) 
00148     return true; 
00149       else 
00150     return false; 
00151     }
00152     const char *getName(void) 
00153     { 
00154       if (myCallbackWithError != NULL)
00155     return myCallbackWithError->getName();
00156       else if (myCallback != NULL)
00157     return myCallback->getName();
00158       // if we get here there's a problem
00159       ArLog::log(ArLog::Terse, "ArFileParser: Horrible problem with process callback names");
00160       return NULL;
00161     }
00162     protected:
00163     ArRetFunctor3<bool, ArArgumentBuilder *, char *, size_t> *myCallbackWithError;
00164     ArRetFunctor1<bool, ArArgumentBuilder *> *myCallback;
00165   };
00166   int myLineNumber;
00167   std::string myBaseDir;
00168   std::map<std::string, HandlerCBType *, ArStrCaseCmpOp> myMap;
00169   // handles that NULL case
00170   HandlerCBType *myRemainderHandler;
00171 };
00172 
00173 #endif // ARFILEPARSER_H
00174 
00175 

Generated on Tue Feb 20 10:51:39 2007 for Aria by  doxygen 1.4.0