OSHA1stream.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) 2011 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::OSHA1stream
29
30Description
31 An output stream for calculating SHA1 digests.
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef Foam_OSHA1stream_H
36#define Foam_OSHA1stream_H
37
38#include "OSstream.H"
39#include "SHA1.H"
40
41// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42
43namespace Foam
44{
45
46/*---------------------------------------------------------------------------*\
47 Class osha1stream Declaration
48\*---------------------------------------------------------------------------*/
49
50//- A basic output stream for calculating SHA1 digests
51class osha1stream
52:
53 virtual public std::ios,
54 public std::ostream
55{
56 //- A streambuf class for calculating SHA1 digests
57 class sha1buf
58 :
59 public std::streambuf
60 {
61 //- This does all the work and has its own buffering
62 SHA1 sha1_;
63
64 protected:
65
66 //- Handle overflow
67 virtual int overflow(int c = EOF)
68 {
69 if (c != EOF) sha1_.append(c);
70 return c;
71 }
72
73 //- Put sequence of characters
74 virtual std::streamsize xsputn(const char* s, std::streamsize n)
75 {
76 if (n) sha1_.append(s, n);
77 return n;
78 }
79
80 public:
81
82 //- Default construct
83 sha1buf() = default;
84
85 //- Full access to the sha1
86 SHA1& sha1() noexcept
87 {
88 return sha1_;
89 }
90 };
91
92
93 // Private Data
94
95 //- Reference to the underlying buffer
96 sha1buf buf_;
97
98public:
99
100 // Constructors
101
102 //- Default construct
104 :
105 std::ostream(&buf_)
106 {}
107
108
109 // Member Functions
110
111 //- This hides both signatures of std::basic_ios::rdbuf()
112 sha1buf* rdbuf()
113 {
114 return &buf_;
115 }
116
117 //- Full access to the sha1
119 {
120 return buf_.sha1();
121 }
122};
123
124
125namespace Detail
126{
127
128/*---------------------------------------------------------------------------*\
129 Class Detail::OSHA1streamAllocator Declaration
130\*---------------------------------------------------------------------------*/
131
132//- Allocator for an osha1stream
134{
135protected:
136
137 // Protected Data
139 typedef osha1stream stream_type;
140
141 //- The output stream
143
144
145 // Constructors
146
147 //- Default construct
148 OSHA1streamAllocator() = default;
149
150
151public:
152
153 // Member Functions
154
155 //- Full access to the sha1
157 {
158 return stream_.sha1();
159 }
160
161
162 //- Return SHA1::Digest for the data processed until now
164 {
165 return stream_.sha1().digest();
166 }
167
168
169 //- Clear the SHA1 calculation
170 void reset()
171 {
172 return stream_.sha1().clear();
173 }
174};
175
176} // End namespace Detail
177
178
179/*---------------------------------------------------------------------------*\
180 Class OSHA1stream Declaration
181\*---------------------------------------------------------------------------*/
182
183//- The output stream for calculating SHA1 digests
184class OSHA1stream
185:
187 public OSstream
188{
190
191 // Private Member Functions
192
193 //- No copy construct
194 OSHA1stream(const OSHA1stream&) = delete;
195
196 //- No copy assignment
197 void operator=(const OSHA1stream&) = delete;
198
199public:
200
201 // Constructors
202
203 //- Construct with an empty digest
204 explicit OSHA1stream
205 (
206 IOstreamOption streamOpt = IOstreamOption()
207 )
208 :
210 OSstream(stream_, "sha1", streamOpt.format(), streamOpt.version())
211 {}
212
213
214 // Write Functions
215
216 //- Add (unquoted) string contents.
217 // Ensures that SHA1 of C-string or C++-string content are identical.
218 virtual Ostream& write(const string& str)
219 {
220 return writeQuoted(str, false); // Unquoted!
221 }
222
223
224 // Housekeeping
225
226 //- Deprecated(2017-07) clear the SHA1 calculation
227 // \deprecated(2017-07) - use reset() method
228 void rewind()
229 {
230 sha1().clear();
231 }
232
233
234 // Additional constructors and methods (as per v2012 and earlier)
235 #ifdef Foam_IOstream_extras
236
237 //- Construct empty
238 explicit OSHA1stream
239 (
242 )
243 :
244 OSHA1stream(IOstreamOption(fmt, ver))
245 {}
246
247 #endif /* Foam_IOstream_extras */
248};
249
250
251// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252
253} // End namespace Foam
254
255// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256
257#endif
258
259// ************************************************************************* //
label n
Allocator for an osha1stream.
Definition: OSHA1stream.H:133
OSHA1streamAllocator()=default
Default construct.
SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:162
void reset()
Clear the SHA1 calculation.
Definition: OSHA1stream.H:169
SHA1 & sha1() noexcept
Full access to the sha1.
Definition: OSHA1stream.H:155
stream_type stream_
The output stream.
Definition: OSHA1stream.H:141
Representation of a major/minor version number.
The IOstreamOption is a simple container for options an IOstream can normally have.
versionNumber version() const noexcept
Get the stream version.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary)
static const versionNumber currentVersion
The current version number (2.0)
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:187
OSHA1stream(IOstreamOption streamOpt=IOstreamOption())
Construct with an empty digest.
Definition: OSHA1stream.H:204
void rewind()
Deprecated(2017-07) clear the SHA1 calculation.
Definition: OSHA1stream.H:227
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:57
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:119
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
The SHA1 message digest.
Definition: SHA1Digest.H:61
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:61
void clear() noexcept
Reset the hashed data before appending more.
Definition: SHA1.C:315
void append(char c)
Append single character.
Definition: SHA1I.H:53
SHA1Digest digest() const
Calculate digest from current data.
Definition: SHA1I.H:99
A basic output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:54
osha1stream()
Default construct.
Definition: OSHA1stream.H:102
sha1buf * rdbuf()
This hides both signatures of std::basic_ios::rdbuf()
Definition: OSHA1stream.H:111
SHA1 & sha1() noexcept
Full access to the sha1.
Definition: OSHA1stream.H:117
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: Scalar.H:223
runTime write()