00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CLASSAD_LEXER_SOURCE_H__
00022 #define __CLASSAD_LEXER_SOURCE_H__
00023
00024 #include "classad/common.h"
00025 #include <iosfwd>
00026
00027 BEGIN_NAMESPACE(classad)
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class LexerSource
00041 {
00042 public:
00043 LexerSource()
00044 {
00045 return;
00046 }
00047 virtual ~LexerSource()
00048 {
00049 return;
00050 }
00051
00052
00053 virtual int ReadCharacter(void) = 0;
00054
00055
00056
00057 virtual int ReadPreviousCharacter(void) { return _previous_character; };
00058
00059
00060
00061
00062
00063
00064 virtual void UnreadCharacter(void) = 0;
00065 virtual bool AtEnd(void) const = 0;
00066 protected:
00067 int _previous_character;
00068 private:
00069
00070
00071
00072
00073 LexerSource(const LexerSource &) { return; }
00074 LexerSource &operator=(const LexerSource &) { return *this; }
00075 };
00076
00077
00078 class FileLexerSource : public LexerSource
00079 {
00080 public:
00081 FileLexerSource(FILE *file);
00082 virtual ~FileLexerSource();
00083
00084 virtual void SetNewSource(FILE *file);
00085
00086 virtual int ReadCharacter(void);
00087 virtual void UnreadCharacter(void);
00088 virtual bool AtEnd(void) const;
00089
00090 private:
00091 FILE *_file;
00092 FileLexerSource(const FileLexerSource &) : LexerSource() { return; }
00093 FileLexerSource &operator=(const FileLexerSource &) { return *this; }
00094 };
00095
00096
00097
00098 class InputStreamLexerSource : public LexerSource
00099 {
00100 public:
00101 InputStreamLexerSource(std::istream &stream);
00102 virtual ~InputStreamLexerSource();
00103
00104 virtual void SetNewSource(std::istream &stream);
00105
00106 virtual int ReadCharacter(void);
00107 virtual void UnreadCharacter(void);
00108 virtual bool AtEnd(void) const;
00109
00110 private:
00111 std::istream *_stream;
00112 InputStreamLexerSource(const InputStreamLexerSource &) : LexerSource() { return; }
00113 InputStreamLexerSource &operator=(const InputStreamLexerSource &) { return *this; }
00114 };
00115
00116
00117 class CharLexerSource : public LexerSource
00118 {
00119 public:
00120 CharLexerSource(const char *string, int offset=0);
00121 virtual ~CharLexerSource();
00122
00123 virtual void SetNewSource(const char *string, int offset=0);
00124 virtual int ReadCharacter(void);
00125 virtual void UnreadCharacter(void);
00126 virtual bool AtEnd(void) const;
00127
00128 virtual int GetCurrentLocation(void) const;
00129 private:
00130 const char *_string;
00131 int _offset;
00132 CharLexerSource(const CharLexerSource &) : LexerSource() { return; }
00133 CharLexerSource &operator=(const CharLexerSource &) { return *this; }
00134 };
00135
00136
00137 class StringLexerSource : public LexerSource
00138 {
00139 public:
00140 StringLexerSource(const std::string *string, int offset=0);
00141 virtual ~StringLexerSource();
00142
00143 virtual void SetNewSource(const std::string *string, int offset=0);
00144
00145 virtual int ReadCharacter(void);
00146 virtual void UnreadCharacter(void);
00147 virtual bool AtEnd(void) const;
00148
00149 virtual int GetCurrentLocation(void) const;
00150 private:
00151 const std::string *_string;
00152 int _offset;
00153 StringLexerSource(const StringLexerSource &) : LexerSource() { return; }
00154 StringLexerSource &operator=(const StringLexerSource &) { return *this; }
00155 };
00156
00157 END_NAMESPACE
00158
00159 #endif