Loading...
Searching...
No Matches
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-2025 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{
52/*---------------------------------------------------------------------------*\
53 Class base64Layer Declaration
54\*---------------------------------------------------------------------------*/
55
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
70 // Private Member Functions
71
72 inline unsigned char encode0() const noexcept;
73 inline unsigned char encode1() const noexcept;
74 inline unsigned char encode2() const noexcept;
75 inline unsigned char encode3() const noexcept;
76
77 //- Add a character to the group, outputting when the group is full.
78 inline void add_char(char c);
79
80protected:
81
82 // Protected Member Functions
83
84 //- Add a character to the group, outputting when the group is full.
85 void add(char c);
86
87public:
88
89 // Constructors
90
91 //- Attach to an output stream
92 explicit base64Layer(std::ostream& os) noexcept;
93
94 //- No copy construct
95 base64Layer(const base64Layer&) = delete;
96
97 //- No copy assignment
98 void operator=(const base64Layer&) = delete;
99
100
101 //- Destructor. Performs close()
102 ~base64Layer();
103
105 // Static Functions
106
107 //- The encoded length has 4 bytes out for every 3 bytes and
108 //- any trailing bytes are padded with '='.
109 //
110 // The output length is (4*ceil(len / 3.0))
111 static constexpr std::size_t encodedLength(std::size_t len) noexcept
112 {
113 return (4*((len+2)/3));
114 }
115
116
117 // Member Functions
118
119 //- Encode the character sequence, writing when possible.
120 void write(const char* s, std::streamsize n);
121
122 //- Restart a new encoding sequence.
123 void reset() noexcept;
124
125 //- End the encoding sequence, padding the final characters with '='.
126 // \return false if no encoding was actually performed.
127 bool close();
128};
129
130
131// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132
133} // End namespace Foam
134
135// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136
137#endif
138
139// ************************************************************************* //
label n
void reset() noexcept
Restart a new encoding sequence.
void add(char c)
Add a character to the group, outputting when the group is full.
Definition base64Layer.C:91
bool close()
End the encoding sequence, padding the final characters with '='.
void operator=(const base64Layer &)=delete
No copy assignment.
base64Layer(const base64Layer &)=delete
No copy construct.
base64Layer(std::ostream &os) noexcept
Attach to an output stream.
Definition base64Layer.C:99
static constexpr std::size_t encodedLength(std::size_t len) noexcept
The encoded length has 4 bytes out for every 3 bytes and any trailing bytes are padded with '='.
~base64Layer()
Destructor. Performs close().
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.
const direction noexcept
Definition scalarImpl.H:265
runTime write()