Vaucanson  1.4.1
char_letter.hxx
1 // char_letter.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX
19 
20 # include <string>
21 # include <utility>
22 
23 # include <vaucanson/algebra/implementation/letter/char_letter.hh>
24 
25 namespace vcsn
26 {
27  namespace algebra
28  {
29  template <>
30  struct letter_traits<char>
31  {
32  // This letter type needs one char to be displayed.
33  typedef misc::true_t is_char_letter;
34 
35  enum
36  {
37  // Here we use 255 and not 256 because random::generate<char>
38  // does not generates 0 to avoid conflicts with 0 terminated
39  // C strings. Therefore char alphabets will never hold more
40  // than 255 different letters.
41  cardinal = 255
42  };
43 
44  // We can not "project" a char letter.
45  typedef undefined_type first_projection_t;
46  typedef undefined_type second_projection_t;
47 
48  // FIXME: use LETTER_DEFAULT
49  static char default_joker() { return '?'; }
50  static char default_other() { return '#'; }
51 
52  static
53  std::pair<bool, char>
54  literal_to_letter(const std::string& str)
55  {
56  // Check for the size of the input (a char is a one sized string).
57  if (str.size() != 1)
58  return std::make_pair(false, 0);
59 
60  return std::make_pair(true, str[0]);
61  }
62 
63  static
64  std::string
65  letter_to_literal(const char& c)
66  {
67  std::string str;
68  str = str + c;
69  return str;
70  }
71 
72  // A char is "simple" with dimension 1.
73  static std::string kind() { return "simple"; }
74  static int dim() { return 1; }
75 
76  };
77 
78  } // ! algebra
79 
80 } // ! vcsn
81 
82 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX