1 | #include <iostream>
|
---|
2 | #include <cstring>
|
---|
3 |
|
---|
4 | #include <boost/iostreams/filtering_stream.hpp>
|
---|
5 | #include <boost/iostreams/code_converter.hpp>
|
---|
6 |
|
---|
7 | struct SinkDev: public boost::iostreams::device<boost::iostreams::output, char>
|
---|
8 | {
|
---|
9 | std::streamsize write(const char* s, std::streamsize n)
|
---|
10 | {
|
---|
11 | std::cerr << "SinkDev::write(): Recieved " << n << " characters.\n";
|
---|
12 |
|
---|
13 | return n;
|
---|
14 | }
|
---|
15 | };
|
---|
16 |
|
---|
17 | struct SourceDev: public boost::iostreams::device<boost::iostreams::input, char>
|
---|
18 | {
|
---|
19 | std::streamsize read(char* s, std::streamsize n)
|
---|
20 | {
|
---|
21 | std::cerr << "SourceDev::read(): Sending " << n << " characters.\n";
|
---|
22 |
|
---|
23 | char data[] = "wrlubriachlasluprlebriuq";
|
---|
24 |
|
---|
25 | std::memcpy(s, data, n);
|
---|
26 |
|
---|
27 | return n;
|
---|
28 | }
|
---|
29 | };
|
---|
30 |
|
---|
31 | int main()
|
---|
32 | {
|
---|
33 | using namespace boost;
|
---|
34 |
|
---|
35 | // This our test output stream
|
---|
36 | iostreams::filtering_stream<iostreams::output, wchar_t> out;
|
---|
37 | // Add a code converter filter with a 16 character buffer
|
---|
38 | out.push(iostreams::code_converter<SinkDev>(SinkDev(), 16), 0);
|
---|
39 |
|
---|
40 | // This our test output stream
|
---|
41 | iostreams::filtering_stream<boost::iostreams::input, wchar_t> in;
|
---|
42 | // Add a code converter filter with a 16 character buffer
|
---|
43 | in.push(iostreams::code_converter<SourceDev>(SourceDev(), 16), 0);
|
---|
44 |
|
---|
45 | wchar_t data[] = L"wieriaciafrianoechlajoes";
|
---|
46 |
|
---|
47 | // Test the output stream
|
---|
48 | std::cerr << "main(): Sending 24 characters of data to output stream\n";
|
---|
49 | out.write(data, 24);
|
---|
50 | std::cerr << "main(): Calling a sync on the output stream\n";
|
---|
51 | out.strict_sync();
|
---|
52 | std::cerr << "main(): Sending 21 characters of data to output stream\n";
|
---|
53 | out.write(data, 21);
|
---|
54 |
|
---|
55 | std::cerr << '\n';
|
---|
56 |
|
---|
57 | // Test the input stream
|
---|
58 | std::cerr << "main(): Asking for 24 characters of data from input stream\n";
|
---|
59 | in.read(data, 24);
|
---|
60 | std::cerr << "main(): Calling a sync on the input stream\n";
|
---|
61 | in.strict_sync();
|
---|
62 | std::cerr << "main(): Asking for 9 characters of data from input stream\n";
|
---|
63 | in.read(data, 9);
|
---|
64 |
|
---|
65 | std::cerr << '\n';
|
---|
66 |
|
---|
67 | std::cerr << "main(): At end of test case\n";
|
---|
68 |
|
---|
69 | return 0;
|
---|
70 | }
|
---|