--- trunk/OOPSE-4/src/io/basic_teebuf.hpp 2005/02/24 20:55:07 2060 +++ trunk/OOPSE-4/src/io/basic_teebuf.hpp 2005/04/15 22:04:00 2204 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -45,75 +45,75 @@ namespace oopse { #include namespace oopse { -/** - * @class basic_teebuf basic_teebuf.hpp "utils/basic_teebuf.hpp" - * @brief As a subclass of basic_streambuf, basic_teebuf can operate on multiple stream simultaneously. - * @code - * std::ofstream file1("file1"); - * std::ofstream file2("file22"); - * std::vector buffers; - * buffers.push_back(file1.rdbuf()); - * buffers.push_back(file2.rdbuf()); - * teebuf tmp(buffers.begin(), buffers.end()); - * std::ostream myOs(&tmp); - * myOs << "hello world"; - * @endcode - */ + /** + * @class basic_teebuf basic_teebuf.hpp "utils/basic_teebuf.hpp" + * @brief As a subclass of basic_streambuf, basic_teebuf can operate on multiple stream simultaneously. + * @code + * std::ofstream file1("file1"); + * std::ofstream file2("file22"); + * std::vector buffers; + * buffers.push_back(file1.rdbuf()); + * buffers.push_back(file2.rdbuf()); + * teebuf tmp(buffers.begin(), buffers.end()); + * std::ostream myOs(&tmp); + * myOs << "hello world"; + * @endcode + */ -template > -class basic_teebuf: public std::basic_streambuf { - public: - typedef std::basic_streambuf streambuf_type; - typedef Traits traits_type; - typedef CharT char_type; - typedef typename traits_type::int_type int_type; + template > + class basic_teebuf: public std::basic_streambuf { + public: + typedef std::basic_streambuf streambuf_type; + typedef Traits traits_type; + typedef CharT char_type; + typedef typename traits_type::int_type int_type; - template - basic_teebuf(ForwardIterator begin, ForwardIterator end) : buffers_(begin, end){ + template + basic_teebuf(ForwardIterator begin, ForwardIterator end) : buffers_(begin, end){ - } + } - protected: - int_type overflow(int_type c = traits_type::eof()) { + protected: + int_type overflow(int_type c = traits_type::eof()) { - //avoid writing eof to stream - if (c == traits_type::eof()) { - return traits_type::eof(); - } + //avoid writing eof to stream + if (c == traits_type::eof()) { + return traits_type::eof(); + } - typename std::vector::iterator iter; //typename is needed since it's a dependant name - for (iter = buffers_.begin(); iter != buffers_.end(); ++iter) { - if ((*iter)->sputc(c) == traits_type::eof()) { - return traits_type::eof(); - } - } + typename std::vector::iterator iter; //typename is needed since it's a dependant name + for (iter = buffers_.begin(); iter != buffers_.end(); ++iter) { + if ((*iter)->sputc(c) == traits_type::eof()) { + return traits_type::eof(); + } + } - return traits_type::not_eof(c); - } + return traits_type::not_eof(c); + } - int sync() { + int sync() { - //flush buffer, checking return for eof. - if (traits_type::eq_int_type(overflow(traits_type::eof()), traits_type::eof())) { - return -1; - } + //flush buffer, checking return for eof. + if (traits_type::eq_int_type(overflow(traits_type::eof()), traits_type::eof())) { + return -1; + } - //flush streams - typename std::vector::iterator iter; - for (iter = buffers_.begin(); iter != buffers_.end(); ++iter) { - if ((*iter)->pubsync() == -1) { - return -1; - } - } + //flush streams + typename std::vector::iterator iter; + for (iter = buffers_.begin(); iter != buffers_.end(); ++iter) { + if ((*iter)->pubsync() == -1) { + return -1; + } + } - return 0; - } + return 0; + } - private: - std::vector buffers_; -}; + private: + std::vector buffers_; + }; -typedef basic_teebuf TeeBuf; + typedef basic_teebuf TeeBuf; } #endif