OpenLB 1.7
Loading...
Searching...
No Matches
base64.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2007 Jonas Latt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24/* Acknowledgment: The strategy adopted here to encode
25 * and decode Base64, and in particular the expression of the
26 * arrays Base64Encoder::enc64 and Base64Decoder::dec64,
27 * is inspired by the open source library b64 by Bob Trower,
28 * which is distributed with a MIT license at the address
29 * http://base64.sourceforge.net/b64.c
30 */
31
32
33#ifndef BASE64_H
34#define BASE64_H
35
36#include <iosfwd>
37
38namespace olb {
39
40template<typename T>
42public:
43 Base64Encoder(std::ostream& ostr_, size_t fullLength_);
44 void encode(const T* data, size_t length);
45private:
46 void fillOverflow(const unsigned char* charData, size_t charLength, size_t& pos);
47 void flushOverflow();
48 void writeSize();
49 void encodeBlock( const unsigned char* data);
50 void encodeUnfinishedBlock( const unsigned char* data, int length);
51private:
52 static const char enc64[65];
53private:
54 std::ostream& ostr;
55 size_t charFullLength;
56 size_t numWritten;
57 int numOverflow;
58 unsigned char overflow[3];
59};
60
61template<typename T>
63public:
64 Base64Decoder(std::istream& istr_, size_t fullLength_);
65 void decode(T* data, size_t length);
66private:
67 void flushOverflow(unsigned char* charData, size_t charLength, size_t& pos);
68 unsigned char getNext();
69 void decodeBlock(unsigned char* data);
70private:
71 static const char dec64[82];
72private:
73 std::istream& istr;
74 size_t charFullLength;
75 size_t numRead;
76 int posOverflow;
77 unsigned char overflow[3];
78};
79
80} // namespace olb
81
82#endif
Base64Decoder(std::istream &istr_, size_t fullLength_)
Definition base64.hh:137
void decode(T *data, size_t length)
Definition base64.hh:145
Base64Encoder(std::ostream &ostr_, size_t fullLength_)
Definition base64.hh:51
void encode(const T *data, size_t length)
Definition base64.hh:59
Top level namespace for all of OpenLB.