00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00019
00020 # include <sstream>
00021 # include <climits>
00022
00023 # include <vaucanson/algebra/implementation/letter/int_letter.hh>
00024
00025 namespace vcsn {
00026
00027 namespace algebra {
00028
00029 template <>
00030 struct letter_traits<int>
00031 {
00032
00033 typedef misc::false_t is_char_letter;
00034
00035 enum
00036 {
00037
00038
00039 cardinal = UINT_MAX
00040 };
00041
00042
00043 typedef undefined_type first_projection_t;
00044 typedef undefined_type second_projection_t;
00045
00046 LETTER_DEFAULT(open_par, "(")
00047 LETTER_DEFAULT(close_par, ")")
00048 LETTER_DEFAULT(plus, "+")
00049 LETTER_DEFAULT(times, ".")
00050 LETTER_DEFAULT(star, "*")
00051 LETTER_DEFAULT(epsilon, "e")
00052 LETTER_DEFAULT(zero, "z")
00053 LETTER_DEFAULT(open_weight, "{")
00054 LETTER_DEFAULT(close_weight, "}")
00055 LETTER_DEFAULT(space, " ")
00056
00057 static
00058 int
00059 literal_to_letter(const std::string& str)
00060 {
00061 std::stringstream sstr(str);
00062 int ret;
00063 sstr >> ret;
00064 return ret;
00065 }
00066
00067 static
00068 std::string
00069 letter_to_literal(const int& c)
00070 {
00071 std::stringstream sstr;
00072 sstr << c;
00073 return sstr.str();
00074 }
00075
00076 // An int is "simple" with dimension 1.
00077 static std::string kind() { return "simple"; }
00078 static int dim() { return 1; }
00079
00080 };
00081
00082 template <typename S, typename CharContainer>
00083 bool op_parse(const algebra::FreeMonoidBase<S>& set,
00084 std::basic_string<int>& v,
00085 const std::string& s,
00086 typename std::string::const_iterator& i,
00087 const CharContainer&)
00088 {
00089 typename std::string::const_iterator j = i;
00090 typename std::string::const_iterator back;
00091
00092 while (i != s.end()) {
00093 std::string out;
00094 back = i;
00095
00096 while ((i != s.end()) && (((*i >= '0') && (*i <= '9')) || (*i == '#')))
00097 if (*i == '#') {
00098 ++i;
00099 break;
00100 }
00101 else {
00102 out += *i;
00103 ++i;
00104 }
00105
00106 if (out.empty())
00107 break;
00108
00109 int value;
00110 std::istringstream is(out);
00111 is >> value;
00112
00113 if (!set.alphabet().contains(value)) {
00114 i = back;
00115 break ;
00116 }
00117 v.push_back(value);
00118 }
00119 return (i != j);
00120 }
00121
00122 } // ! algebra
00123
00124 } // ! vcsn
00125
00126 namespace std {
00127
00128 inline
00129 ostream& operator<<(ostream& o, basic_string<int> s)
00130 {
00131 basic_string<int>::const_iterator i;
00132 basic_string<int>::const_iterator j;
00133
00134 for (i = s.begin(); i != s.end(); ) {
00135 o << *i;
00136 i++;
00137 if (i != s.end())
00138 o << "#";
00139 }
00140
00141 return o;
00142 }
00143
00144 } // ! std
00145
00146 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX