00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGEBRA_CONCEPT_FREEMONOID_BASE_HXX
00019 # define VCSN_ALGEBRA_CONCEPT_FREEMONOID_BASE_HXX
00020
00021 # include <vaucanson/algebra/concept/freemonoid_base.hh>
00022 # include <vaucanson/misc/escaper.hh>
00023
00024 namespace vcsn {
00025
00026 namespace algebra {
00027
00028
00029
00030
00031
00032 template <class Self>
00033 typename FreeMonoidBase<Self>::alphabet_t&
00034 FreeMonoidBase<Self>::alphabet()
00035 {
00036 return this->self().alphabet();
00037 }
00038
00039 template <class Self>
00040 const typename FreeMonoidBase<Self>::alphabet_t&
00041 FreeMonoidBase<Self>::alphabet() const
00042 {
00043 return this->self().alphabet();
00044 }
00045
00046 template <class Self>
00047 FreeMonoidBase<Self>::FreeMonoidBase()
00048 {}
00049
00050 template <class Self>
00051 FreeMonoidBase<Self>::FreeMonoidBase(const FreeMonoidBase& m) :
00052 MonoidBase<Self>(m)
00053 {}
00054
00055 }
00056
00057
00058
00059
00060
00061 template <class Self, typename T>
00062 size_t
00063 MetaElement<algebra::FreeMonoidBase<Self>, T>::length() const
00064 {
00065 return op_size(this->structure(), this->value());
00066 }
00067
00068 template <class Self, typename T>
00069 void
00070 MetaElement<algebra::FreeMonoidBase<Self>, T>::mirror()
00071 {
00072 op_in_mirror(this->structure(), this->value());
00073 }
00074
00075 template <class Self, typename T>
00076 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::iterator
00077 MetaElement<algebra::FreeMonoidBase<Self>, T>::begin()
00078 {
00079 return op_begin(this->structure(), this->value());
00080 }
00081
00082 template <class Self, typename T>
00083 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::const_iterator
00084 MetaElement<algebra::FreeMonoidBase<Self>, T>::begin() const
00085 {
00086 return op_begin_const(this->structure(), this->value());
00087 }
00088
00089 template <class Self, typename T>
00090 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::reverse_iterator
00091 MetaElement<algebra::FreeMonoidBase<Self>, T>::rbegin()
00092 {
00093 return op_rbegin(this->structure(), this->value());
00094 }
00095
00096 template <class Self, typename T>
00097 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::const_reverse_iterator
00098 MetaElement<algebra::FreeMonoidBase<Self>, T>::rbegin() const
00099 {
00100 return op_rbegin_const(this->structure(), this->value());
00101 }
00102
00103 template <class Self, typename T>
00104 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::iterator
00105 MetaElement<algebra::FreeMonoidBase<Self>, T>::end()
00106 {
00107 return op_end(this->structure(), this->value());
00108 }
00109
00110 template <class Self, typename T>
00111 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::const_iterator
00112 MetaElement<algebra::FreeMonoidBase<Self>, T>::end() const
00113 {
00114 return op_end_const(this->structure(), this->value());
00115 }
00116
00117 template <class Self, typename T>
00118 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::reverse_iterator
00119 MetaElement<algebra::FreeMonoidBase<Self>, T>::rend()
00120 {
00121 return op_rend(this->structure(), this->value());
00122 }
00123
00124 template <class Self, typename T>
00125 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::const_reverse_iterator
00126 MetaElement<algebra::FreeMonoidBase<Self>, T>::rend() const
00127 {
00128 return op_rend_const(this->structure(), this->value());
00129 }
00130
00131 template <class Self, typename T>
00132 MetaElement<algebra::FreeMonoidBase<Self>, T>::MetaElement() :
00133 MetaElement<algebra::MonoidBase<Self>, T>()
00134 {}
00135
00136 template <class Self, typename T>
00137 MetaElement<algebra::FreeMonoidBase<Self>, T>::MetaElement(const MetaElement& o) :
00138 MetaElement<algebra::MonoidBase<Self>, T>(o)
00139 {}
00140
00141
00142
00143
00144
00145 template <typename S, typename T>
00146 Element<S, T>
00147 mirror(const Element<S, T>& e)
00148 {
00149 Element<S, T> ret(e);
00150 ret.mirror();
00151 return ret;
00152 }
00153
00154 template <typename S, typename T>
00155 bool
00156 parse_word(Element<S, T>& dest,
00157 const std::string& s)
00158 {
00159 return op_parse(dest.structure(), dest.value(), s);
00160 }
00161
00162 template<typename S, typename T>
00163 const std::basic_string<T>&
00164 op_convert(const algebra::FreeMonoidBase<S>& s,
00165 SELECTOR(std::basic_string<T>),
00166 const std::basic_string<T>& from_data)
00167 {
00168 # ifndef VCSN_NDEBUG
00169 for (typename std::basic_string<T>::const_iterator it = from_data.begin();
00170 it != from_data.end();
00171 ++it)
00172 precondition_ (s.alphabet().contains(*it),
00173 "The letter " + vcsn::algebra::letter_traits<T>::letter_to_literal(*it) +
00174 " is not in the given alphabet");
00175 # else // ! VCSN_NDEBUG
00176 (void) s;
00177 # endif // ! VCSN_NDEBUG
00178 return from_data;
00179 }
00180
00181 namespace algebra {
00182
00183
00184
00185
00186
00187 template <typename S, typename T>
00188 bool op_parse(const algebra::FreeMonoidBase<S>&,
00189 T& v,
00190 const std::string& s)
00191 {
00192 static_error(no_op_parse_operator_available);
00193 return false;
00194 }
00195
00196 template <typename Self, typename T>
00197 void
00198 op_in_mirror(const algebra::FreeMonoidBase<Self>& s, T& v)
00199 {
00200 const T new_v(v);
00201 typename MetaElement<algebra::FreeMonoidBase<Self>, T>::iterator it
00202 = op_begin(s.self(), v);
00203
00204 for (typename MetaElement<algebra::FreeMonoidBase<Self>, T>::
00205 const_reverse_iterator i = op_rbegin_const(s.self(), new_v);
00206 i != op_rend_const(s.self(), new_v);
00207 ++i)
00208 *it++ = *i;
00209 }
00210
00211 template <typename Self, typename T>
00212 bool
00213 op_contains(const algebra::FreeMonoidBase<Self>& s, const T& v)
00214 {
00215 typedef typename op_begin_traits<Self, T>::const_ret_t const_iterator;
00216
00217 for (const_iterator i = op_begin_const(s.self(), v);
00218 i != op_end_const(s.self(), v);
00219 ++i)
00220 if (! s.alphabet().contains(*i))
00221 return false;
00222 return true;
00223 }
00224
00225 template <typename Self, typename St, typename T>
00226 St&
00227 op_rout(const algebra::FreeMonoidBase<Self>& s,
00228 St& st,
00229 const T& v)
00230 {
00231 return op_rout(s.self(), st, v);
00232 }
00233
00234 }
00235
00236 }
00237
00238 #endif // ! VCSN_ALGEBRA_CONCEPT_FREEMONOID_BASE_HXX