Dune Core Modules (2.6.0)

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;
34 size_type size;
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;
55 size_type size;
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 {
73 b64txt txt;
74 b64data data;
75 };
76
79} // namespace Dune
80
81#endif // DUNE_GRID_IO_FILE_VTK_B64ENC_HH
Dune namespace.
Definition: alignedallocator.hh:10
const char base64table[]
endoing table
Definition: b64enc.hh:21
Definition: b64enc.hh:53
struct with three bytes of text
Definition: b64enc.hh:32
union representing the three byte text as well as the four 6 bit chunks
Definition: b64enc.hh:72
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)