Vaucanson 1.4
|
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 # include <utility> 00022 00023 # include <vaucanson/algebra/implementation/letter/char_letter.hh> 00024 00025 namespace vcsn 00026 { 00027 namespace algebra 00028 { 00029 template <> 00030 struct letter_traits<char> 00031 { 00032 // This letter type needs one char to be displayed. 00033 typedef misc::true_t is_char_letter; 00034 00035 enum 00036 { 00037 // Here we use 255 and not 256 because random::generate<char> 00038 // does not generates 0 to avoid conflicts with 0 terminated 00039 // C strings. Therefore char alphabets will never hold more 00040 // than 255 different letters. 00041 cardinal = 255 00042 }; 00043 00044 // We can not "project" a char letter. 00045 typedef undefined_type first_projection_t; 00046 typedef undefined_type second_projection_t; 00047 00048 // FIXME: use LETTER_DEFAULT 00049 static char default_joker() { return '?'; } 00050 static char default_other() { return '#'; } 00051 00052 static 00053 std::pair<bool, char> 00054 literal_to_letter(const std::string& str) 00055 { 00056 // Check for the size of the input (a char is a one sized string). 00057 if (str.size() != 1) 00058 return std::make_pair(false, 0); 00059 00060 return std::make_pair(true, str[0]); 00061 } 00062 00063 static 00064 std::string 00065 letter_to_literal(const char& c) 00066 { 00067 std::string str; 00068 str = str + c; 00069 return str; 00070 } 00071 00072 // A char is "simple" with dimension 1. 00073 static std::string kind() { return "simple"; } 00074 static int dim() { return 1; } 00075 00076 }; 00077 00078 } // ! algebra 00079 00080 } // ! vcsn 00081 00082 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_CHAR_LETTER_HXX