00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef VCSN_ALGEBRA_CONCEPT_ALPHABETS_BASE_HXX
00018 # define VCSN_ALGEBRA_CONCEPT_ALPHABETS_BASE_HXX
00019 
00020 # include <vaucanson/algebra/concept/alphabets_base.hh>
00021 # include <vaucanson/misc/random.hh>
00022 # include <vaucanson/misc/contract.hh>
00023 # include <cstddef>
00024 
00025 namespace vcsn {
00026 
00027   namespace algebra {
00028 
00029     
00030 
00031 
00032 
00033     template<typename S>
00034     AlphabetSetBase<S>::AlphabetSetBase()
00035     {}
00036 
00037     template<typename S>
00038     AlphabetSetBase<S>::AlphabetSetBase(const AlphabetSetBase& other)
00039     {}
00040 
00041   } 
00042 
00043   
00044 
00045 
00046   
00047   
00048 
00049   template<typename S, typename T>
00050   size_t
00051   MetaElement<algebra::AlphabetSetBase<S>, T>::size() const
00052   {
00053     return op_size(this->structure(), this->value());
00054   }
00055 
00056   template<typename S, typename T>
00057   size_t
00058   MetaElement<algebra::AlphabetSetBase<S>, T>::max_size() const
00059   {
00060     return op_max_size(this->structure(), this->value());
00061   }
00062 
00063   template<typename S, typename T>
00064   bool
00065   MetaElement<algebra::AlphabetSetBase<S>, T>::contains(const letter_t& l) const
00066   {
00067     return op_contains_e(this->structure(), this->value(), l);
00068   }
00069 
00070   template<typename S, typename T>
00071   bool
00072   MetaElement<algebra::AlphabetSetBase<S>, T>::is_finite() const
00073   {
00074     return op_is_finite(this->structure(), this->value());
00075   }
00076 
00077   template<typename S, typename T>
00078   typename MetaElement<algebra::AlphabetSetBase<S>, T>::iterator
00079   MetaElement<algebra::AlphabetSetBase<S>, T>::begin()
00080   {
00081     return op_begin(this->structure(), this->value());
00082   }
00083 
00084   template<typename S, typename T>
00085   typename MetaElement<algebra::AlphabetSetBase<S>, T>::const_iterator
00086   MetaElement<algebra::AlphabetSetBase<S>, T>::begin() const
00087   {
00088     return op_begin_const(this->structure(), this->value());
00089   }
00090 
00091   template<typename S, typename T>
00092   typename MetaElement<algebra::AlphabetSetBase<S>, T>::iterator
00093   MetaElement<algebra::AlphabetSetBase<S>, T>::end()
00094   {
00095     return op_end(this->structure(), this->value());
00096   }
00097 
00098   template<typename S, typename T>
00099   typename MetaElement<algebra::AlphabetSetBase<S>, T>::const_iterator
00100   MetaElement<algebra::AlphabetSetBase<S>, T>::end() const
00101   {
00102     return op_end_const(this->structure(), this->value());
00103   }
00104 
00105   template<typename S, typename T>
00106   void
00107   MetaElement<algebra::AlphabetSetBase<S>, T>::insert(const letter_t& l)
00108   {
00109     op_insert(this->structure(), this->value(), l);
00110   }
00111 
00112   template<typename S, typename T>
00113   bool
00114   MetaElement<algebra::AlphabetSetBase<S>, T>::letter_equality(letter_t lhs,
00115                                                                letter_t rhs) const
00116   {
00117     return op_letter_equality(this->structure(), this->value(), lhs, rhs);
00118   }
00119 
00120   template<typename S, typename T>
00121   typename algebra::alphabet_traits<S, T>::letter_t
00122   MetaElement<algebra::AlphabetSetBase<S>, T>::choose() const
00123   {
00124     
00125     precondition (is_finite());
00126     precondition (size() > 0);
00127 
00128     int  nr = misc::random::generate<int>(0, size() - 1);
00129 
00130     const_iterator it = begin();
00131     for (int k = 0; k < nr; ++k)
00132       ++it;
00133 
00134     return *it;
00135   }
00136 
00137   template <class S, typename T>
00138   typename algebra::alphabet_traits<S, T>::letter_t
00139   MetaElement<algebra::AlphabetSetBase<S>, T>::random_letter() const
00140   {
00141     return misc::random::generate
00142       <typename algebra::alphabet_traits<S, T>::letter_t>();
00143   }
00144 
00145   template<typename S, typename T>
00146   MetaElement<algebra::AlphabetSetBase<S>, T>::MetaElement()
00147   {}
00148 
00149   template<typename S, typename T>
00150   MetaElement<algebra::AlphabetSetBase<S>, T>::MetaElement(const MetaElement& other) :
00151     MetaElement<Structure<S>, T>(other)
00152   {}
00153 
00154   template <typename S, typename T, typename L>
00155   bool op_letter_equality(const algebra::AlphabetSetBase<S>& s,
00156                           const T& a,
00157                           L lhs,
00158                           L rhs)
00159   {
00160     return lhs == rhs;
00161   }
00162 
00163   template<typename S, typename St, typename T>
00164   St& op_rout(const algebra::AlphabetSetBase<S>& s, St& st, const T& a)
00165   {
00166     st << "{ ";
00167     if (op_is_finite(s.self(), a))
00168       for (typename op_begin_traits<S, T>::const_ret_t i = op_begin_const(s.self(), a);
00169            i != op_end_const(s.self(), a);
00170            ++i)
00171         {
00172           if (i != op_begin_const(s.self(), a))
00173             st << ", ";
00174           st << *i;
00175         }
00176     else
00177       st << "<many letters>";
00178     st << " }";
00179     return st;
00180   }
00181 
00182 } 
00183 
00184 #endif // ! VCSN_ALGEBRA_CONCEPT_ALPHABETS_BASE_HXX