>xabsl   The Extensible Agent Behavior Specification Language

XabslEngine Class Library Reference

 

XabslTools.h

Go to the documentation of this file.
00001 /**
00002 * @file XabslTools.h
00003 *
00004 * Definition of several helper classes for the Engine.
00005 *
00006 * @author <a href="http://www.martin-loetzsch.de">Martin Loetzsch</a>
00007 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00008 * @author <a href="http://www.informatik.hu-berlin.de/~juengel">Matthias Juengel</a>
00009 */
00010 
00011 #ifndef __XabslTools_h_
00012 #define __XabslTools_h_
00013 
00014 #include "XabslArray.h"
00015 
00016 namespace xabsl 
00017 {
00018 
00019 /**
00020 * A Engine helper class for reading input data from files or from memory.
00021 */
00022 class InputSource
00023 {
00024 public:
00025   /** Virtual destructor */
00026   virtual ~InputSource() {}
00027   
00028   /** opens the source that contains the intermediate code */
00029   virtual bool open() = 0;
00030   
00031   /** closes the source */
00032   virtual void close() = 0;
00033 
00034   /** reads a numeric value from the input source */
00035   virtual double readValue() = 0;
00036 
00037   /** 
00038   * reads a string from the input source
00039   * @param destination The position where to write the string
00040   * @param maxLength the maximum length of the string
00041   * @return if the read succeded
00042   */
00043   virtual bool readString(char* destination, int maxLength) = 0;
00044 };
00045 
00046 /**
00047 * A Engine helper class for handling errors and debug messages
00048 */
00049 class ErrorHandler
00050 {
00051 public:
00052   /** constructor */
00053   ErrorHandler() : errorsOccurred(false) {};
00054   
00055   /** virtual destructor */
00056   virtual ~ErrorHandler() {}
00057 
00058   /** 
00059   * Prints out an error
00060   * @param text The text to display
00061   */
00062   virtual void printError(const char* text) = 0;
00063 
00064   /**
00065   * Prints out a message
00066   * @param text The text to display
00067   */
00068   virtual void printMessage(const char* text) = 0;
00069 
00070   /** 
00071   * Formats a error message and calls the printError() function.
00072   * @param format Format string as used by printf defined in stdio.h.
00073   * @param ... See printf in stdio.h.
00074   */
00075   void error(const char* format, ...);
00076 
00077   /** 
00078   * Formats a message and calls the printMessage() function 
00079   * @param format Format string as used by printf defined in stdio.h.
00080   * @param ... See printf in stdio.h.
00081   */
00082   void message(const char* format, ...);
00083 
00084   /** if errors occurred */
00085   bool errorsOccurred;
00086 
00087 private:
00088   /** a buffer for errors and debug messages */
00089   char messageBuffer[300];
00090 };
00091 
00092 /**
00093 * @typedef TimeFunction
00094 * A pointer to a function that returns the current system time.
00095 */
00096 typedef unsigned (*TimeFunction)();
00097 
00098 // If that macro is defined, the engine prints a lot of debug messages during initialization 
00099 //#define _DO_DEBUG_INIT
00100 
00101 /** Expressions inside that macro are only executed if XABSL_DEBUG_INIT is defined */
00102 #ifdef _DO_DEBUG_INIT
00103 #define XABSL_DEBUG_INIT(expression) expression
00104 #else
00105 #define XABSL_DEBUG_INIT(expression) /**/
00106 #endif
00107 
00108 } // namespace
00109 
00110 #endif //__XabslTools_h_

Up | Main Page | Generated at Wed Aug 19 17:32:29 2009.