/*
** SellaNMS
** $Id: clause.h,v 1.7 2005/05/21 23:10:28 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#ifndef __CLAUSE_H__
#define __CLAUSE_H__

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include "defaults.h"
#include "common/confignode.h"
#include "storage/storage.h"

#include <stl/slist>
#include <stl/string>
#include <stl/hash_map>

#define	ACTION_FAILURE				0x00000000

#define	ACTION_THEN					0x00000001

#define	ACTION_ACCEPT				0x00000100
#define	ACTION_REJECT				0x00000200

#define	ACTION_NEXT_TERM			0x00010000
#define	ACTION_NEXT_INPUT			0x00020000
#define	ACTION_NEXT_STATEMENT	0x00040000

#define	TYPE_STR						0x00000001
#define	TYPE_REG						0x00000002
#define	TYPE_INT						0x00000004
#define	TYPE_TME						0x00000010
#define	TYPE_DTE						0x00000020
#define	TYPE_DAY						0x00000040
#define	TYPE_PFX						0x00000100

#define	FUNCTION_EQ					0x00000001
#define	FUNCTION_NE					0x00000002
#define	FUNCTION_LT					0x00000010
#define	FUNCTION_LE					0x00000020
#define	FUNCTION_GT					0x00000100
#define	FUNCTION_GE					0x00000200

#define	MAX_REGEX_MATCH			64
#define	MAX_VARIABLE_REPLACE		256

typedef struct variable_t {
	string			name;
	slist<string>	values;
} _variable_t;

#ifdef ACTION
	#undef ACTION
#endif
typedef unsigned long					ACTION;
typedef slist<slist<variable_t> >	variable_reference_t;
typedef hash_map<string, string>		variable_binding_t;

extern long xxxTT;

class Clause {
	public:
		Clause();

		ACTION evaluate(slist<variable_binding_t> &v);
		RESULT setStorage(Storage *storage);

		virtual ACTION evaluate(variable_binding_t &v) = 0;
		virtual RESULT compile(ConfigNode *config) = 0;

		virtual RESULT clear() = 0;
		virtual RESULT print(unsigned long depth = 0) = 0;

	protected:
		RESULT replaceVariables(variable_binding_t &variables, string &destination);
		bool containsVariable(string &value);

		Storage	*storage;
};

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3 sts=3
*/
