[395] | 1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
[134] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
| 6 |
|
---|
[134] | 7 | /**
|
---|
| 8 | * @file std_stream.hh
|
---|
| 9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
| 10 | * @brief stream adapter for usage with STL
|
---|
| 11 | */
|
---|
| 12 |
|
---|
[395] | 13 | #ifndef NV_IO_STD_STREAM_HH
|
---|
| 14 | #define NV_IO_STD_STREAM_HH
|
---|
[134] | 15 |
|
---|
[395] | 16 | #include <nv/common.hh>
|
---|
[422] | 17 | #include <nv/stl/stream.hh>
|
---|
[134] | 18 | #include <streambuf>
|
---|
[138] | 19 | #include <istream>
|
---|
[134] | 20 | #include <vector>
|
---|
| 21 |
|
---|
| 22 | namespace nv
|
---|
| 23 | {
|
---|
[138] | 24 |
|
---|
| 25 | class std_streambuf : public std::streambuf
|
---|
[134] | 26 | {
|
---|
| 27 | public:
|
---|
[138] | 28 | explicit std_streambuf( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 );
|
---|
| 29 | virtual ~std_streambuf();
|
---|
[134] | 30 | protected:
|
---|
| 31 | stream* m_stream;
|
---|
| 32 | bool m_owner;
|
---|
| 33 | std::vector<char> m_buffer;
|
---|
| 34 | std::size_t m_put_back;
|
---|
| 35 | private:
|
---|
[138] | 36 | std_streambuf( const std_streambuf& ); // dissalow copy
|
---|
| 37 | std_streambuf *operator =( const std_streambuf& ); // dissalow assign
|
---|
[134] | 38 | int_type underflow();
|
---|
| 39 | };
|
---|
| 40 |
|
---|
[138] | 41 | class std_stream : public std::istream
|
---|
| 42 | {
|
---|
| 43 | public:
|
---|
| 44 | explicit std_stream( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 )
|
---|
| 45 | : std::istream( &m_streambuf )
|
---|
| 46 | , m_streambuf( source, owner, bsize, put_back )
|
---|
| 47 | {}
|
---|
| 48 | private:
|
---|
| 49 | std_streambuf m_streambuf;
|
---|
| 50 | };
|
---|
| 51 |
|
---|
[134] | 52 | } // namespace nv
|
---|
| 53 |
|
---|
[395] | 54 | #endif // NV_IO_STD_STREAM_HH
|
---|