include/AbstractAutomaton.hpp

Go to the documentation of this file.
00001 // AbstractAutomaton.hpp: this file is part of the REGAL project.
00002 //
00003 // REGAL : Random and Exhaustive Generators for Automata - Library
00004 //
00005 // Copyright (C) 2007 Julien DAVID.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 //
00016 #ifndef ABSTRACTAUTOMATON
00017 #define ABSTRACTAUTOMATON
00018 
00019 
00020 #include "GasteXConverter.hpp"
00021 #include "DotConverter.hpp"
00022 #include "Converter.hpp"
00023 #include "VerboseOption.hpp"
00024 #include "Alphabet.hpp"
00025 
00026 #include<map>
00027 
00028 namespace regal{
00029 
00030   struct InvalidStateException : public std::exception {};
00031   
00032   template<typename StateLabel_t,typename Sigma>
00033   class AbstractAutomaton{
00034   private:
00035     std::map<int,StateLabel_t> intTostateMap; 
00036     std::map<StateLabel_t,int> stateTointMap; 
00042     virtual StateLabel_t createState(const StateLabel_t & value)=0;
00043     
00044   protected:
00045     Alphabet<Sigma> alphabet;
00046     int stateNumber; 
00049     /*
00050       Reduces by one the number of states in the automaton, 
00051       which is the same than deleting the last state.
00052      */
00053     void undefineLastState(){
00054       stateNumber--;
00055     }
00056     
00057     
00058   public:
00062     AbstractAutomaton(const Alphabet<Sigma> & a):alphabet(a){
00063       stateNumber=0;
00064       verbose("Creation of an Automaton");
00065     }
00066     
00070     virtual ~AbstractAutomaton(){
00071       verbose("Destruction of an Automaton");
00072     }
00073     
00074     virtual Alphabet<Sigma> getAlphabet()const{return alphabet;}
00075     
00076     virtual StateLabel_t undefinedTransition()const =0;
00077     
00078     virtual int getSize()=0;
00079     
00080     virtual int getAlphabetSize(){return alphabet.getSize();}
00081     
00087     int getIntegerValue(const StateLabel_t & s){
00088       if(stateTointMap.find(s)==stateTointMap.end())
00089         return -1;
00090       return stateTointMap[s];
00091     }
00092     
00098     StateLabel_t getRealValue(const int & ind){
00099       if(ind<0)
00100         return undefinedTransition();
00101       return intTostateMap[ind];
00102     }
00103     
00108     virtual StateLabel_t addState(const StateLabel_t & value=0){
00109       intTostateMap[stateNumber]=createState(value);
00110       stateTointMap[getRealValue(stateNumber-1)]=stateNumber-1;
00111       return getRealValue(stateNumber-1);
00112     }
00113 
00114     
00115 
00123     virtual void addTransition(const StateLabel_t & start,const StateLabel_t & end,const Sigma & value)=0;
00124     
00131     virtual bool isFinal(const StateLabel_t & sl)=0;
00132     
00139     virtual bool isInitial(const StateLabel_t & sl)=0;
00140     
00146     virtual void setStateAsFinal(const StateLabel_t & sl,const bool & value)=0;
00152     virtual void setStateAsInitial(const StateLabel_t & sl,const bool & value)=0;
00153   };
00154   
00155 }
00156 
00157 #endif

Generated on Mon Sep 29 16:33:58 2008 for REGAL by  doxygen 1.5.1