Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63325 - in sandbox/variadic_templates/boost/iostreams: . filter utility
From: cppljevans_at_[hidden]
Date: 2010-06-25 15:40:38


Author: cppljevans
Date: 2010-06-25 15:40:37 EDT (Fri, 25 Jun 2010)
New Revision: 63325
URL: http://svn.boost.org/trac/boost/changeset/63325

Log:
add iostreams files needed by composite_storage/sandbox examples
Added:
   sandbox/variadic_templates/boost/iostreams/
   sandbox/variadic_templates/boost/iostreams/filter/
   sandbox/variadic_templates/boost/iostreams/filter/indent.hpp (contents, props changed)
   sandbox/variadic_templates/boost/iostreams/utility/
   sandbox/variadic_templates/boost/iostreams/utility/indent_scoped_ostreambuf.hpp (contents, props changed)

Added: sandbox/variadic_templates/boost/iostreams/filter/indent.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/iostreams/filter/indent.hpp 2010-06-25 15:40:37 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,99 @@
+#ifndef BOOST_IOSTREAMS_FILTER_INDENT_HPP
+#define BOOST_IOSTREAMS_FILTER_INDENT_HPP
+
+#include <boost/iostreams/concepts.hpp>
+#include <boost/iostreams/operations.hpp>
+
+// Must come last.
+#include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1 C4244.
+
+namespace boost { namespace iostreams {
+
+//
+// Class name: indent_filter.
+//
+// Template paramters:
+// Ch - The character type.
+// Description: Output Filter which indents each line by user modifiable amount.
+//
+ template
+ < typename Ch = BOOST_IOSTREAMS_DEFAULT_ARG(char)
+ >
+class indent_filter
+ : public filter
+ < output
+ , Ch
+ >
+{
+ public:
+
+ typedef filter< output, Ch> super_type;
+ typedef Ch char_type;
+ static int const width_default=4;
+
+ template<typename Sink>
+ bool put(Sink& dest, char_type c)
+ {
+ if (c == '\n')
+ linestart_ = true;
+ else
+ if (linestart_) {
+ for(int n=0; n<indent_; ++n)
+ boost::iostreams::put(dest, ' ');
+ linestart_ = false;
+ }
+ return boost::iostreams::put(dest, c);
+ }
+
+ template<typename Sink>
+ void close(Sink&)
+ {
+ indent_ = 0;
+ linestart_ = true;
+ }
+
+ void indent_in()
+ {
+ indent_by(+width_);
+ }
+
+ void indent_out()
+ {
+ indent_by(-width_);
+ }
+
+ int indentation()const
+ {
+ return indent_;
+ }
+
+ int width()const
+ {
+ return width_;
+ }
+
+ void indent_by(int amount)
+ {
+ int my_indent=indent_+amount;
+ indent_=my_indent>0?my_indent:0;
+ }
+
+ explicit indent_filter
+ ( int width=width_default
+ )
+ : indent_(0)
+ , linestart_(true)
+ , width_((width>0)?width:0)
+ {
+ }
+ private:
+ int indent_;//current indentation
+ bool linestart_;//at the start of line?
+ int width_;//amount to change indentation.
+};
+
+} } // End namespaces iostreams, boost.
+
+#include <boost/iostreams/detail/config/enable_warnings.hpp>
+
+#endif // INDENT

