Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / OpenFOAM / db / IOstreams / hashes / OSHA1stream.H
blob18104873b16ce350944db6873e9ff9057a6017b5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::OSHA1stream
28 Description
29     An output stream for calculating SHA1 digests.
31 SourceFiles
32     OSHA1stream.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef OSHA1stream_H
37 #define OSHA1stream_H
39 #include <OpenFOAM/OSstream.H>
40 #include <OpenFOAM/SHA1.H>
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 class osha1stream;
48 class OSHA1stream;
50 /*---------------------------------------------------------------------------*\
51                         Class sha1streambuf Declaration
52 \*---------------------------------------------------------------------------*/
54 //- A streambuf class for calculating SHA1 digests
55 class sha1streambuf
57     public std::streambuf
59     // Private data
61     //- This does all the work and has its own buffering
62     SHA1 sha1_;
64     friend class osha1stream;
66 public:
68     // Constructors
70         //- Construct null
71         sha1streambuf()
72         {}
74     // Member Functions
76     // Write
78         //- Process unbuffered
79         virtual std::streamsize xsputn(const char* str, std::streamsize n)
80         {
81             sha1_.append(str, n);
82             return n;
83         }
87 /*---------------------------------------------------------------------------*\
88                          Class osha1stream Declaration
89 \*---------------------------------------------------------------------------*/
91 //- A basic output stream for calculating SHA1 digests
92 class osha1stream
94     virtual public std::ios,
95     public std::ostream
97     // Private data
99     sha1streambuf sbuf_;
101 public:
103     // Constructors
105         //- Construct null
106         osha1stream()
107         :
108             std::ostream(&sbuf_)
109         {}
111     // Member Functions
113     // Access
115         //- This hides both signatures of std::basic_ios::rdbuf()
116         sha1streambuf* rdbuf()
117         {
118             return &sbuf_;
119         }
121         //- Full access to the sha1
122         SHA1& sha1()
123         {
124             return sbuf_.sha1_;
125         }
130 /*---------------------------------------------------------------------------*\
131                          Class OSHA1stream Declaration
132 \*---------------------------------------------------------------------------*/
134 //- The output stream for calculating SHA1 digests
135 class OSHA1stream
137     public OSstream
140     // Private Member Functions
142         //- Disallow default bitwise copy construct
143         OSHA1stream(const OSHA1stream&);
145         //- Disallow default bitwise assignment
146         void operator=(const OSHA1stream&);
148 public:
150     // Constructors
152         //- Construct and set stream status
153         OSHA1stream
154         (
155             streamFormat format=ASCII,
156             versionNumber version=currentVersion
157         )
158         :
159             OSstream
160             (
161                 *(new osha1stream),
162                 "OSHA1stream.sinkFile_",
163                 format,
164                 version
165             )
166         {}
169     // Destructor
171         ~OSHA1stream()
172         {
173             delete &dynamic_cast<osha1stream&>(stream());
174         }
177     // Member functions
179     // Access
181         //- Full access to the sha1
182         Foam::SHA1& sha1()
183         {
184             return dynamic_cast<osha1stream&>(stream()).sha1();
185         }
187         //- Return SHA1::Digest for the data processed until now
188         Foam::SHA1Digest digest()
189         {
190             return sha1().digest();
191         }
193     // Edit
195         //- Clear the SHA1 calculation
196         void rewind()
197         {
198             sha1().clear();
199         }
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 } // End namespace Foam
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 #endif
212 // ************************ vim: set sw=4 sts=4 et: ************************ //