00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00079
00081
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
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
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
00170 HandlerCBType *myRemainderHandler;
00171 };
00172
00173 #endif // ARFILEPARSER_H
00174
00175