bc6c3d35 | /* Copyright (C) CJ Affiliate * * You may use, distribute and modify this code under the * terms of the GNU General Public License version 2 or * later. * * You should have received a copy of the license with this * file. If not, you will find a copy in the "LICENSE" file * at https://github.com/cjdev/dual-control. */ |
215ea751 | #ifndef SYS_FSTREAM_H #define SYS_FSTREAM_H #include <memory> #include <sstream> |
af3a4cd4 | #include <iostream> |
215ea751 | |
bc6c3d35 | class fstreams_ifc { public: typedef std::shared_ptr<std::istream> pstream; |
af3a4cd4 | typedef std::shared_ptr<std::ostream> postream; |
4d825470 | virtual ~fstreams_ifc() {} |
af3a4cd4 | virtual pstream open_fstream (const std::string &file_path) const |
bc6c3d35 | { return pstream (new std::istringstream ("")); } |
d10906ee | virtual postream open_ofstream (const std::string &file_path, std::ios_base::openmode mode) const { return postream (new std::ostringstream ("")); |
af3a4cd4 | } |
215ea751 | }; |
3ae0e083 | class fstreams |
bc6c3d35 | { public: typedef std::shared_ptr<fstreams_ifc> delegate; private: delegate delegate_; public: |
3ae0e083 | typedef fstreams_ifc::pstream pstream; |
af3a4cd4 | typedef fstreams_ifc::postream postream; |
bc6c3d35 | fstreams (const delegate &delegate) : delegate_ (delegate) {} fstreams() : fstreams (delegate (new fstreams_ifc)) {} |
af3a4cd4 | pstream open_fstream (const std::string &file_path) const |
bc6c3d35 | { return delegate_->open_fstream (file_path); } |
d10906ee | postream open_ofstream (const std::string &file_path, std::ios_base::openmode mode) const |
af3a4cd4 | { return delegate_->open_ofstream (file_path, mode); } |
bc6c3d35 | static fstreams create(); |
215ea751 | }; #endif |