File: mcf_alphabet.hh

package info (click to toggle)
tantan 23-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 492 kB
  • sloc: cpp: 2,062; sh: 58; makefile: 39
file content (52 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2010 Martin C. Frith

// An "Alphabet" consists of two things:
// 1) A mapping from ASCII letters to small integers.
// 2) A distinction between "normal" and "abnormal" letters.  The
// letters that map to the first "size" integers are normal.  For
// example, for DNA, ACGT would be normal.

#ifndef MCF_ALPHABET_HH
#define MCF_ALPHABET_HH

#include <string>

namespace mcf {

typedef unsigned char uchar;

struct Alphabet {
  static const char* dna;
  static const char* protein;

  static const unsigned capacity = 256;

  // Initializes the Alphabet with the given normal letters.
  void fromString(const std::string &normalLetters);  // case is preserved

  // Makes lowercase letters map to the same numbers that uppercase
  // letters do.
  void makeCaseInsensitive();

  // Maps letters to numbers in the given range.
  void encodeInPlace(uchar *beg, uchar *end) const;

  // Maps numbers back to letters in the given range.
  void decodeInPlace(uchar *beg, uchar *end) const;

  unsigned size;  // number of "normal" letters in the alphabet

  uchar lettersToNumbers[capacity];
  uchar numbersToLetters[capacity];

  uchar numbersToUppercase[capacity];
  uchar numbersToLowercase[capacity];

 private:
  void addLetters(const std::string &letters, uchar &number);
  void initCaseConversions();
};

}

#endif