base64Layer.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::base64Layer
28
29Description
30 An output filter layer to write base-64 encoded content.
31
32 Base64 encoding according to RFC 4648 specification
33 (https://tools.ietf.org/html/rfc4648#page-5).
34 It is the obligation of the caller to avoid using normal output
35 while the base-64 encoding layer is actively used.
36
37SourceFiles
38 base64Layer.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_base64Layer_H
43#define Foam_base64Layer_H
44
45#include <iostream>
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51
52/*---------------------------------------------------------------------------*\
53 Class base64Layer Declaration
54\*---------------------------------------------------------------------------*/
56class base64Layer
57{
58 // Private Data
59
60 //- The output stream for the layer
61 std::ostream& os_;
62
63 //- Buffer of characters to encode
64 unsigned char group_[3];
65
66 //- Current length of the encode buffer
67 unsigned char groupLen_;
68
69 //- Track if anything has been encoded.
70 bool dirty_;
71
72
73 // Private Member Functions
74
75 inline unsigned char encode0() const noexcept;
76 inline unsigned char encode1() const noexcept;
77 inline unsigned char encode2() const noexcept;
78 inline unsigned char encode3() const noexcept;
79
80
81protected:
82
83 // Protected Member Functions
84
85 //- Add a character to the group, outputting when the group is full.
86 void add(char c);
87
88 //- No copy construct
89 base64Layer(const base64Layer&) = delete;
90
91 //- No copy assignment
92 void operator=(const base64Layer&) = delete;
93
94
95public:
96
97 // Constructors
98
99 //- Construct and attach to an output stream
100 explicit base64Layer(std::ostream& os);
101
102
103 //- Destructor. Performs close()
104 ~base64Layer();
105
106
107 // Member Functions
108
109 //- The encoded length has 4 bytes out for every 3 bytes in.
110 static std::size_t encodedLength(std::size_t n);
111
112
113 //- Encode the character sequence, writing when possible.
114 void write(const char* s, std::streamsize n);
115
116 //- Restart a new encoding sequence.
117 void reset();
118
119 //- End the encoding sequence, padding the final characters with '='.
120 // \return false if no encoding was actually performed.
121 bool close();
122};
123
124
125// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126
127} // End namespace Foam
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131#endif
132
133// ************************************************************************* //
label n
An output filter layer to write base-64 encoded content.
Definition: base64Layer.H:56
void add(char c)
Add a character to the group, outputting when the group is full.
Definition: base64Layer.C:83
bool close()
End the encoding sequence, padding the final characters with '='.
Definition: base64Layer.C:140
void operator=(const base64Layer &)=delete
No copy assignment.
base64Layer(const base64Layer &)=delete
No copy construct.
~base64Layer()
Destructor. Performs close()
Definition: base64Layer.C:116
static std::size_t encodedLength(std::size_t n)
The encoded length has 4 bytes out for every 3 bytes in.
Definition: base64Layer.C:50
void reset()
Restart a new encoding sequence.
Definition: base64Layer.C:133
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
runTime write()