Click here to Skip to main content
15,895,142 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 39.1K   66   11  
A simple logging library using generic object to streams
#ifndef PSTADE_OVEN_RANGE_HOLDER_HPP
#define PSTADE_OVEN_RANGE_HOLDER_HPP
///////////////////////////////////////////////////////////////////////////////
// PStade.Oven
//
// 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)


#include <boost/any.hpp>
#include <boost/noncopyable.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/empty.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>


namespace pstade { namespace oven {


///////////////////////////////////////////////////////////////////////////////
// range_placeholder
//
struct range_placeholder
{
	virtual ~range_placeholder() { }

	boost::any begin() { return begin_impl(); }
	boost::any end() { return end_impl(); }
	boost::any size() { return size_impl(); }
	bool empty() { return empty_impl(); }

	boost::any ptr_begin() { return ptr_begin_impl(); }
	boost::any ptr_end() { return ptr_end_impl(); }

protected:
	virtual boost::any begin_impl() = 0;
	virtual boost::any end_impl() = 0;
	virtual boost::any size_impl() = 0;
	virtual bool empty_impl() = 0;

	virtual boost::any ptr_begin_impl() = 0;
	virtual boost::any ptr_end_impl() = 0;
};


///////////////////////////////////////////////////////////////////////////////
// range_holder
//
template< class Range >
struct range_holder :
	range_placeholder,
	private boost::noncopyable
{
	explicit range_holder(Range& rng) :
		m_held(rng)
	{ }

	Range& held() { return m_held; }

protected:
	boost::any begin_impl() { return boost::begin(m_held); }
	boost::any end_impl() { return boost::end(m_held); }
	boost::any size_impl() { return boost::size(m_held); }
	bool empty_impl() { return boost::empty(m_held); }

	boost::any ptr_begin_impl() { return &*boost::begin(m_held); }
	boost::any ptr_end_impl() { return &*boost::end(m_held); }

private:
	Range& m_held;
};


} } // namespace pstade::oven


///////////////////////////////////////////////////////////////////////////////
#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