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 <limits.h>
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 enum
00033 {
00034
00035
00036 cardinal = UINT_MAX
00037 };
00038
00039 static const char default_epsilon() { return 'e'; }
00040
00041 static
00042 int
00043 literal_to_letter(const std::string& str)
00044 {
00045 std::stringstream sstr(str);
00046 int ret;
00047 sstr >> ret;
00048 return ret;
00049 }
00050
00051 static
00052 std::string
00053 letter_to_literal(const int& c)
00054 {
00055 std::stringstream sstr;
00056 sstr << c;
00057 std::string str;
00058 sstr >> str;
00059 return str;
00060 }
00061 };
00062
00063 template <typename S, typename CharContainer>
00064 bool op_parse(const algebra::FreeMonoidBase<S>& set,
00065 std::basic_string<int>& v,
00066 const std::string& s,
00067 typename std::string::const_iterator& i,
00068 const CharContainer&)
00069 {
00070 typename std::string::const_iterator j = i;
00071 typename std::string::const_iterator k;
00072 typename std::string::const_iterator back;
00073
00074 while (i != s.end()) {
00075 std::string out;
00076 back = i;
00077
00078 while ((i != s.end()) && (((*i >= '0') && (*i <= '9'))) || (*i == '#'))
00079 if (*i == '#') {
00080 ++i;
00081 break;
00082 }
00083 else {
00084 out += *i;
00085 ++i;
00086 }
00087
00088 int value;
00089 std::istringstream is(out);
00090 is >> value;
00091 if (!set.alphabet().contains(value)) {
00092 i = back;
00093 break ;
00094 }
00095 v.push_back(value);
00096 }
00097 return (i != j);
00098 }
00099
00100 }
00101
00102 }
00103
00104 namespace std {
00105
00106 inline
00107 ostream& operator<<(ostream& o, basic_string<int> s)
00108 {
00109 basic_string<int>::const_iterator i;
00110 basic_string<int>::const_iterator j;
00111
00112 for (i = s.begin(); i != s.end(); ) {
00113 o << *i;
00114 i++;
00115 if (i != s.end())
00116 o << "#";
00117 }
00118
00119 return o;
00120 }
00121
00122 }
00123
00124 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX