|
|
|
OSHA1stream.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 Foam::OSHA1stream 00027 00028 Description 00029 An output stream for calculating SHA1 digests. 00030 00031 SourceFiles 00032 OSHA1stream.C 00033 00034 \*---------------------------------------------------------------------------*/ 00035 00036 #ifndef OSHA1stream_H 00037 #define OSHA1stream_H 00038 00039 #include "OSstream.H" 00040 #include "SHA1.H" 00041 00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00043 00044 namespace Foam 00045 { 00046 00047 class osha1stream; 00048 class OSHA1stream; 00049 00050 /*---------------------------------------------------------------------------*\ 00051 Class sha1streambuf Declaration 00052 \*---------------------------------------------------------------------------*/ 00053 00054 //- A streambuf class for calculating SHA1 digests 00055 class sha1streambuf 00056 : 00057 public std::streambuf 00058 { 00059 // Private data 00060 00061 //- This does all the work and has its own buffering 00062 SHA1 sha1_; 00063 00064 friend class osha1stream; 00065 00066 public: 00067 00068 // Constructors 00069 00070 //- Construct null 00071 sha1streambuf() 00072 {} 00073 00074 // Member Functions 00075 00076 // Write 00077 00078 //- Process unbuffered 00079 virtual std::streamsize xsputn(const char* str, std::streamsize n) 00080 { 00081 sha1_.append(str, n); 00082 return n; 00083 } 00084 }; 00085 00086 00087 /*---------------------------------------------------------------------------*\ 00088 Class osha1stream Declaration 00089 \*---------------------------------------------------------------------------*/ 00090 00091 //- A basic output stream for calculating SHA1 digests 00092 class osha1stream 00093 : 00094 virtual public std::ios, 00095 public std::ostream 00096 { 00097 // Private data 00098 00099 sha1streambuf sbuf_; 00100 00101 public: 00102 00103 // Constructors 00104 00105 //- Construct null 00106 osha1stream() 00107 : 00108 std::ostream(&sbuf_) 00109 {} 00110 00111 // Member Functions 00112 00113 // Access 00114 00115 //- This hides both signatures of std::basic_ios::rdbuf() 00116 sha1streambuf* rdbuf() 00117 { 00118 return &sbuf_; 00119 } 00120 00121 //- Full access to the sha1 00122 SHA1& sha1() 00123 { 00124 return sbuf_.sha1_; 00125 } 00126 00127 }; 00128 00129 00130 /*---------------------------------------------------------------------------*\ 00131 Class OSHA1stream Declaration 00132 \*---------------------------------------------------------------------------*/ 00133 00134 //- The output stream for calculating SHA1 digests 00135 class OSHA1stream 00136 : 00137 public OSstream 00138 { 00139 00140 // Private Member Functions 00141 00142 //- Disallow default bitwise copy construct 00143 OSHA1stream(const OSHA1stream&); 00144 00145 //- Disallow default bitwise assignment 00146 void operator=(const OSHA1stream&); 00147 00148 public: 00149 00150 // Constructors 00151 00152 //- Construct and set stream status 00153 OSHA1stream 00154 ( 00155 streamFormat format=ASCII, 00156 versionNumber version=currentVersion 00157 ) 00158 : 00159 OSstream 00160 ( 00161 *(new osha1stream), 00162 "OSHA1stream.sinkFile_", 00163 format, 00164 version 00165 ) 00166 {} 00167 00168 00169 // Destructor 00170 00171 ~OSHA1stream() 00172 { 00173 delete &dynamic_cast<osha1stream&>(stream()); 00174 } 00175 00176 00177 // Member functions 00178 00179 // Access 00180 00181 //- Full access to the sha1 00182 Foam::SHA1& sha1() 00183 { 00184 return dynamic_cast<osha1stream&>(stream()).sha1(); 00185 } 00186 00187 //- Return SHA1::Digest for the data processed until now 00188 Foam::SHA1Digest digest() 00189 { 00190 return sha1().digest(); 00191 } 00192 00193 // Edit 00194 00195 //- Clear the SHA1 calculation 00196 void rewind() 00197 { 00198 sha1().clear(); 00199 } 00200 00201 }; 00202 00203 00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00205 00206 } // End namespace Foam 00207 00208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00209 00210 #endif 00211 00212 // ************************************************************************* // |