/*

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.

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

*/

/*!
	\file
	\brief Класс тега, который не имеет собственного значения.
*/

#include <assert.h>
#include <string.h>

#include <cls_2/h/tag_no_value.hpp>

namespace cls_2 {

//
// tag_no_value_t
//

tag_no_value_t::tag_no_value_t(
	const char * name,
	bool is_mandatory,
	bool is_one_copy_only )
:
	tag_t( name ),
	m_is_mandatory( is_mandatory ),
	m_is_defined( false ),
	m_is_one_copy_only( is_one_copy_only )
{
}

tag_no_value_t::tag_no_value_t(
	tag_t & owner,
	const char * name,
	bool is_mandatory,
	bool is_one_copy_only )
:
	tag_t( owner, name ),
	m_is_mandatory( is_mandatory ),
	m_is_defined( false ),
	m_is_one_copy_only( is_one_copy_only )
{
}

tag_no_value_t::~tag_no_value_t() {
}

int
tag_no_value_t::on_start(
	parser_context_t & context ) {

	if( m_is_defined && m_is_one_copy_only ) {
		context.show_error( query_name() );
		context.show_error( context.find_msg(
			c_msg_tag_already_defined ) );

		return c_semantic_error;
	}

	return c_ok;
}

int
tag_no_value_t::on_finish(
	parser_context_t & context ) {

	int ret_code = tag_t::on_finish( context );
	if( c_ok == ret_code ) {
		m_is_defined = true;
	}

	return ret_code;
}

int
tag_no_value_t::on_tok_nonspace(
	parser_context_t & context,
	const char * tok_value ) {
	assert( tok_value );

	context.show_error( tok_value );
	context.show_error( context.find_msg(
		c_msg_invalid_value ) );

	return c_semantic_error;
}

int
tag_no_value_t::on_tok_string(
	parser_context_t & context,
	const char * tok_value ) {
	assert( tok_value );

	context.show_error( tok_value );
	context.show_error( context.find_msg(
		c_msg_invalid_value ) );

	return c_semantic_error;
}

bool
tag_no_value_t::is_mandatory() const {
	return m_is_mandatory;
}

bool
tag_no_value_t::is_defined() const {
	return m_is_defined;
}

void
tag_no_value_t::reset() {
	tag_t::reset();

	m_is_defined = false;
}

void
tag_no_value_t::make_defined() {
	m_is_defined = true;
}

} /* namespace cls_2 */
