dune-grid  2.4.1
b64enc.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_GRID_IO_FILE_VTK_B64ENC_HH
5 #define DUNE_GRID_IO_FILE_VTK_B64ENC_HH
6 
7 #include <assert.h>
8 
9 namespace Dune {
10 
19  const char base64table[] =
20  {
21  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
22  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
23  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
24  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
25  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
26  };
27 
29  struct b64txt
30  {
31  typedef unsigned char size_type;
32  size_type size;
33  char txt[3];
34  int read(const char* t, size_type s)
35  {
36  size = s>=3 ? 3 : s;
37  txt[2] = s>0 ? t[0] : 0;
38  txt[1] = s>1 ? t[1] : 0;
39  txt[0] = s>2 ? t[2] : 0;
40  return size;
41  }
42  void put(const char c)
43  {
44  assert (size < 3);
45  txt[2-size++] = c;
46  }
47  };
48 
50  struct b64data
51  {
52  typedef unsigned char size_type;
53  size_type size;
54  unsigned A : 6;
55  unsigned B : 6;
56  unsigned C : 6;
57  unsigned D : 6;
58  void write(char* t)
59  {
60  t[3] = size>2 ? base64table[A] : '=';
61  t[2] = size>1 ? base64table[B] : '=';
62  t[1] = size>0 ? base64table[C] : '=';
63  t[0] = size>0 ? base64table[D] : '=';
64  size = 0;
65  }
66  };
67 
69  union b64chunk
70  {
73  };
74 
77 } // namespace Dune
78 
79 #endif // DUNE_GRID_IO_FILE_VTK_B64ENC_HH
b64txt txt
Definition: b64enc.hh:71
b64data data
Definition: b64enc.hh:72
void put(const char c)
Definition: b64enc.hh:42
unsigned char size_type
Definition: b64enc.hh:31
union representing the three byte text aswell as the four 6 bit chunks
Definition: b64enc.hh:69
unsigned B
Definition: b64enc.hh:55
unsigned D
Definition: b64enc.hh:57
const char base64table[]
endoing table
Definition: b64enc.hh:19
char txt[3]
Definition: b64enc.hh:33
size_type size
Definition: b64enc.hh:53
void write(char *t)
Definition: b64enc.hh:58
struct with three bytes of text
Definition: b64enc.hh:29
unsigned A
Definition: b64enc.hh:54
unsigned C
Definition: b64enc.hh:56
Include standard header files.
Definition: agrid.hh:59
int read(const char *t, size_type s)
Definition: b64enc.hh:34
size_type size
Definition: b64enc.hh:32
unsigned char size_type
Definition: b64enc.hh:52
Definition: b64enc.hh:50