char_letter.hxx

00001 // char_letter.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2008 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_CHAR_LETTER_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX
00019 
00020 # include <string>
00021 
00022 # include <vaucanson/algebra/implementation/letter/char_letter.hh>
00023 
00024 namespace vcsn {
00025 
00026   namespace algebra {
00027 
00028     template <>
00029     struct letter_traits<char>
00030     {
00031       // This letter type needs one char to be displayed.
00032       typedef misc::true_t is_char_letter;
00033 
00034       enum
00035       {
00036         // Here we use 255 and not 256 because random::generate<char>
00037         // does not generates 0 to avoid conflicts with 0 terminated
00038         // C strings. Therefore char alphabets will never hold more
00039         // than 255 different letters.
00040         cardinal = 255
00041       };
00042 
00043       // We can not "project" a char letter.
00044       typedef undefined_type first_projection_t;
00045       typedef undefined_type second_projection_t;
00046 
00047       // FIXME: use LETTER_DEFAULT
00048       static char default_joker()   { return '?'; }
00049       static char default_other()   { return '#'; }
00050 
00051       LETTER_DEFAULT(open_par, "(")
00052       LETTER_DEFAULT(close_par, ")")
00053       LETTER_DEFAULT(plus, "+")
00054       LETTER_DEFAULT(times, ".")
00055       LETTER_DEFAULT(star, "*")
00056       LETTER_DEFAULT(epsilon, "1")
00057       LETTER_DEFAULT(zero, "0")
00058       LETTER_DEFAULT(open_weight, "{")
00059       LETTER_DEFAULT(close_weight, "}")
00060       LETTER_DEFAULT(space, " ")
00061 
00062       static
00063       char
00064       literal_to_letter(const std::string& str)
00065       {
00066         precondition(str.size() == 1);
00067         return str[0];
00068       }
00069 
00070       static
00071       std::string
00072       letter_to_literal(const char& c)
00073       {
00074         std::string str;
00075         str = str + c;
00076         return str;
00077       }
00078 
00079       // A char is "simple" with dimension 1.
00080       static std::string kind() { return "simple"; }
00081       static int dim() { return 1; }
00082 
00083     };
00084 
00085     template <typename S, typename CharContainer>
00086     bool op_parse(const algebra::FreeMonoidBase<S>& set,
00087                   std::basic_string<char>& v,
00088                   const std::string& s,
00089                   typename std::string::const_iterator& i,
00090                   const CharContainer&)
00091     {
00092       typename std::string::const_iterator j = i;
00093       typename std::string::const_iterator k;
00094 
00095       while ((i != s.end()) && (set.alphabet().contains(*i)))
00096       {
00097         v += *i;
00098         ++i;
00099       }
00100       return (i != j);
00101     }
00102 
00103   } // ! algebra
00104 
00105 } // ! vcsn
00106 
00107 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX

Generated on Thu Oct 9 20:22:34 2008 for Vaucanson by  doxygen 1.5.1