Map.h

Go to the documentation of this file.
00001 
00002 #ifndef _MAP_H_
00003 #define _MAP_H_
00004 
00005 #include <iostream>
00006 
00007 #include <vector>
00008 #include "Word.h"
00009 #include "errormsgs.h"
00010 
00012 //                                                                //
00013 // Map                                                            //
00014 //                                                                //
00016 
00017 
00019 
00022 class Map
00023 {
00024   
00025 public:
00026   
00028 //   Map( ) : 
00029 //     theDomain(0), 
00030 //     theRange(0),
00031 //     theDomainAlphabet(&(InfiniteAlphabet::defaultAlphabet)),
00032 //     theRangeAlphabet(&(InfiniteAlphabet::defaultAlphabet)) {} 
00033 
00034   // copy constructor supplied by compiler
00035   
00036 
00037   
00039 
00045   Map( int domain_gens, int range_gens ) 
00046     : theDomain(domain_gens),
00047     theRange(range_gens),
00048     theDomainAlphabet(domain_gens),
00049     theRangeAlphabet(range_gens),
00050     theGeneratingImages(domain_gens)  { }
00051 
00052   
00054 
00060   Map(  int domain_gens, int range_gens, const vector<Word>& generatingImages ) 
00061     :theDomain(domain_gens),
00062     theRange(range_gens),
00063     theDomainAlphabet(domain_gens),
00064     theRangeAlphabet(range_gens),
00065     theGeneratingImages(generatingImages)  
00066   { 
00067     
00068     if (generatingImages.size() != domain_gens)
00069       msgs::error("wrong number of generating images in  Map::Map(domain,range,generatingImages)");
00070     
00071   }
00072 
00074 
00080   Map( const FiniteAlphabet&  domain_alph, const FiniteAlphabet& range_alph ) 
00081     : theDomain(domain_alph.size()),
00082       theRange(range_alph.size()),
00083       theDomainAlphabet(domain_alph),
00084       theRangeAlphabet(range_alph),
00085       theGeneratingImages(domain_alph.size())  { }
00086 
00087   
00089 
00095   Map(  const FiniteAlphabet&  domain_alph, const FiniteAlphabet& range_alph, 
00096         const vector<Word>& generatingImages ) 
00097     :theDomain(domain_alph.size()),
00098      theRange(range_alph.size()),
00099      theDomainAlphabet(domain_alph),
00100      theRangeAlphabet(range_alph),
00101      theGeneratingImages(generatingImages)  
00102   { 
00103     
00104     if (generatingImages.size() != theDomain)
00105       msgs::error("wrong number of generating images in  Map::Map(domain,range,generatingImages)");
00106     
00107   }
00108   // destructor supplied by compiler
00109 
00111   //                                                                //
00112   // Standard Operators                                             //
00113   //                                                                //
00115 
00117 
00121   bool operator == ( const Map& m ) const 
00122   {
00123     return ( theDomain == m.theDomain && theRange == m.theRange && theGeneratingImages == m.theGeneratingImages );
00124   }
00125 
00127   //                                                                //
00128   // Accessors / Modifiers                                          //
00129   //                                                                //
00131 
00133   int domainSize( ) const { return theDomain; }
00134 
00136   const FiniteAlphabet&  domainAlphabet( ) const { return theDomainAlphabet; }
00137 
00139   int rangeSize( ) const { return theRange; }
00140 
00142   const FiniteAlphabet&  rangeAlphabet( ) const { return theRangeAlphabet; }
00143 
00144  
00146   const vector<Word>& generatingImages( ) const { return theGeneratingImages; }
00147 
00149   Word generatingImages( int i ) const { 
00150     if (i < 0 || i >= theDomain)
00151       msgs::error("generating image index out of range in  Map::generatingImages(int)");
00152     return theGeneratingImages[i]; 
00153   } 
00154 
00155  
00157  void setGeneratingImages( const vector<Word> gi ) 
00158   {
00159     if (gi.size() != theDomain)
00160       msgs::error("wrong number of generating images in  Map::setGeneratingImages( const VectorOf<Word> )");
00161     theGeneratingImages = gi;
00162   }
00163 
00164   
00166 
00170  void setGeneratingImages( int i, const Word& e  ) 
00171   {
00172 
00173     if (i < 0 || i >= theDomain)
00174       msgs::error("generating image index out of range in  Map::setGeneratingImages(int, const Word&)");
00175     theGeneratingImages[i] = e;
00176   }
00177 
00178 
00179         
00181   //                                                                //
00182   // Mapping methods                                                //
00183   //                                                                //
00185 
00186   // computing images:
00187   // formally:
00188 
00190 
00200   Word imageOf( const Word& w ) const;
00201 
00202 
00204 
00210   friend Map composition( const Map& firstMap,
00211                           const Map& secondMap );
00212    
00213 
00215 
00218   Map operator | ( const Map& secondMap )
00219   { return composition(*this, secondMap); }
00220   
00221 
00222 
00224   //                                                                //
00225   // I/O                                                            //
00226   //                                                                //
00228 
00229 
00230   //------------------ Related global functions --------------------//
00231   
00233   friend ostream& operator << ( ostream& out, const Map& m ){
00234     m.printOn(out);
00235     return out;
00236   }
00237 
00239   friend istream& operator >> ( istream& in, Map& m ){
00240     m.readFrom(in);
00241     return in;
00242   }
00243 
00245   void printOn(ostream& ostr) const;
00246  
00248   void readFrom(istream& in);
00249 private:
00250   char readChar(istream& in)const;
00251 
00252 
00253   // real data:
00254   int theDomain;
00255   int theRange;
00256   vector<Word> theGeneratingImages;
00257 
00258   FiniteAlphabet theDomainAlphabet;
00259   FiniteAlphabet theRangeAlphabet;
00260   
00261 };
00262 
00263 
00265 //                                                                //
00266 // Random Maps                                                    //
00267 //                                                                //
00269   
00271 namespace RMap 
00272 {
00274 
00278   Map getRandomWhiteheadAuto(  int n );
00279 
00281 
00285   Map getRandomAuto( int n, int l);
00286 };
00287 
00288 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1