diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-04-13 21:53:43 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-04-13 21:53:43 +0000 |
commit | f9471e983baccaa4f43cfa43463c7a26bcb16c55 (patch) | |
tree | eee3a8fee8071d78821444ef5b871557253b156d /libdimensionxx/dimensionxx | |
parent | 11c2b9bbc790216eeb22a1e4d4de8161394c3fbf (diff) | |
download | dimension-f9471e983baccaa4f43cfa43463c7a26bcb16c55.tar.xz |
Use an RAII interface to fopencookie().
Diffstat (limited to 'libdimensionxx/dimensionxx')
-rw-r--r-- | libdimensionxx/dimensionxx/cookie.hpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/libdimensionxx/dimensionxx/cookie.hpp b/libdimensionxx/dimensionxx/cookie.hpp index 639fbfe..a2a3324 100644 --- a/libdimensionxx/dimensionxx/cookie.hpp +++ b/libdimensionxx/dimensionxx/cookie.hpp @@ -30,9 +30,35 @@ namespace Dimension { - std::FILE* fcookie(std::istream& istr); - std::FILE* fcookie(std::ostream& ostr); - std::FILE* fcookie(std::iostream& iostr); + // Simple RAII class for FILE*'s which interface with a C++ stream. + class FILE_Cookie + { + public: + FILE_Cookie(std::istream& istr); + FILE_Cookie(std::ostream& ostr); + FILE_Cookie(std::istream& istr, std::ostream& ostr); + ~FILE_Cookie(); + + FILE* file(); + const FILE* file() const; + + bool is_input() const; + bool is_output() const; + + std::istream& istr(); + const std::istream& istr() const; + std::ostream& ostr(); + const std::ostream& ostr() const; + + private: + std::FILE* m_file; + std::istream* m_istr; + std::ostream* m_ostr; + + // Copying prohibited + FILE_Cookie(const FILE_Cookie& cookie); + FILE_Cookie& operator=(const FILE_Cookie& cookie); + }; } #endif /* DIMENSIONXX_COOKIE_HPP */ |