00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
00019
00020 # include <sstream>
00021
00022 # include <vaucanson/algebra/implementation/letter/couple_letter.hh>
00023
00024 namespace vcsn {
00025
00026
00027 template <typename S, typename U, typename V>
00028 bool op_parse(const algebra::FreeMonoidBase<S>& set,
00029 std::basic_string< std::pair<U, V> >& v,
00030 const std::string& s,
00031 typename std::string::const_iterator& i,
00032 const std::list<char>&)
00033 {
00034 typename std::string::const_iterator j = i;
00035
00036 while (i != s.end()) {
00037 if (*i != '(')
00038 break ;
00039 std::string sub(i, s.end());
00040 std::istringstream is(sub);
00041 std::pair<U,V> p;
00042 is >> p;
00043 if (!set.alphabet().contains(p))
00044 break ;
00045 int inc = sub.size() - is.str().size();
00046 for (int k = 0; k < inc; k++, i++) ;
00047 v += p;
00048 }
00049 return (i != j);
00050 }
00051 }
00052
00053 namespace utility {
00054
00055 template <typename U, typename V>
00056 std::ostream& operator<<(std::ostream& o, std::pair<U, V> p)
00057 {
00058 return o << "(" << p.first << "," << p.second << ")";
00059 }
00060
00061 template <typename U, typename V, class Traits, class Allocator>
00062 std::ostream& operator<<(std::ostream& o,
00063 std::basic_string<std::pair<U, V>, Traits, Allocator> s)
00064 {
00065 typename
00066 std::basic_string<std::pair<U, V>, Traits, Allocator>::const_iterator i;
00067 for (i = s.begin(); i != s.end(); ++i)
00068 o << "(" << i->first << "," << i->second << ")";
00069 return o;
00070 }
00071
00072 template <typename U, typename V>
00073 std::istream& operator>>(std::istream& i, std::pair<U, V>& p)
00074 {
00075 char c = i.get();
00076 if (c != '(')
00077 i.unget();
00078 i >> p.first;
00079 c = i.get();
00080 if (c != ',')
00081 i.unget();
00082 i >> p.second;
00083 c = i.get();
00084 if (c != ')')
00085 i.unget();
00086 return i;
00087 }
00088
00089 }
00090
00091 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX