1 2 /************************************************************/ 3 /* */ 4 /* Predefined char stream: Input from (c++) stream. */ 5 /* */ 6 /* By Hubert Holin (Hubert.Holin (at) Bigfoot.com), 1998. */ 7 /* */ 8 /* This is completely free stuff, do whatever you want with */ 9 /* it (but then, I will take no responsability for whatever */ 10 /* may happen if you do either... caveat emptor!). */ 11 /* */ 12 /************************************************************/ 13 14 #ifndef _DLG_STREAM_INPUT_H 15 #define _DLG_STREAM_INPUT_H 16 17 #include "pccts_istream.h" 18 19 PCCTS_NAMESPACE_STD 20 21 #ifndef DLGX_H 22 #include "DLexerBase.h" 23 #endif 24 25 26 // NOTES: The semantics of the copy constructor 27 // and the affectation operator may be unwaranted... 28 // and the stream may not be reset. 29 // 30 // It would have been so much nicer for nextChar() 31 // to throw (of for the DLGInputStream to change status) 32 // upon hiting EOF than to return an "int"... 33 34 template < 35 class E, 36 class T = ::std::char_traits<E> 37 > 38 class DLG_stream_input : public DLGInputStream 39 { 40 public: 41 42 DLG_stream_input(::std::basic_istream<E,T> * p_input_stream) 43 : input(p_input_stream) 44 { 45 // nothing to do! 46 }; 47 48 DLG_stream_input(const DLG_stream_input & a_recopier) 49 : input(a_recopier.input) 50 { 51 // nothing to do! 52 }; 53 54 virtual ~DLG_stream_input() 55 { 56 this->purge(); // bloody templarized lookup... 57 }; 58 59 DLG_stream_input operator = (const DLG_stream_input & a_affecter) 60 { 61 if (this != &a_affecter) 62 { 63 input = a_affecter.input; 64 } 65 66 return(*this); 67 }; 68 69 virtual int nextChar() 70 { 71 E extracted_stuff; 72 73 input->get(extracted_stuff); 74 75 if (*input) 76 { 77 return(int(extracted_stuff)); 78 } 79 else 80 { 81 return(EOF); 82 } 83 }; 84 85 protected: 86 87 ::std::basic_istream<E,T> * input; 88 89 private: 90 91 void purge() 92 { 93 // nothing to do! 94 }; 95 }; 96 97 #endif /* _DLG_STREAM_INPUT_H */ 98 99