00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::OSHA1stream 00026 00027 Description 00028 An output stream for calculating SHA1 digests. 00029 00030 SourceFiles 00031 OSHA1stream.C 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef OSHA1stream_H 00036 #define OSHA1stream_H 00037 00038 #include <OpenFOAM/OSstream.H> 00039 #include <OpenFOAM/SHA1.H> 00040 00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00042 00043 namespace Foam 00044 { 00045 00046 class osha1stream; 00047 class OSHA1stream; 00048 00049 /*---------------------------------------------------------------------------*\ 00050 Class sha1streambuf Declaration 00051 \*---------------------------------------------------------------------------*/ 00052 00053 //- A streambuf class for calculating SHA1 digests 00054 class sha1streambuf 00055 : 00056 public std::streambuf 00057 { 00058 // Private data 00059 00060 //- This does all the work and has its own buffering 00061 SHA1 sha1_; 00062 00063 friend class osha1stream; 00064 00065 public: 00066 00067 // Constructors 00068 00069 //- Construct null 00070 sha1streambuf() 00071 {} 00072 00073 // Member Functions 00074 00075 // Write 00076 00077 //- Process unbuffered 00078 virtual std::streamsize xsputn(const char* str, std::streamsize n) 00079 { 00080 sha1_.append(str, n); 00081 return n; 00082 } 00083 }; 00084 00085 00086 /*---------------------------------------------------------------------------*\ 00087 Class osha1stream Declaration 00088 \*---------------------------------------------------------------------------*/ 00089 00090 //- A basic output stream for calculating SHA1 digests 00091 class osha1stream 00092 : 00093 virtual public std::ios, 00094 public std::ostream 00095 { 00096 // Private data 00097 00098 sha1streambuf sbuf_; 00099 00100 public: 00101 00102 // Constructors 00103 00104 //- Construct null 00105 osha1stream() 00106 : 00107 std::ostream(&sbuf_) 00108 {} 00109 00110 // Member Functions 00111 00112 // Access 00113 00114 //- This hides both signatures of std::basic_ios::rdbuf() 00115 sha1streambuf* rdbuf() 00116 { 00117 return &sbuf_; 00118 } 00119 00120 //- Full access to the sha1 00121 SHA1& sha1() 00122 { 00123 return sbuf_.sha1_; 00124 } 00125 00126 }; 00127 00128 00129 /*---------------------------------------------------------------------------*\ 00130 Class OSHA1stream Declaration 00131 \*---------------------------------------------------------------------------*/ 00132 00133 //- The output stream for calculating SHA1 digests 00134 class OSHA1stream 00135 : 00136 public OSstream 00137 { 00138 00139 // Private Member Functions 00140 00141 //- Disallow default bitwise copy construct 00142 OSHA1stream(const OSHA1stream&); 00143 00144 //- Disallow default bitwise assignment 00145 void operator=(const OSHA1stream&); 00146 00147 public: 00148 00149 // Constructors 00150 00151 //- Construct and set stream status 00152 OSHA1stream 00153 ( 00154 streamFormat format=ASCII, 00155 versionNumber version=currentVersion 00156 ) 00157 : 00158 OSstream 00159 ( 00160 *(new osha1stream), 00161 "OSHA1stream.sinkFile_", 00162 format, 00163 version 00164 ) 00165 {} 00166 00167 00168 // Destructor 00169 00170 ~OSHA1stream() 00171 { 00172 delete &dynamic_cast<osha1stream&>(stream()); 00173 } 00174 00175 00176 // Member functions 00177 00178 // Access 00179 00180 //- Full access to the sha1 00181 Foam::SHA1& sha1() 00182 { 00183 return dynamic_cast<osha1stream&>(stream()).sha1(); 00184 } 00185 00186 //- Return SHA1::Digest for the data processed until now 00187 Foam::SHA1Digest digest() 00188 { 00189 return sha1().digest(); 00190 } 00191 00192 // Edit 00193 00194 //- Clear the SHA1 calculation 00195 void rewind() 00196 { 00197 sha1().clear(); 00198 } 00199 00200 }; 00201 00202 00203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00204 00205 } // End namespace Foam 00206 00207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00208 00209 #endif 00210 00211 // ************************ vim: set sw=4 sts=4 et: ************************ //