- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# couple_letter.hxx

    00001 // couple_letter.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License
    00009 // as published by the Free Software Foundation; either version 2
    00010 // of the License, or (at your option) any later version.
    00011 //
    00012 // The complete GNU General Public Licence Notice can be found as the
    00013 // `COPYING' file in the root directory.
    00014 //
    00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
    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   namespace algebra {
    00027
    00028     // Specialization for pairs.
    00029     template <typename S, typename U, typename V, typename CharContainer>
    00030     bool op_parse (const algebra::FreeMonoidBase<S>& set,
    00031                    std::basic_string< std::pair<U, V> >& v,
    00032                    const std::string& s,
    00033                    typename std::string::const_iterator& i,
    00034                    const CharContainer&)
    00035     {
    00036       typename std::string::const_iterator j = i;
    00037
    00038       while (i != s.end ()) {
    00039         if (*i != '(')
    00040           break ;
    00041         std::string sub (i, s.end ());
    00042         std::istringstream is (sub);
    00043         std::pair<U,V> p;
    00044         is >> p;
    00045         if (!set.alphabet ().contains (p))
    00046           break ;
    00047         int inc = sub.size () - is.str ().size ();
    00048         for (int k = 0; k < inc; k++, i++) ;
    00049         v += p;
    00050       }
    00051       return (i != j);
    00052     }
    00053
    00054   } // algebra
    00055 } // vcsn
    00056
    00057 namespace std
    00058 {
    00059
    00060   template <typename U, typename V>
    00061   std::ostream& operator<< (std::ostream& o, std::pair<U, V> p)
    00062   {
    00063     return o << "(" << p.first << "," << p.second << ")";
    00064   }
    00065
    00066   template <typename U, typename V, class Traits, class Allocator>
    00067   std::ostream& operator<< (std::ostream& o,
    00068                             std::basic_string<std::pair<U, V>, Traits, Allocator> s)
    00069   {
    00070     typename
    00071       std::basic_string<std::pair<U, V>, Traits, Allocator>::const_iterator i;
    00072     for (i = s.begin (); i != s.end (); ++i)
    00073       o << "(" << i->first << "," << i->second << ")";
    00074     return o;
    00075   }
    00076
    00077   template <typename U, typename V>
    00078   std::istream& operator>> (std::istream& i, std::pair<U, V>& p)
    00079   {
    00080     char c = i.get ();
    00081     if (c != '(')
    00082       i.unget ();
    00083     i >> p.first;
    00084     c = i.get ();
    00085     if (c != ',')
    00086       i.unget ();
    00087     i >> p.second;
    00088     c = i.get ();
    00089     if (c != ')')
    00090       i.unget ();
    00091     return i;
    00092   }
    00093
    00094 } // std
    00095
    00096
    00097 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_COUPLE_LETTER_HXX