/*

oess_1: Object Entity Serialization & Stability
Yauheni A. Akhotnikau (C) 2002-2006
eao197@yahoo.com
-------------------------------------------------

Permission is granted to anyone to use this software for any purpose on any
computer system, and to redistribute it freely, subject to the following
restrictions:

1. This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2. The origin of this software must not be misrepresented, either by
   explicit claim or by omission.

3. Altered versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

-------------------------------------------------

*/

/*!
 * \file
 * \since v.1.4.0-b2.2
 * \brief Ручная сериализация для std::vector.
 */

#if !defined( OESS_1__IO__CUSTOM__STL__VECTOR_HPP )
#define OESS_1__IO__CUSTOM__STL__VECTOR_HPP

#include <vector>

#include <oess_1/defs/h/quantity.hpp>

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

namespace oess_1
{

namespace io
{

/*!
 * \since v.1.4.0-b2.2
 * \brief Ручная десериализация для std::vector.
 */
template< class T >
oess_1::io::istream_t &
operator>>( oess_1::io::istream_t & s, std::vector< T > & o )
	{
		oess_1::defs::quantity_t q;
		s >> q;
		std::vector< T > tmp;
		if( q.value() )
			{
				tmp.reserve( q.value() );
				for( oess_1::uint_t c = q.value(); c; --c )
					{
						T next;
						s >> next;
						tmp.push_back( next );
					}
			}

		tmp.swap( o );

		return s;
	}

/*!
 * \since v.1.4.0-b2.2
 * \brief Ручная сериализация для std::vector.
 */
template< class T >
oess_1::io::ostream_t &
operator<<( oess_1::io::ostream_t & s, const std::vector< T > & o )
	{
		oess_1::defs::quantity_t q( o.size() );
		s << q;
		for( typename std::vector< T >::const_iterator i = o.begin(), end = o.end();
				i != end; ++i )
			{
				s << *i;
			}
		return s;
	}

} /* namespace io */

} /* namespace oess_1 */

#endif

