// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz // http://chaosforge.org/ // // This file is part of NV Libraries. // For conditions of distribution and use, see copyright notice in nv.hh /** * @file std_stream.hh * @author Kornel Kisielewicz epyon@chaosforge.org * @brief stream adapter for usage with STL */ #ifndef NV_STD_STREAM_HH #define NV_STD_STREAM_HH #include #include #include #include #include namespace nv { class std_streambuf : public std::streambuf { public: explicit std_streambuf( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 ); virtual ~std_streambuf(); protected: stream* m_stream; bool m_owner; std::vector m_buffer; std::size_t m_put_back; private: std_streambuf( const std_streambuf& ); // dissalow copy std_streambuf *operator =( const std_streambuf& ); // dissalow assign int_type underflow(); }; class std_stream : public std::istream { public: explicit std_stream( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 ) : std::istream( &m_streambuf ) , m_streambuf( source, owner, bsize, put_back ) {} private: std_streambuf m_streambuf; }; } // namespace nv #endif // NV_STD_STREAM_HH