Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C++

Napkin

Rate me:
Please Sign up or sign in to vote.
4.38/5 (4 votes)
12 Mar 20063 min read 39K   66   11  
A simple logging library using generic object to streams
#ifndef PSTADE_NAPKIN_TRANSFORM_OUT_HPP
#define PSTADE_NAPKIN_TRANSFORM_OUT_HPP


// PStade.Napkin
//
// Copyright 2006 MB.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


// Usage:
//
// Functor must return OutputStreamable.


#include "./ostream.hpp"


namespace pstade { namespace napkin {


template< class CharT, class Functor >
struct basic_transform_out
{
	template< class StringOutputable >
	basic_transform_out(Functor fun, StringOutputable& out) :
		m_fun(fun), m_os(out)
	{ }

	void operator<<(const CharT *psz)
	{
		m_os << m_fun(psz);
	}

	Functor functor() const
	{
		return m_fun;
	}

private:
	Functor m_fun;
	basic_ostream<CharT> m_os;
};


template< class Functor >
struct transform_out :
	basic_transform_out<char, Functor>
{
	template< class StringOutputable >
	transform_out(Functor fun, StringOutputable& out) :
		basic_transform_out<char, Functor>(fun, out)
	{ }
};


template< class Functor >
struct transform_wout :
	basic_transform_out<wchar_t, Functor>
{
	template< class WideStringOutputable >
	transform_wout(Functor fun, WideStringOutputable& wout) :
		basic_transform_out<wchar_t, Functor>(fun, wout)
	{ }
};


} } // namespace pstade::napkin


#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
I am worried about my poor English...

Comments and Discussions