00001 // configsource.h: interface for the ConfigSource class. 00002 // 00004 00005 #if !defined(_CONFIGSOURCE_H__INCLUDED_) 00006 #define _CONFIGSOURCE_H__INCLUDED_ 00007 00008 #if _MSC_VER > 1000 00009 #pragma once 00010 #endif // _MSC_VER > 1000 00011 00012 //--------------------------------------------------------------------------- 00013 #include <stdlib.h> // for atol, atoi 00014 #include <stdio.h> 00015 #include <string.h> 00016 #include <limits.h> // for invalid values 00017 #include <float.h> // for invalid values 00018 00019 00020 #define MAX_LINE_LENGTH 1024 00021 00022 #define MAX_TOKEN_LENGTH 100 00023 00024 #define CS_MODE_COMMAND 0 00025 00026 00027 // These must all be negative numbers, as they are mingled with 00028 // the number of bytes read in the ReadLine() return code. 00029 enum COMFILE_STATE 00030 { 00031 COMFILE_ERROR = -2 00032 , COMFILE_EOF = -1 00033 , COMFILE_GOOD = 0 00034 }; 00035 00036 00037 //--------------------------------------------------------------------------- 00038 class ConfigSource 00039 { 00040 protected: 00041 00042 int ReadMode; 00043 00044 char curr_token[MAX_TOKEN_LENGTH+1]; 00045 00046 int LastError; // err 00047 00048 int LineParseIndex; // i 00049 00050 char CurrentLine[MAX_LINE_LENGTH+1]; // card 00051 00052 char Token[100]; 00053 bool TokenIsNull; // nul 00054 00055 char LastMessage[120]; 00056 00057 public: 00058 ConfigSource(); 00059 ~ConfigSource(); 00060 00061 virtual void Close() { }; 00062 00063 // No source from which to read 00064 virtual int ReadLine() { return COMFILE_EOF; } 00065 00066 const char* GetCurrentLine() { return (const char *)CurrentLine; } 00067 char* NextToken(); 00068 const char* GetCurrentToken() { return (const char *)Token; } 00069 char* GetToken(int n, int off); 00070 char* GetToken(int n); 00071 int Load(const char * p_cmd); 00072 int Error( char** p_textual = NULL ); 00073 bool IsTokenNull() { return TokenIsNull; } 00074 char* String(); 00075 int Int(); 00076 int Int(int n); 00077 int Int(int n, int off); 00078 long Long(); 00079 long Long(int n); 00080 long Long(int n, int off); 00081 // Double(?) returns MINDOUBLE for invalid 00082 double Double(); 00083 double Double(int n); 00084 double Double(int n, int off); 00085 bool Its(const char* p_str); 00086 00087 static int INVALID_INT; 00088 static long INVALID_LONG; 00089 static double INVALID_DOUBLE; 00090 00091 }; 00092 00093 #endif // !defined(_CONFIGSOURCE_H__INCLUDED_)