Debian Codegraph @

yo/concrete/examples/fistream/fistream.h

raw
1 #ifndef INCLUDED_FISTREAM_H_
2 #define INCLUDED_FISTREAM_H_
3
4 #include <iosfwd>
5 #include <istream>
6 #include <sstream>
7 #include <fstream>
8 #include <memory>
9
10 /*
11 fis >> field(3) >> x extracts x over max 3 positions.
12 First, 3 chars are extracted from fis itself. They are put
13 in a separate buffer which is then extracted. What if the extraction
14 is not complete? Then a rest remains in the buffer, most likely
15 resulting in a failing read, thereafter. Manipulators are provided
16 to prevent this: field(0) returns to the non-fixed reading: the
17 last field, even if not completely read, is then further ignored.
18 field() reads the next field, same width as the previous field. If
19 no field has been set before, field() has no effect.
20 */
21
22 namespace FBB
23 {
24
25 class field;
26
27 //INITIAL
28 class Fistream: public std::istream
29 {
30 std::unique_ptr<std::filebuf> d_filebuf;
31 std::streambuf *d_streambuf;
32 std::istringstream d_iss;
33 size_t d_width;
34 //=
35 public:
36 //CONS
37 Fistream(std::istream &stream);
38 Fistream(char const *name,
39 std::ios::openmode mode = std::ios::in);
40 //=
41 std::istream &setField(field const &params);
42 private:
43 void setBuffer();
44 };
45 //FIELD
46 class field
47 {
48 friend class Fistream;
49 size_t d_width;
50 bool d_newWidth;
51
52 public:
53 field(size_t width);
54 field();
55 };
56
57 inline field::field(size_t width)
58 :
59 d_width(width),
60 d_newWidth(true)
61 {}
62
63 inline field::field()
64 :
65 d_newWidth(false)
66 {}
67 //=
68 } // FBB
69
70 //OPEX
71 namespace std
72 {
73 istream &operator>>(istream &str, FBB::field const &params);
74 }
75 //=
76
77 #endif