@@ -215,25 +215,12 @@ void simplecpp::Token::printOut() const
215215
216216class simplecpp ::TokenList::Stream {
217217public:
218- Stream (std::istream &istr)
219- : istr(istr)
220- , bom(getAndSkipBOM())
221- , isUtf16(bom == 0xfeff || bom == 0xfffe )
222- {
223- }
218+ virtual ~Stream () {}
224219
225- int get () {
226- return istr.get ();
227- }
228- int peek () {
229- return istr.peek ();
230- }
231- void unget () {
232- istr.unget ();
233- }
234- bool good () {
235- return istr.good ();
236- }
220+ virtual int get () = 0;
221+ virtual int peek () = 0;
222+ virtual void unget () = 0;
223+ virtual bool good () = 0;
237224
238225 unsigned char readChar ()
239226 {
@@ -294,7 +281,12 @@ class simplecpp::TokenList::Stream {
294281 unget ();
295282 }
296283
297- private:
284+ protected:
285+ void init () {
286+ bom = getAndSkipBOM ();
287+ isUtf16 = (bom == 0xfeff || bom == 0xfffe );
288+ }
289+
298290 unsigned short getAndSkipBOM ()
299291 {
300292 const int ch1 = peek ();
@@ -322,17 +314,41 @@ class simplecpp::TokenList::Stream {
322314 return 0 ;
323315 }
324316
317+ unsigned short bom;
318+ bool isUtf16;
319+ };
320+
321+ class StdIStream : public simplecpp ::TokenList::Stream {
322+ public:
323+ StdIStream (std::istream &istr)
324+ : istr(istr)
325+ {
326+ init ();
327+ }
328+
329+ virtual int get () {
330+ return istr.get ();
331+ }
332+ virtual int peek () {
333+ return istr.peek ();
334+ }
335+ virtual void unget () {
336+ istr.unget ();
337+ }
338+ virtual bool good () {
339+ return istr.good ();
340+ }
341+
342+ private:
325343 std::istream &istr;
326- const unsigned short bom;
327- const bool isUtf16;
328344};
329345
330346simplecpp::TokenList::TokenList (std::vector<std::string> &filenames) : frontToken(nullptr ), backToken(nullptr ), files(filenames) {}
331347
332348simplecpp::TokenList::TokenList (std::istream &istr, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
333349 : frontToken(nullptr ), backToken(nullptr ), files(filenames)
334350{
335- simplecpp::TokenList::Stream stream (istr);
351+ StdIStream stream (istr);
336352 readfile (stream,filename,outputList);
337353}
338354
@@ -1310,7 +1326,7 @@ namespace simplecpp {
13101326 Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f), valueDefinedInCode_(false ) {
13111327 const std::string def (name + ' ' + value);
13121328 std::istringstream istr (def);
1313- simplecpp::TokenList::Stream stream (istr);
1329+ StdIStream stream (istr);
13141330 tokenListDefine.readfile (stream);
13151331 if (!parseDefine (tokenListDefine.cfront ()))
13161332 throw std::runtime_error (" bad macro syntax. macroname=" + name + " value=" + value);
0 commit comments