/*
** SellaNMS
** $Id: policy_statement_from_variable.h,v 1.7 2006/01/24 07:08:09 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 __POLICY_STATEMENT_FROM_VARIABLE_H__
#define __POLICY_STATEMENT_FROM_VARIABLE_H__

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

#include "clause.h"
#include "map_statement.h"
#include "policy_statement.h"
#include "format_statement.h"
#include "common/netblock.h"

#include <regex.h>
#include <stl/string>
#include <stl/slist>

class PolicyStatementFromVariable: public Clause {
	public:
		PolicyStatementFromVariable();
      PolicyStatementFromVariable(PolicyStatementFromVariable const &src);
		virtual ~PolicyStatementFromVariable();
      virtual PolicyStatementFromVariable const& operator=(PolicyStatementFromVariable const &src);
	
		RESULT setName(string &name);	
		RESULT addValue(string &value);

		RESULT setCompiledStatements(hash_map<string, PolicyStatement> *policies, hash_map<string, MapStatement> *maps);
		RESULT getReferencedVariable(variable_t &variable);
		RESULT getAppliedMapStatements(slist<string> &map_names);

		RESULT applyFormatStatement(FormatStatement &format);

		virtual ACTION evaluate(variable_binding_t &input);		
		virtual RESULT compile(ConfigNode *config);

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

	protected:
		inline ACTION evaluateFunction(long left, long right);

		RESULT addType(unsigned long type);
		RESULT addFunction(unsigned long function);

		RESULT addMapStatement(string &map_name);

	private:
		unsigned long				type;
		unsigned long				function;

		bool							runtimeVariable;

		string						name;

		slist<string>				mapStatements;

		slist<string>				values;
		slist<pair<string, regex_t> >	regexes; /* Needed for deep copy: string is original, regex_t is compiled version */
		slist<long>					integers;
		slist<long>					dates;
		slist<long>					times;
		slist<long>					days;
		slist<Netblock>			netblocks;

		regex_t						dateFormat;
		regex_t						timeFormat;
		hash_map<string, long>	dayOfWeek;

		hash_map<string, PolicyStatement>   *compiledPolicies;		
		hash_map<string, MapStatement>   	*compiledMaps;		
};

#endif

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