Added: sandbox/variadic_templates/boost/iostreams/utility/indent_scoped_ostreambuf.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/iostreams/utility/indent_scoped_ostreambuf.hpp 2010-06-25 15:40:37 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,131 @@
+#ifndef BOOST_IOSTREAMS_INDENT_SCOPED_OSTREAMBUF_HPP_INCLUDED
+#define BOOST_IOSTREAMS_INDENT_SCOPED_OSTREAMBUF_HPP_INCLUDED
+
+#include <boost/iostreams/filter/indent.hpp>
+#include <boost/iostreams/filtering_streambuf.hpp>
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+namespace boost { namespace iostreams {
+
+template<typename Ch>
+struct select_scoped_ostreambuf
+;
+template<>
+struct select_scoped_ostreambuf<char>
+{
+ typedef filtering_ostreambuf type;
+};
+template<>
+struct select_scoped_ostreambuf<wchar_t>
+{
+ typedef filtering_wostreambuf type;
+};
+
+//
+// Template name: indent_scoped_ostreambuf.
+// Description: Temporarily replaces the ostreambuf of ostream
+// passed to CTOR. DTOR restores original ostreambuf.
+// Template paramters:
+// Ch - The charactertype.
+//
+template<typename Ch=char>
+class indent_scoped_ostreambuf
+{
+ public:
+ typedef std::basic_streambuf<Ch> std_buf_type;
+ typedef std::basic_ostream<Ch> std_ostrm_type;
+ typedef typename select_scoped_ostreambuf<Ch>::type filt_buf_type;
+
+ indent_scoped_ostreambuf
+ ( std_ostrm_type& a_ostrm
+ , int width=2
+ )
+ : my_old_buf(a_ostrm.rdbuf())
+ , my_strm(a_ostrm)
+ , my_filt_buf(*my_old_buf,width)
+ {
+ my_strm.rdbuf(&my_filt_buf);
+ }
+
+ ~indent_scoped_ostreambuf(void)
+ {
+ my_strm.rdbuf(my_old_buf);
+ }
+
+ // Class name: push_filt_strmbuf
+ // Description: streambuf allowing user to indent
+ // the stream (by calling filt_get and then
+ // calling filt_type::indent_in or filt_type::indent_out).
+ struct push_filt_strmbuf
+ : public filt_buf_type
+ {
+ typedef indent_filter<Ch> filt_type;
+
+ push_filt_strmbuf
+ ( std_buf_type& a_buf
+ , int width=2
+ )
+ {
+ filt_type my_filter(width);
+ this->push(my_filter,0,0);
+ this->push(a_buf);
+ }
+
+ filt_type*filt_get(void)
+ {
+ filt_type*const my_filter = this->template component<filt_type>(0);
+ return my_filter;
+ }
+
+ };
+
+ private:
+ std_buf_type* my_old_buf;//For DTOR.
+
+ std_ostrm_type& my_strm;//For DTOR.
+
+ push_filt_strmbuf my_filt_buf;//The temporary replacement buffer.
+};
+
+} } // End namespaces iostreams, boost.
+
+// Function name: indent_buf
+// Descrption:: Indents the buffer of ostream argument, if possible.
+//
+template<class charT, class traits>
+inline std::basic_ostream<charT, traits>&
+indent_buf_in(std::basic_ostream<charT, traits>& os)
+{
+ typedef boost::iostreams::indent_scoped_ostreambuf<charT> filt_scoped_type;
+ typedef typename filt_scoped_type::push_filt_strmbuf filt_strmbuf_type;
+ filt_strmbuf_type*buf_ptr = dynamic_cast<filt_strmbuf_type*>(os.rdbuf());
+ if (buf_ptr) {
+ typedef typename filt_strmbuf_type::filt_type filt_type;
+ filt_type* filt_ptr=buf_ptr->filt_get();
+ filt_ptr->indent_in();
+ }
+ return os;
+}
+
+// Function name: undent_buf
+// Descrption:: Indents outwardly the buffer of ostream argument, if possible.
+//
+template<class charT, class traits>
+inline std::basic_ostream<charT, traits>&
+indent_buf_out(std::basic_ostream<charT, traits>& os)
+{
+ typedef boost::iostreams::indent_scoped_ostreambuf<charT> filt_scoped_type;
+ typedef typename filt_scoped_type::push_filt_strmbuf filt_strmbuf_type;
+ filt_strmbuf_type*buf_ptr = dynamic_cast<filt_strmbuf_type*>(os.rdbuf());
+ if (buf_ptr) {
+ typedef typename filt_strmbuf_type::filt_type filt_type;
+ filt_type* filt_ptr=buf_ptr->filt_get();
+ filt_ptr->indent_out();
+ }
+ return os;
+}
+
+#endif // #ifndef BOOST_IOSTREAMS_INDENT_SCOPED_OSTREAMBUF_HPP_INCLUDED


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk