Click here to Skip to main content
15,886,519 members
Articles / Programming Languages / XML

XmlBind: putting PugXML on steroïds !

Rate me:
Please Sign up or sign in to vote.
3.36/5 (10 votes)
2 Oct 20035 min read 131.8K   580   31  
A mutant XML parser using IoBind, EDOM and PugXML.
// iobind library
//
// author: Jonathan de Halleux, 2003

#ifndef IOBIND_STREAM_POLICY_HPP
#define IOBIND_STREAM_POLICY_HPP

#include <iostream>
#include <boost/spirit.hpp>
#include <iobind/policy.hpp>
#include <iobind/stream_property.hpp>

namespace iobind{
namespace detail{

class to_stream_policy :
	public property::ostream_property
{
public:
	typedef property::ostream_property ostream_property_type;
	typedef ostream_reference return_type;

	explicit to_stream_policy(
		ostream_reference ostream_
		)
		: 
		ostream_property_type( ostream_)
		{};

	template<typename T>
	return_type encode( T const& value_) const
	{
		return get_ostream()<<value_;
	};
};
/*
template<
	typename T
>
struct from_stream_policy
{
public:
	typedef std::istream & param_type;
	typedef T return_type;

	return_type encode( param_type istream_) const
	{
		return_tye r = return_type();
		istream_>>r;

		return r;
	};
};
*/

}; // detail

class to_stream : 
	public detail::policy_cons< detail::to_stream_policy , detail::identity_policy >
{
public:
	typedef to_stream type;
	typedef detail::to_stream_policy to_stream_policy_type;
	typedef to_stream_policy_type::ostream_reference ostream_reference;
	typedef detail::policy_cons< to_stream_policy_type , detail::identity_policy > policy_type;

	explicit to_stream( ostream_reference ostream_ )
	: policy_type(
		to_stream_policy_type(ostream_),
		detail::identity_policy()
		)
	{};

	to_stream change_stream( ostream_reference ostream_) const
	{
		return to_stream(ostream_);
	};

	to_stream operator % ( ostream_reference ostream_) const
	{
		return to_stream(ostream_);
	};
};

const to_stream to_stream_p = to_stream( std::cout );
/*
template<
	typename T
>
struct from_stream : 
	detail::policy_cons< detail::from_stream_policy<T> , detail::identity_policy >
{
	typedef from_stream<T> type;
};

typedef from_stream<std::string> from_stream_p_type;
const from_stream_p_type from_stream_p = from_stream_p_type();
*/
}; //iobind


#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
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions