include/Alphabet.hpp

Go to the documentation of this file.
00001 // Alphabet.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 ALPHABET
00017 #define ALPHABET
00018 
00019 #include "VerboseOption.hpp"
00020 #include <list>
00021 #include <map>
00022 #include <iterator>
00023 #include <algorithm>
00024 
00025 
00026 
00027 
00028 namespace regal{
00029   
00030   template<typename Sigma>
00031   class Alphabet{
00032   private:
00033     std::list<Sigma> alphabet; 
00034     std::map<Sigma,int> numericalAlphabet; 
00035     int size; 
00037   public:
00038     
00043     void insert(const Sigma & elt){
00044       if(find(alphabet.begin(),alphabet.end(),elt)==alphabet.end()){
00045         alphabet.push_back(elt);
00046         numericalAlphabet[elt]=size;
00047         size++;
00048       }
00049     }
00050     
00055     int getSize() const{return size;}
00056     
00063     int getNumericalValue(const Sigma & val){
00064       return numericalAlphabet[val];
00065     }
00066     
00071     std::list<Sigma> getList(){return alphabet;}
00072     
00076     Alphabet(){
00077       size=0;
00078       verbose("Creation of an Alphabet");
00079     }
00080     
00081     
00087     Alphabet(Sigma* l,const int & s){
00088       size=0;
00089       for(int i=0;i<s;i++)
00090         insert(l[i]);
00091     }
00092     
00096     virtual ~Alphabet(){
00097       verbose("Destruction of an Alphabet");
00098     }
00099     
00100     friend std::ostream& operator<<(std::ostream& o,const Alphabet<char> & a);
00101 
00102 
00103   };
00104 
00105 
00112   std::ostream& operator<<(std::ostream& o,const Alphabet<char> & a){
00113     o<<std::endl<<"----------"<<std::endl;
00114     o<<"Alphabet"<<std::endl;
00115     o<<"Size = "<<a.size<<std::endl;
00116     std::list<char> listT=a.alphabet;
00117     for(std::list<char>::iterator l=listT.begin();l!=listT.end();l++)
00118       o<<*l<<" ";
00119     o<<std::endl<<"----------"<<std::endl;
00120     return o;
00121   }
00122 
00123 
00124 
00125 
00126 
00127 }
00128 
00129 #endif

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