Dune Core Modules (2.7.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 b64chunk
32 {
33 using size_type = unsigned char;
34 size_type size;
35 char txt[3];
36
37 void reset()
38 {
39 size = 0;
40 txt[0] = txt[1] = txt[2] = 0;
41 }
42
43 int read(const char* t, size_type s)
44 {
45 size = s>=3 ? 3 : s;
46 txt[0] = s>0 ? t[0] : 0;
47 txt[1] = s>1 ? t[1] : 0;
48 txt[2] = s>2 ? t[2] : 0;
49 return size;
50 }
51
52 void put(const char c)
53 {
54 assert (size < 3);
55 txt[size++] = c;
56 }
57
58 void write(char* t)
59 {
60 const unsigned A = (txt[0] & 0b1111'1100) >> 2;
61 const unsigned B = (txt[0] & 0b0000'0011) << 4 | (txt[1] & 0b1111'0000) >> 4;
62 const unsigned C = (txt[1] & 0b0000'1111) << 2 | (txt[2] & 0b1100'0000) >> 6;
63 const unsigned D = txt[2] & 0b0011'1111;
64 t[0] = size>0 ? base64table[A] : '=';
65 t[1] = size>0 ? base64table[B] : '=';
66 t[2] = size>1 ? base64table[C] : '=';
67 t[3] = size>2 ? base64table[D] : '=';
68 size = 0;
69 }
70 };
71
74} // namespace Dune
75
76#endif // DUNE_GRID_IO_FILE_VTK_B64ENC_HH
Dune namespace.
Definition: alignedallocator.hh:14
const char base64table[]
endoing table
Definition: b64enc.hh:21
struct representing the three byte text as well as the four 6 bit chunks
Definition: b64enc.hh:32
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)