18 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
19 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX
27 # include <vaucanson/algebra/implementation/letter/couple_letter.hh>
33 template <
typename U,
typename V>
34 struct letter_traits< std::pair<U, V> >
37 typedef misc::true_t is_char_letter;
53 typedef U first_projection_t;
54 typedef V second_projection_t;
57 std::pair<bool, std::pair<U, V> >
58 literal_to_letter(
const std::string& str)
61 if (str.size() < 5 || str[0] !=
'(' || *(str.end() - 1) !=
')')
62 return std::make_pair(
false, std::make_pair(0, 0));
65 typedef std::vector<std::string> tokens_t;
66 typedef tokens_t::const_iterator tokens_iter_t;
67 std::string delim =
",";
68 std::string buff(str.begin() + 1, str.end() - 1);
70 std::string::size_type last_pos = buff.find_first_not_of(delim, 0);
71 std::string::size_type pos = buff.find_first_of(delim, last_pos);
75 while (std::string::npos != pos || std::string::npos != last_pos)
78 tokens.push_back(buff.substr(last_pos, pos - last_pos));
80 last_pos = buff.find_first_not_of(delim, pos);
81 pos = buff.find_first_of(delim, last_pos);
84 if (tokens.size() != 2)
85 return std::make_pair(
false, std::make_pair(0, 0));
87 std::pair<bool, U> fc = algebra::letter_traits<U>::literal_to_letter(tokens[0]);
88 std::pair<bool, V> sc = algebra::letter_traits<V>::literal_to_letter(tokens[1]);
90 if (!(fc.first && sc.first))
91 return std::make_pair(
false, std::make_pair(0, 0));
93 return std::make_pair(
true, std::make_pair(fc.second, sc.second));
98 letter_to_literal(
const std::pair<U, V>& c)
100 std::stringstream sstr;
101 sstr <<
'(' << c.first <<
',' << c.second <<
')';
106 static std::string kind() {
return "tuple"; }
107 static int dim() {
return 2; }
117 template <
typename U,
typename V>
118 std::ostream& operator<<(std::ostream& s, const std::pair<U, V>& letter)
120 s << vcsn::algebra::letter_traits<std::pair<U, V> >::letter_to_literal(letter);
126 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX