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 -------------------------------------------------------------------------------
10 License
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 
26 Class
27  Foam::base64Layer
28 
29 Description
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 
37 SourceFiles
38  base64Layer.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef base64Layer_H
43 #define base64Layer_H
44 
45 #include <iostream>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class base64Layer Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class 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;
76  inline unsigned char encode1() const;
77  inline unsigned char encode2() const;
78  inline unsigned char encode3() const;
79 
80  //- No copy construct
81  base64Layer(const base64Layer&) = delete;
82 
83  //- No copy assignment
84  void operator=(const base64Layer&) = delete;
85 
86 
87 protected:
88 
89  // Protected Member Functions
90 
91  //- Add a character to the group, outputting when the group is full.
92  void add(char c);
93 
94 
95 public:
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 // ************************************************************************* //
s
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))
Definition: gmvOutputSpray.H:25
Foam::base64Layer::~base64Layer
~base64Layer()
Destructor. Performs close()
Definition: base64Layer.C:116
Foam::base64Layer::close
bool close()
End the encoding sequence, padding the final characters with '='.
Definition: base64Layer.C:140
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::base64Layer::write
void write(const char *s, std::streamsize n)
Encode the character sequence, writing when possible.
Definition: base64Layer.C:124
Foam::base64Layer::reset
void reset()
Restart a new encoding sequence.
Definition: base64Layer.C:133
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::base64Layer::add
void add(char c)
Add a character to the group, outputting when the group is full.
Definition: base64Layer.C:83
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::base64Layer
An output filter layer to write base-64 encoded content.
Definition: base64Layer.H:55
Foam::base64Layer::encodedLength
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