DLG_stream_input.h 1.9 KB

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