Click here to Skip to main content
15,878,814 members
Articles / Programming Languages / C++

IoBind, a serializer code factory.

Rate me:
Please Sign up or sign in to vote.
4.89/5 (10 votes)
29 Jun 20037 min read 78.8K   763   29  
IoBind proposes a new approach to object serialization.
// iobind library
//
// author: Jonathan de Halleux, 2003

#ifndef IOBIND_CRC_POLICY_HPP
#define IOBIND_CRC_POLICY_HPP

#include <boost/crc.hpp>
#include <iobind/policy.hpp>

namespace iobind{
namespace detail{

template < 
	typename CRCComputer
>
struct crc_policy
{
	typedef typename CRCComputer::value_type return_type;

	template<
		typename Container
	>
	return_type encode(Container const& cont_) const
	{	
		CRCComputer crc;
		crc.process_bytes(
			cont_.data(), 
			cont_.size() * sizeof( Container::value_type )
			);

		return crc.checksum();
	};

	template<typename Iterator>
	return_type encode(Iterator const& begin_, Iterator const& end_) const
	{
		CRCComputer crc;
		crc.process_block(
			begin_, 
			end_
			);

		return crc.checksum();
	};

	// factories

};

}; // detail


template < 
	typename CRCComputer
>
struct to_crc : 
	detail::policy_cons< 
		detail::crc_policy<CRCComputer>,
		detail::identity_policy 
	>
{
	typedef detail::crc_policy<CRCComputer> type;
};

typedef to_crc<boost::crc_16_type> to_crc_16;
typedef to_crc<boost::crc_ccitt_type> to_crc_ccitt;
typedef to_crc<boost::crc_xmodem_type> to_crc_xmodem;
typedef to_crc<boost::crc_32_type> to_crc_32;

}; // 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