OSHA1stream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::OSHA1stream
26 
27 Description
28  A Foam::OSstream for calculating SHA-1 digests
29 
30 SourceFiles
31  OSHA1stream.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef OSHA1stream_H
36 #define OSHA1stream_H
37 
38 #include "OSstream.H"
39 #include "SHA1.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class sha1streambuf Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class sha1streambuf
51 :
52  public std::streambuf
53 {
54  // Private Data
55 
56  //- The SHA-1 class which processes the strings
57  SHA1 sha1_;
58 
59 
60 public:
61 
62  // Constructors
63 
64  //- Construct null
66  {}
67 
68 
69  // Member Functions
70 
71  //- Return the SHA-1
72  SHA1& sha1()
73  {
74  return sha1_;
75  }
76 
77  //- Writes characters from the array pointed to by s
78  // into the controlled output sequence, until either n characters
79  // have been written or the end of the output sequence is reached
80  virtual std::streamsize xsputn(const char* s, std::streamsize n)
81  {
82  sha1_.append(s, n);
83  return n;
84  }
85 
86  //- Writes c to the current position of the put pointer (pptr),
87  // and advances that pointer one position forward.
88  // If c is EOF, no characters are written and the put pointer
89  // (pptr) is not advanced.
90  // Maybe used by xsputn (C++11).
91  virtual int overflow(int c = EOF)
92  {
93  if (c != EOF)
94  {
95  const char cc = c;
96  sha1_.append(&cc, 1);
97  }
98 
99  return c;
100  }
101 };
102 
103 
104 /*---------------------------------------------------------------------------*\
105  Class osha1stream Declaration
106 \*---------------------------------------------------------------------------*/
107 
108 class osha1stream
109 :
110  virtual public std::ios,
111  public std::ostream
112 {
113  // Private Data
114 
115  // SHA-1 stream buffer
116  sha1streambuf sbuf_;
117 
118 
119 public:
120 
121  // Constructors
122 
123  //- Construct null
124  osha1stream()
125  :
126  std::ostream(&sbuf_)
127  {}
128 
129 
130  // Member Functions
131 
132  //- Return the SHA-1
133  SHA1& sha1()
134  {
135  return sbuf_.sha1();
136  }
137 
138  //- Return the stream buffer
140  {
141  return &sbuf_;
142  }
143 };
144 
145 
146 /*---------------------------------------------------------------------------*\
147  Class OSHA1stream Declaration
148 \*---------------------------------------------------------------------------*/
149 
150 class OSHA1stream
151 :
152  public OSstream
153 {
154 
155 public:
156 
157  // Constructors
158 
159  //- Construct and set stream status
161  (
164  )
165  :
166  OSstream
167  (
168  *(new osha1stream),
169  "OSHA1stream.sinkFile_",
170  format,
171  version
172  )
173  {}
174 
175  //- Disallow default bitwise copy construction
176  OSHA1stream(const OSHA1stream&) = delete;
177 
178 
179  //- Destructor
180  ~OSHA1stream()
181  {
182  delete &dynamic_cast<osha1stream&>(stdStream());
183  }
184 
185 
186  // Member Functions
187 
188  //- Return the SHA-1
189  SHA1& sha1()
190  {
191  return dynamic_cast<osha1stream&>(stdStream()).sha1();
192  }
193 
194  //- Return the SHA-1 digest for the data processed until now
196  {
197  return sha1().digest();
198  }
199 
200  //- Clear the SHA1 calculation
201  void rewind()
202  {
203  sha1().clear();
204  }
205 
206 
207  // Member Operators
208 
209  //- Disallow default bitwise assignment
210  void operator=(const OSHA1stream&) = delete;
211 };
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
label n
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
A Foam::OSstream for calculating SHA-1 digests.
Definition: OSHA1stream.H:152
OSHA1stream(streamFormat format=ASCII, versionNumber version=currentVersion)
Construct and set stream status.
Definition: OSHA1stream.H:160
SHA1Digest digest()
Return the SHA-1 digest for the data processed until now.
Definition: OSHA1stream.H:194
~OSHA1stream()
Destructor.
Definition: OSHA1stream.H:179
void rewind()
Clear the SHA1 calculation.
Definition: OSHA1stream.H:200
SHA1 & sha1()
Return the SHA-1.
Definition: OSHA1stream.H:188
void operator=(const OSHA1stream &)=delete
Disallow default bitwise assignment.
Generic output stream.
Definition: OSstream.H:54
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:180
The SHA1 message digest.
Definition: SHA1Digest.H:63
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:69
SHA1 & append(const char *data, size_t len)
Append data for processing.
Definition: SHA1I.H:53
void clear()
Reset the hashed data before appending more.
Definition: SHA1.C:339
SHA1Digest digest() const
Calculate current digest from appended data.
Definition: SHA1.C:393
sha1streambuf * rdbuf()
Return the stream buffer.
Definition: OSHA1stream.H:138
osha1stream()
Construct null.
Definition: OSHA1stream.H:123
SHA1 & sha1()
Return the SHA-1.
Definition: OSHA1stream.H:132
sha1streambuf()
Construct null.
Definition: OSHA1stream.H:64
virtual int overflow(int c=EOF)
Writes c to the current position of the put pointer (pptr),.
Definition: OSHA1stream.H:90
SHA1 & sha1()
Return the SHA-1.
Definition: OSHA1stream.H:71
virtual std::streamsize xsputn(const char *s, std::streamsize n)
Writes characters from the array pointed to by s.
Definition: OSHA1stream.H:79
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.