Vaucanson 1.4
|
00001 // series_rep_base.hxx: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2008 The Vaucanson Group. 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 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 00018 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_SERIES_REP_BASE_HXX 00019 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_SERIES_REP_BASE_HXX 00020 00021 # include <vaucanson/algebra/implementation/series/series_rep_base.hh> 00022 00023 namespace vcsn 00024 { 00025 namespace algebra 00026 { 00027 template <template <typename, typename> class B, typename S, typename M> 00028 SeriesRepBase<B, S, M>::SeriesRepBase() 00029 { 00030 self_t* self = static_cast<self_t*>(this); 00031 00032 // Sane defaults. 00033 self->maybe_zero.push_back("0"); 00034 self->maybe_zero.push_back("z"); 00035 00036 // Trying with more than one char. 00037 self->maybe_zero.push_back("_z"); 00038 self->maybe_zero.push_back("zero"); 00039 00040 self->zero = *(self->maybe_zero.begin()); 00041 self->open_par = "("; 00042 self->close_par = ")"; 00043 self->plus = "+"; 00044 self->times = "."; 00045 self->star = "*"; 00046 self->open_weight = "{"; 00047 self->close_weight = "}"; 00048 self->spaces.push_back(" "); 00049 } 00050 00051 // FIXME: maybe we can factor even more code with MonoidRepBase 00052 // (maybe some sort of RepresentationBase?) 00053 template <template <typename, typename> class B, typename S, typename M> 00054 void 00055 SeriesRepBase<B, S, M>::disambiguate(const monoid_t& monoid, 00056 pointer_t& orig) 00057 { 00058 // Type helpers. 00059 typedef typename monoid_t::alphabet_t alphabet_t; 00060 typedef typename alphabet_t::letter_t letter_t; 00061 00062 self_t* self = static_cast<self_t*>(this); 00063 00064 // Type helpers. 00065 typedef std::vector<std::string>::const_iterator iterator_t; 00066 00067 self_t new_rep = *self; 00068 00069 for (iterator_t zero_it = new_rep.maybe_zero.begin(); 00070 zero_it != new_rep.maybe_zero.end(); 00071 ++zero_it) 00072 { 00073 bool found = true; 00074 00075 for_all_const_(alphabet_t, i, monoid.alphabet()) 00076 { 00077 if (letter_traits<letter_t>::letter_to_literal(*i) == *zero_it) 00078 { 00079 found = false; 00080 break; 00081 } 00082 } 00083 00084 // Best match. 00085 if (found) 00086 { 00087 // Copy on write. 00088 if (new_rep.zero != *zero_it) 00089 { 00090 new_rep.zero = *zero_it; 00091 orig = pointer_t(new self_t(new_rep)); 00092 } 00093 break; 00094 } 00095 } 00096 } 00097 00098 template <template <typename, typename> class B, typename S, typename M> 00099 bool 00100 operator==(boost::shared_ptr<SeriesRepBase<B, S, M> > lhs, 00101 boost::shared_ptr<SeriesRepBase<B, S, M> > rhs) 00102 { 00103 return (lhs->open_par == rhs->open_par && 00104 lhs->close_par == rhs->close_par && 00105 lhs->plus == rhs->plus && 00106 lhs->times == rhs->times && 00107 lhs->star == rhs->star && 00108 lhs->zero == rhs->zero && 00109 lhs->open_weight == rhs->open_weight && 00110 lhs->close_weight == rhs->close_weight && 00111 lhs->spaces == rhs->spaces && 00112 lhs->maybe_zero == rhs->maybe_zero); 00113 } 00114 00115 } // ! algebra 00116 00117 } // ! vcsn 00118 00119 #endif // !VCSN_ALGEBRA_IMPLEMENTATION_SERIES_SERIES_REP_BASE_HXX