Loading...
Searching...
No Matches
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-2024 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 "SHA1.H"
39#include "OSstream.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 : public std::streambuf
58 {
59 //- This does all the work and has its own buffering
60 SHA1 sha1_;
61
62 protected:
63
64 //- Output overflow handling - append to SHA1
65 virtual int overflow(int_type c = traits_type::eof())
66 {
67 if (c != traits_type::eof()) sha1_.append(c);
68 return c;
69 }
70
71 //- Put sequence of characters - append to SHA1
72 virtual std::streamsize xsputn(const char* s, std::streamsize n)
73 {
74 if (n) sha1_.append(s, n);
75 return n;
76 }
77
78 public:
79
80 //- Default construct
81 sha1buf() = default;
82
83 //- Full access to the sha1
84 SHA1& sha1() noexcept { return sha1_; }
85 };
86
87
88 // Private Data
89
90 //- Reference to the underlying buffer
91 sha1buf buf_;
92
93public:
94
95 // Constructors
96
97 //- Default construct
98 osha1stream() : std::ostream(&buf_) {}
99
100
101 // Member Functions
102
103 //- This hides both signatures of std::basic_ios::rdbuf()
104 sha1buf* rdbuf() { return &buf_; }
105
106 //- Full access to the sha1
107 SHA1& sha1() noexcept { return buf_.sha1(); }
108
109 //- Return SHA1::Digest for the data processed until now
110 SHA1Digest digest() { return buf_.sha1().digest(); }
111
112 //- Clear the SHA1 calculation
113 void reset() { buf_.sha1().clear(); }
114};
115
116
117/*---------------------------------------------------------------------------*\
118 Class OSHA1stream Declaration
119\*---------------------------------------------------------------------------*/
120
121//- The output stream for calculating SHA1 digests
123:
124 public Foam::Detail::StreamAllocator<Foam::osha1stream>,
125 public Foam::OSstream
126{
127 typedef
129 allocator_type;
130
131public:
133 //- No copy construct
134 OSHA1stream(const OSHA1stream&) = delete;
135
136 //- No copy assignment
137 void operator=(const OSHA1stream&) = delete;
138
139
140 // Constructors
141
142 //- Construct with an empty digest
143 explicit OSHA1stream
144 (
145 IOstreamOption streamOpt = IOstreamOption()
146 )
147 :
148 allocator_type(),
149 OSstream(stream_, "sha1", streamOpt.format(), streamOpt.version())
150 {}
151
152
153 // Member Functions
154
155 //- Full access to the sha1
156 SHA1& sha1() noexcept { return stream_.sha1(); }
158 //- Return SHA1::Digest for the data processed until now
159 SHA1Digest digest() { return stream_.digest(); }
160
161 //- Clear the SHA1 calculation
162 void reset() { stream_.reset(); }
163
164
165 // Write Functions
166
167 //- Add (unquoted) string contents.
168 // Ensures that SHA1 of C-string or C++-string content are identical.
169 virtual Ostream& write(const std::string& s) override
171 return writeQuoted(s.data(), s.size(), false); // Unquoted!
172 }
173
174
175 // Housekeeping
176
177 //- Deprecated(2017-07) clear the SHA1 calculation
178 // \deprecated(2017-07) - use reset() method
179 void rewind() { stream_.reset(); }
180
181
182 // Additional constructors and methods (as per v2012 and earlier)
183 #ifdef Foam_IOstream_extras
184
185 //- Construct with an empty digest, using given format
187 :
189 {}
191 #endif /* Foam_IOstream_extras */
192};
193
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197} // End namespace Foam
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#endif
202
203// ************************************************************************* //
label n
A wrapper to hold a std::stream type for OpenFOAM wrapped streams. This is necessary since the OpenFO...
Definition IOstream.H:620
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
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression.
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary | coherent).
The output stream for calculating SHA1 digests.
OSHA1stream(const OSHA1stream &)=delete
No copy construct.
virtual Ostream & write(const std::string &s) override
Add (unquoted) string contents.
SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
OSHA1stream(IOstreamOption streamOpt=IOstreamOption())
Construct with an empty digest.
void rewind()
Deprecated(2017-07) clear the SHA1 calculation.
void reset()
Clear the SHA1 calculation.
SHA1 & sha1() noexcept
Full access to the sha1.
void operator=(const OSHA1stream &)=delete
No copy assignment.
Generic output stream using a standard (STL) stream.
Definition OSstream.H:53
OSstream(const OSstream &)=default
Copy construct.
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
Definition OSstream.C:101
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
The SHA1 message digest.
Definition SHA1Digest.H:58
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition SHA1.H:57
void clear() noexcept
Reset the hashed data before appending more.
Definition SHA1.C:314
void append(char c)
Append single character.
Definition SHA1I.H:46
SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
osha1stream()
Default construct.
sha1buf * rdbuf()
This hides both signatures of std::basic_ios::rdbuf().
void reset()
Clear the SHA1 calculation.
SHA1 & sha1() noexcept
Full access to the sha1.
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()