00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_MONOID_MONOID_REP_BASE_HXX
00019 # define VCSN_ALGEBRA_IMPLEMENTATION_MONOID_MONOID_REP_BASE_HXX
00020
00021 # include <vaucanson/algebra/implementation/monoid/monoid_rep_base.hh>
00022
00023 namespace vcsn
00024 {
00025 namespace algebra
00026 {
00027 template <template <typename> class S, typename T>
00028 MonoidRepBase<S, T>::MonoidRepBase()
00029 {
00030 self_t* self = static_cast<self_t*>(this);
00031
00032
00033 self->maybe_epsilon.push_back("1");
00034 self->maybe_epsilon.push_back("e");
00035
00036
00037 self->maybe_epsilon.push_back("_e");
00038 self->maybe_epsilon.push_back("eps");
00039
00040 self->empty = *(self->maybe_epsilon.begin());
00041 self->concat = "";
00042 }
00043
00044 template <template <typename> class S, typename T>
00045 void
00046 MonoidRepBase<S, T>::disambiguate(const monoid_t& monoid, pointer_t& orig)
00047 {
00048
00049 typedef typename monoid_t::alphabet_t alphabet_t;
00050 typedef typename alphabet_t::letter_t letter_t;
00051
00052 self_t* self = static_cast<self_t*>(this);
00053
00054
00055 typedef std::vector<std::string>::const_iterator iterator_t;
00056
00057 self_t new_rep = *self;
00058
00059 for (iterator_t empty_it = new_rep.maybe_epsilon.begin();
00060 empty_it != new_rep.maybe_epsilon.end();
00061 ++empty_it)
00062 {
00063 bool found = true;
00064
00065 for_all_const_(alphabet_t, i, monoid.alphabet())
00066 {
00067 if (letter_traits<letter_t>::letter_to_literal(*i) == *empty_it)
00068 {
00069 found = false;
00070 break;
00071 }
00072 }
00073
00074
00075 if (found)
00076 {
00077
00078 if (new_rep.empty != *empty_it)
00079 {
00080 new_rep.empty = *empty_it;
00081 orig = pointer_t(new self_t(new_rep));
00082 }
00083 break;
00084 }
00085 }
00086 }
00087
00088 template <template <typename> class S, typename T>
00089 bool
00090 operator==(boost::shared_ptr<MonoidRepBase<S, T> > lhs,
00091 boost::shared_ptr<MonoidRepBase<S, T> > rhs)
00092 {
00093 return (lhs->empty == rhs->empty &&
00094 lhs->concat == rhs->concat &&
00095 lhs->maybe_epsilon == rhs->maybe_epsilon);
00096 }
00097
00098 }
00099
00100 }
00101
00102 #endif // !VCSN_ALGEBRA_IMPLEMENTATION_MONOID_MONOID_REP_BASE_HXX