/*************************************************************************
  FILE:  BddSdDES.h
  DESCR: Header file of BddSdDES.cpp (Process DES file)
  AUTH:  Raoguang Song, Yu Wang
  DATE:  (C) Jan, 2006, 2009
*************************************************************************/
#ifndef _BDDSDDES_H_
#define _BDDSDDES_H_



#include <string>
#include <map>
#include <list>
#include "BddSdType.h"
#include <fstream>

#include "Des.h"


using namespace std;

namespace BDDSD
{

class CSub;

class CDES
{
public: //Constructor and Destructor
    CDES(CSub *vpSub, const string &vsDESFile, const DESTYPE vDESType);
    virtual ~CDES();

public:
    int LoadDES(DESpot::Des& theDes);
    int PrintDES(ofstream & fout);

public:
    string GetDESName() const {return m_sDESName;};
    int * GetEventsArr() {return m_piEventsArr;};
    int GetNumofEvents() const {return m_DESEventsMap.size();};
    int GetNumofMarkingStates() const {return m_MarkingList.size();};
    MARKINGLIST & GetMarkingList() {return m_MarkingList;};
    int GetNumofStates() const { return m_iNumofStates;};
    int GetInitState() const {return m_iInitState;};
    map<int, int> *GetTrans() const {return m_pTransArr;};
    DESTYPE GetDESType() const {return m_DESType;};
    CSub*  GetSub() {return m_pSub;};
    string GetStateName(int iState) {
#ifdef _WIN32
      return m_InvStatesMap[iState + 1];
#else
      return m_InvStatesMap[iState];
#endif
};

    EVENTS m_DESEventsMap;  //A STL Map for events (event name (key),
                            //local event index). Used only for current DES
                            //(speed reason)

private: //data memeber
    string m_sDESFile;   //DES file name with path
    string m_sDESName;   //DES name without path and file extension
    DESTYPE m_DESType;   //DES type

    int m_iNumofStates; //Number of States
    int m_iInitState;  //Initial state

    MARKINGLIST m_MarkingList; //Link list containing all marking states

    STATES m_StatesMap; //A STL Map for states (state name (key), state index)
    INVSTATES m_InvStatesMap; //A STL Map for states (state index (key),
                              //state name)(for printing)

    INVEVENTS m_InvDESEventsMap; //A STL Map for events (localindex (key),
                                //event name). Used only for current DES
                                //(for printing)
    EVENTS m_UnusedEvents; //A STL Map for blocked events(name: key, index)

    int *m_piEventsArr;  //Save all the event indices ascendingly.
                         //used for find shared events between two DESes.

    TRANS *m_pTransArr; //Transiton Map array, indexed by event indices.
                        //TRANSMAP: first int: source state index
                        //          second int: target state index
    CSub *m_pSub; //which subsystem this DES belongs to
private: //internal function members
    int AddEvent(const string & vsEventName,
                 const char cControllable);
    int AddTrans(const string & vsLine,
                 const string & vsExitState,
                 const int viExitState);
};


} //end of namespace BDDSD

#endif //_BDDSDDES_H_
