KSquare Utilities
TokenBuffer.cpp
Go to the documentation of this file.
1 /* TokenBuffer.cpp -- Class to Manage Token Parsing
2  * Copyright (C) 1994-2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <vector>
9 #include <fstream>
10 #include <iostream>
11 //#include <istream>
12 
13 #include "MemoryDebug.h"
14 using namespace std;
15 
16 
17 #include "TokenBuffer.h"
18 using namespace KKB;
19 
20 
21 
23 {
24 }
25 
26 
27 
29 {
30 }
31 
32 
33 
35  buff (_buff),
36  nextCharPos (0)
37 
38 {
39 }
40 
41 
43 {
44 }
45 
46 
47 
49 {
50  return true;
51 }
52 
53 
54 
56 {
57  if (nextCharPos >= buff.Len ())
58  return 0;
59 
60  char c = buff[nextCharPos];
61  nextCharPos++;
62  return c;
63 } /* GetNextChar */
64 
65 
66 
68 {
69  if (nextCharPos >= buff.Len ())
70  return 0;
71  return buff[nextCharPos];
72 }
73 
74 
75 
77 {
78  if (nextCharPos > 0)
79  --nextCharPos;
80 }
81 
82 
83 
85 {
86  if (nextCharPos >= buff.Len ())
87  return true;
88  else
89  return false;
90 } /* EndOfFile */
91 
92 
93 
94 
95 
96 
97 TokenBufferStream::TokenBufferStream (istream* _in):
99  endOfFile (false),
100  fileName (),
101  fileStream (NULL),
102  in (_in)
103 {
104 }
105 
106 
108  TokenBuffer (),
109  endOfFile (false),
110  fileName (_fileName),
111  fileStream (NULL),
112  in (NULL)
113 {
114  fileStream = new ifstream (fileName.Str ());
115  if (!fileStream->is_open ())
116  {
117  delete fileStream;
118  fileStream = NULL;
119  }
120  else
121  {
122  in = fileStream;
123  }
124 }
125 
126 
127 
129 {
130  if (fileStream)
131  {
132  in = NULL;
133  delete fileStream;
134  fileStream = NULL;
135  }
136 }
137 
138 
139 
140 
141 
143 {
144  if (fileStream)
145  {
146  return fileStream->is_open ();
147  }
148 
149  return (in != NULL);
150 } /* Valid */
151 
152 
153 
154 
156 {
157  char c;
158  if (endOfFile)
159  return 0;
160 
161  c = in->get ();
162  if (in->eof())
163  {
164  endOfFile = true;
165  c = 0;
166  }
167  return c;
168 } /* GetNextChar */
169 
170 
171 
173 {
174  if (in->eof ())
175  return 0;
176  return in->peek ();
177 }
178 
179 
180 
181 
183 {
184  in->unget ();
185 }
186 
187 
188 
190 {
191  return endOfFile;
192 }
TokenBufferStr(const KKStr &_buff)
Definition: TokenBuffer.cpp:34
virtual void UnGetNextChar()
virtual bool Valid()
Definition: TokenBuffer.cpp:48
TokenBufferStream(const KKStr &_fileName)
virtual ~TokenBufferStr()
Definition: TokenBuffer.cpp:42
char operator[](kkuint32 i) const
Definition: KKStr.cpp:3430
TokenBufferStream(std::istream *_in)
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
KKTHread * KKTHreadPtr
virtual void UnGetNextChar()
Definition: TokenBuffer.cpp:76
virtual char GetNextChar()
Definition: TokenBuffer.cpp:55
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
virtual ~TokenBuffer()
Definition: TokenBuffer.cpp:28
virtual char PeekNextChar()
Definition: TokenBuffer.cpp:67
virtual char GetNextChar()
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual bool EndOfFile()
virtual bool Valid()
virtual bool EndOfFile()
Definition: TokenBuffer.cpp:84
virtual char PeekNextChar()