- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# alphabets_base.hxx

    00001 // alphabets_base.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 #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     | AlphabetSetBase<S> |
    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   } // algebra
    00042
    00043   /*-----------------------------------.
    00044   | MetaElement<AlphabetSetBase<S>, T> |
    00045   `-----------------------------------*/
    00046   // Meta-information about element formed from an AlphabetSetBase
    00047   // structuring element.
    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     // FIXME: recommendation(overload this operator)
    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   namespace algebra {
    00155
    00156     template <typename S, typename T, typename L>
    00157     bool op_letter_equality(const algebra::AlphabetSetBase<S>& s,
    00158                             const T& a,
    00159                             L lhs,
    00160                             L rhs)
    00161     {
    00162       return lhs == rhs;
    00163     }
    00164
    00165     template<typename S, typename St, typename T>
    00166     St& op_rout(const algebra::AlphabetSetBase<S>& s, St& st, const T& a)
    00167     {
    00168       st << "{ ";
    00169       if (op_is_finite(s.self(), a))
    00170         for (typename op_begin_traits<S, T>::const_ret_t i = op_begin_const(s.self(), a);
    00171              i != op_end_const(s.self(), a);
    00172              ++i)
    00173           {
    00174             if (i != op_begin_const(s.self(), a))
    00175               st << ", ";
    00176             st << *i;
    00177           }
    00178       else
    00179         st << "<many letters>";
    00180       st << " }";
    00181       return st;
    00182     }
    00183
    00184   } // algebra
    00185
    00186 } // vcsn
    00187
    00188 #endif // ! VCSN_ALGEBRA_CONCEPT_ALPHABETS_BASE_HXX