range.hxx

00001 // range.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 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_IMPLEMENTATION_LETTER_RANGE_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_RANGE_HXX
00019 
00020 # include <cstdlib>
00021 # include <cmath>
00022 
00023 namespace vcsn
00024 {
00025 
00026   namespace algebra
00027   {
00028 
00029     template <class T, class Interval>
00030     static_ranged<T, Interval>::static_ranged()
00031     {}
00032 
00033     template <class T, class Interval>
00034     static_ranged<T, Interval>::static_ranged(const T& v)
00035     {
00036       if (Interval::check(v))
00037         value_ = v;
00038       else
00039         value_ = Interval::from();
00040     }
00041 
00042     template <class T, class Interval>
00043     static_ranged<T, Interval>::static_ranged(const static_ranged& o) :
00044       value_(o.value_)
00045     {}
00046 
00047     template <class T, class Interval>
00048     static_ranged<T, Interval>::operator T() const
00049     {
00050       return value_;
00051     }
00052 
00053     template <class T, class Interval>
00054     bool operator<(const static_ranged<T, Interval>& lhs,
00055                    const static_ranged<T, Interval>& rhs)
00056     {
00057       return lhs.value() < rhs.value();
00058     }
00059 
00060     template <class T, class Interval>
00061     bool operator==(const static_ranged<T, Interval>& lhs,
00062                    const static_ranged<T, Interval>& rhs)
00063     {
00064       return lhs.value() == rhs.value();
00065     }
00066 
00067     template <class T, class Interval>
00068     const T& static_ranged<T, Interval>::value() const
00069     {
00070       return value_;
00071     }
00072 
00073     template <class T, class Interval>
00074     T& static_ranged<T, Interval>::value()
00075     {
00076       return value_;
00077     }
00078 
00079     template <class T, class Interval>
00080     static_ranged<T, Interval>
00081     static_ranged<T, Interval>::randomized()
00082     {
00083       value_ = Interval::random();
00084       return *this;
00085     }
00086 
00087     template <char From, char To>
00088     bool
00089     static_char_interval<From, To>::check(char c)
00090     {
00091       return ((c >= From) && (c <= To));
00092     }
00093 
00094     template <char From, char To>
00095     char static_char_interval<From, To>::from()
00096     {
00097       return From;
00098     }
00099 
00100     template <char From, char To>
00101     char static_char_interval<From, To>::to()
00102     {
00103       return To;
00104     }
00105 
00106     template <char From, char To>
00107     char static_char_interval<From, To>::random()
00108     {
00109       unsigned r = floor((float (rand()) / RAND_MAX) * (To - From + 1));
00110       return (char)(From + r);
00111     }
00112 
00113   } // algebra
00114 
00115 } // vcsn
00116 
00117 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_RANGE_HXX

Generated on Fri Jul 28 12:18:51 2006 for Vaucanson by  doxygen 1.4.6