00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 }
00114
00115 }
00116
00117 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_RANGE_HXX