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