/*

cls_2: Curl Like Syntax
Yauheni A. Akhotnikau (C) 2001-2003
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.

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

*/
#if !defined( _CLS_2__SCALAR__MIN_MAX_HPP_ )
#define _CLS_2__SCALAR__MIN_MAX_HPP_

#include <cls_2/scalar/h/constraint.hpp>
#include <cls_2/scalar/h/format.hpp>

namespace cls_2 {

namespace scalar_constraint {

//
// min_max_t
//

/*
	Constraint: min <= value <= max
*/
template< class T, class Format = scalar_format_t< T > >
class	min_max_t : public scalar_constraint_t< T > {
	public :
		min_max_t( const T & min, const T & max );
		virtual ~min_max_t();

		virtual int
		check(
			parser_context_t & context,
			const T & value );

	protected :
		T	m_min;
		T	m_max;
};

template< class T, class Format >
min_max_t< T, Format >::min_max_t(
	const T & min, const T & max ) {
	m_min = min;
	m_max = max;
}

template< class T, class Format >
min_max_t< T, Format >::~min_max_t() {
}

template< class T, class Format >
int
min_max_t< T, Format >::check(
	parser_context_t & context,
	const T & value ) {

	if( m_min <= value && value <= m_max )
		return c_ok;

	Format fmt;
	context.show_error( fmt.format_disallowed_value( value ) );
	context.show_error( context.find_msg(
		c_msg_value_out_of_range ) );
	return c_semantic_error;
}

} /* namespace scalar_constraint */

} /* namespace cls_2 */

#endif
