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