00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
00019 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
00020
00021 # include <stdexcept>
00022 # include <sstream>
00023
00024 # include <vaucanson/algebra/implementation/letter/couple_letter.hh>
00025
00026 namespace vcsn {
00027
00028 namespace algebra {
00029
00030
00031
00032
00033 template <typename S, typename U, typename V, typename CharContainer>
00034 bool op_parse(const algebra::FreeMonoidBase<S>& set,
00035 std::basic_string< std::pair<U, V> >& v,
00036 const std::string& s,
00037 typename std::string::const_iterator& i,
00038 const CharContainer&)
00039 {
00040 while (i != s.end())
00041 {
00042 if (*i != '(')
00043 break ;
00044
00045 std::string sub(i, s.end());
00046 std::stringstream is(sub);
00047
00048 std::pair<U,V> p;
00049 is >> p;
00050 int pos = is.tellg();
00051
00052
00053 if (pos == 0)
00054 break;
00055
00056
00057 if (!set.alphabet().contains(p))
00058 {
00059 std::stringstream sstr;
00060 sstr << p;
00061 throw std::logic_error(std::string("Letter not in the alphabet: ") + sstr.str());
00062 }
00063
00064
00065 for (int k = 0; k < pos; ++k)
00066 ++i;
00067
00068
00069 v += p;
00070 }
00071
00072 return (i == s.end());
00073 }
00074
00075 }
00076
00077 }
00078
00079 namespace std
00080 {
00081
00082 template <typename U, typename V>
00083 std::ostream& operator<< (std::ostream& o, std::pair<U, V> p)
00084 {
00085 return o << "(" << p.first << "," << p.second << ")";
00086 }
00087
00088 template <typename U, typename V, class Traits, class Allocator>
00089 std::ostream& operator<< (std::ostream& o,
00090 std::basic_string<std::pair<U, V>, Traits, Allocator> s)
00091 {
00092 typename
00093 std::basic_string<std::pair<U, V>, Traits, Allocator>::const_iterator i;
00094 for (i = s.begin (); i != s.end (); ++i)
00095 o << "(" << i->first << "," << i->second << ")";
00096 return o;
00097 }
00098
00099 template <typename U, typename V>
00100 std::istream& operator>> (std::istream& i, std::pair<U, V>& p)
00101 {
00102 char c = i.get ();
00103 if (c != '(')
00104 i.unget ();
00105 i >> p.first;
00106 c = i.get ();
00107 if (c != ',')
00108 i.unget ();
00109 i >> p.second;
00110 c = i.get ();
00111 if (c != ')')
00112 i.unget ();
00113 return i;
00114 }
00115
00116 }
00117
00118 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX