/*************************************************************************************************
** Project:     FSMGenerator
** Package:     FSMGenerator
** Module:      FSMGenerator::dbManager
** File:        dbManager.h
** Date:        2002.08.01
** Author:      Pavel Bekkerman (chpavel@tx.technion.ac.il)
** Copyright:   Copyright (C) 2002 Pavel Bekkerman
** License:
**              This program is free software; you can redistribute it and/or
**              modify it under the terms of the GNU General Public License as
**              published by the Free Software Foundation; either version 2 of
**              the License, or (at your option) any later version.
**
**              This program 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.  See the
**              GNU General Public License for more details.
**
**              You should have received a copy of the GNU General Public License
**              along with this program; if not, write to the Free Software
**              Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**
** Contact:     Pavel Bekkerman (chpavel@tx.technion.ac.il)
*************************************************************************************************/

#ifndef _FSMDBMANAGER_
#define _FSMDBMANAGER_

#pragma warning (disable : 4786)

#include "../db/FSMDB.h"
#include <map>

using std::map;

//************************************************* FSMDB
namespace FSMGenerator
{

	class FSMDBManager
	{
		public:
			FSMDBManager(FSMDB&);
			~FSMDBManager();

			const string& Name	()const;

			// Insertion Interface.
			void NameSet		(const string&);
			void StateInsert	(const string& name);
			void EventInsert	(const string& name);
			void TransInsert	(const string& name, const string& from, 
								 const string& event, const string& to);
			void StartSet		(const string& name);
			void FinalInsert	(const string& name);
			void CallbackInsert	(const string& callName,const string& funcName);
			void HookSet		(const string& name,const string& call1, const string& call2=STRNULL);

		private:

			FSMDB& m_db;

			ID	   m_idNextID;	// for the use of _generateID().

			map<string,ID>	m_mapNameToID;

			map<ID,INDEX>	m_mapIDToState;
			map<ID,INDEX>	m_mapIDToEvent;
			map<ID,INDEX>	m_mapIDToTransition;
			map<ID,INDEX>	m_mapIDToCallback;

			// convenience matters ...
			typedef std::map<string,ID>::iterator		itrNameToID;
			typedef std::map<string,ID>::const_iterator citrNameToID;
			typedef std::map<ID,INDEX>::iterator		itrIDToIndex;
			typedef std::map<ID,INDEX>::const_iterator  citrIDToIndex;

			ID		_generateID    ();	// gets the next ID to be used.
			void	NewStringInsert(const string&,int);	// inserts to m_mapNameToID.

			// Validation.
			bool IsObject	(const string&)const;
			bool IsState	(const string&)const;
			bool IsEvent	(const string&)const;
			bool IsTrans	(const string&)const;
			bool IsFinal	(const string&)const;
			bool IsCallback	(const string&)const;

			// Index Retrival.
			INDEX StateIndex	  (const string&)const;
			INDEX EventIndex	  (const string&)const;
			INDEX TransitionIndex (const string&)const;
			INDEX CallbackIndex	  (const string&)const;
	};

}

#endif

