@@ -227,12 +227,36 @@ void simplecpp::Token::printOut() const
227227 std::cout << std::endl;
228228}
229229
230+ class simplecpp ::TokenList::Stream {
231+ public:
232+ Stream (std::istream &istr)
233+ : istr(istr)
234+ {}
235+
236+ int get () {
237+ return istr.get ();
238+ }
239+ int peek () {
240+ return istr.peek ();
241+ }
242+ void unget () {
243+ istr.unget ();
244+ }
245+ bool good () {
246+ return istr.good ();
247+ }
248+
249+ private:
250+ std::istream &istr;
251+ };
252+
230253simplecpp::TokenList::TokenList (std::vector<std::string> &filenames) : frontToken(nullptr ), backToken(nullptr ), files(filenames) {}
231254
232255simplecpp::TokenList::TokenList (std::istream &istr, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
233256 : frontToken(nullptr ), backToken(nullptr ), files(filenames)
234257{
235- readfile (istr,filename,outputList);
258+ simplecpp::TokenList::Stream stream (istr);
259+ readfile (stream,filename,outputList);
236260}
237261
238262simplecpp::TokenList::TokenList (const TokenList &other) : frontToken(nullptr ), backToken(nullptr ), files(other.files)
@@ -332,7 +356,7 @@ std::string simplecpp::TokenList::stringify() const
332356 return ret.str ();
333357}
334358
335- static unsigned char readChar (std::istream &istr, unsigned int bom)
359+ static unsigned char readChar (simplecpp::TokenList::Stream &istr, unsigned int bom)
336360{
337361 unsigned char ch = static_cast <unsigned char >(istr.get ());
338362
@@ -363,7 +387,7 @@ static unsigned char readChar(std::istream &istr, unsigned int bom)
363387 return ch;
364388}
365389
366- static unsigned char peekChar (std::istream &istr, unsigned int bom)
390+ static unsigned char peekChar (simplecpp::TokenList::Stream &istr, unsigned int bom)
367391{
368392 unsigned char ch = static_cast <unsigned char >(istr.peek ());
369393
@@ -384,14 +408,14 @@ static unsigned char peekChar(std::istream &istr, unsigned int bom)
384408 return ch;
385409}
386410
387- static void ungetChar (std::istream &istr, unsigned int bom)
411+ static void ungetChar (simplecpp::TokenList::Stream &istr, unsigned int bom)
388412{
389413 istr.unget ();
390414 if (bom == 0xfeff || bom == 0xfffe )
391415 istr.unget ();
392416}
393417
394- static unsigned short getAndSkipBOM (std::istream &istr)
418+ static unsigned short getAndSkipBOM (simplecpp::TokenList::Stream &istr)
395419{
396420 const int ch1 = istr.peek ();
397421
@@ -473,7 +497,7 @@ void simplecpp::TokenList::lineDirective(unsigned int fileIndex, unsigned int li
473497
474498static const std::string COMMENT_END (" */" );
475499
476- void simplecpp::TokenList::readfile (std::istream &istr, const std::string &filename, OutputList *outputList)
500+ void simplecpp::TokenList::readfile (Stream &istr, const std::string &filename, OutputList *outputList)
477501{
478502 std::stack<simplecpp::Location> loc;
479503
@@ -1166,7 +1190,7 @@ void simplecpp::TokenList::removeComments()
11661190 }
11671191}
11681192
1169- std::string simplecpp::TokenList::readUntil (std::istream &istr, const Location &location, const char start, const char end, OutputList *outputList, unsigned int bom)
1193+ std::string simplecpp::TokenList::readUntil (Stream &istr, const Location &location, const char start, const char end, OutputList *outputList, unsigned int bom)
11701194{
11711195 std::string ret;
11721196 ret += start;
@@ -1297,7 +1321,8 @@ namespace simplecpp {
12971321 Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f), valueDefinedInCode_(false ) {
12981322 const std::string def (name + ' ' + value);
12991323 std::istringstream istr (def);
1300- tokenListDefine.readfile (istr);
1324+ simplecpp::TokenList::Stream stream (istr);
1325+ tokenListDefine.readfile (stream);
13011326 if (!parseDefine (tokenListDefine.cfront ()))
13021327 throw std::runtime_error (" bad macro syntax. macroname=" + name + " value=" + value);
13031328 }
0 commit comments