dune-grid 3.0-git
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
9namespace Dune {
10
21 const char base64table[] =
22 {
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 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
26 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
27 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
28 };
29
31 struct b64txt
32 {
33 typedef unsigned char size_type;
35 char txt[3];
36 int read(const char* t, size_type s)
37 {
38 size = s>=3 ? 3 : s;
39 txt[2] = s>0 ? t[0] : 0;
40 txt[1] = s>1 ? t[1] : 0;
41 txt[0] = s>2 ? t[2] : 0;
42 return size;
43 }
44 void put(const char c)
45 {
46 assert (size < 3);
47 txt[2-size++] = c;
48 }
49 };
50
52 struct b64data
53 {
54 typedef unsigned char size_type;
56 unsigned A : 6;
57 unsigned B : 6;
58 unsigned C : 6;
59 unsigned D : 6;
60 void write(char* t)
61 {
62 t[3] = size>2 ? base64table[A] : '=';
63 t[2] = size>1 ? base64table[B] : '=';
64 t[1] = size>0 ? base64table[C] : '=';
65 t[0] = size>0 ? base64table[D] : '=';
66 size = 0;
67 }
68 };
69
72 {
75 };
76
79} // namespace Dune
80
81#endif // DUNE_GRID_IO_FILE_VTK_B64ENC_HH
Include standard header files.
Definition agrid.hh:60
const char base64table[]
endoing table
Definition b64enc.hh:21
struct with three bytes of text
Definition b64enc.hh:32
void put(const char c)
Definition b64enc.hh:44
unsigned char size_type
Definition b64enc.hh:33
char txt[3]
Definition b64enc.hh:35
size_type size
Definition b64enc.hh:34
int read(const char *t, size_type s)
Definition b64enc.hh:36
Definition b64enc.hh:53
unsigned A
Definition b64enc.hh:56
unsigned char size_type
Definition b64enc.hh:54
void write(char *t)
Definition b64enc.hh:60
unsigned C
Definition b64enc.hh:58
unsigned D
Definition b64enc.hh:59
size_type size
Definition b64enc.hh:55
unsigned B
Definition b64enc.hh:57
union representing the three byte text as well as the four 6 bit chunks
Definition b64enc.hh:72
b64txt txt
Definition b64enc.hh:73
b64data data
Definition b64enc.hh:74