/*
*/

#include <iostream>

#include <oess_1/io/h/stream.hpp>
#include <oess_1/io/h/mem_buf.hpp>

#include <oess_1/stdsn/h/ent_std.hpp>
#include <oess_1/stdsn/h/custom_inout_templ.hpp>

namespace custom_type_test
{

class my_t
	{
	private :
		int	m_x;
		short	m_y;
	public :
		my_t() : m_x( 1 ), m_y( 0 ) {}
		my_t( int x, short y ) : m_x( x ), m_y( y ) {}

		int x() const { return m_x; }
		short y() const { return m_y; }
	};

oess_1::io::istream_t &
operator>>( oess_1::io::istream_t & in, my_t & m )
	{
		int x;
		short y;

		in >> x >> y;
		m = my_t( x, y );

		return in;
	}

oess_1::io::ostream_t &
operator<<( oess_1::io::ostream_t & out, const my_t & m )
	{
		return ( out << m.x() << m.y() );
	}

} /* namespace custom_type_test */

OESS_1_STDSN_SPECIALIZE_CUSTOM_TYPE( custom_type_test::my_t )

int
test_default()
	{
		custom_type_test::my_t orig( 3, 8 );
		custom_type_test::my_t m;

		oess_1::io::mem_buf_t buf;
		oess_1::stdsn::oent_std_t ostream( buf );

		oess_1::stdsn::oobj_t< custom_type_test::my_t > oobj( orig );
		ostream << oobj;

		buf.set_pos( 0 );
		oess_1::stdsn::ient_std_t istream( buf );

		oess_1::stdsn::iobj_t< custom_type_test::my_t > iobj( m );
		istream >> iobj;

		int errors = 0;

		if( orig.x() != m.x() )
			{
				std::cerr << "orig.x (" << orig.x() << ") != m.x ("
						<< m.x() << ")" << std::endl;
				++errors;
			}
		if( orig.y() != m.y() )
			{
				std::cerr << "orig.y (" << orig.y() << ") != m.y ("
						<< m.y() << ")" << std::endl;
				++errors;
			}

		return errors;
	}

int
main()
	{
		try
			{
				return test_default();
			}
		catch( const std::exception & x )
			{
				std::cerr << "exception: " << x.what() << std::endl;
			}
		return 1;
	}

