Files Classes Functions Hierarchy
#include <streamconversion.h>
Public Member Functions | |
| void | forward (string const &in) |
| Read the string into vi as blocks. | |
| void | reverse (string &os) |
| Write the blocks in vi out as a continuous string. | |
| void | save (ostream &os) const |
| Save this objects state. | |
| void | restore (istream &in) |
| Restore this object to the former state. | |
| template<typename T > | |
| void | eval (T &fn) |
| Apply a function to vi[i]. | |
Public Attributes | |
| uint | blksz |
| Block size. | |
| vector< string > | vi |
| A string of blocks. | |
This last string is padded with 0's. This operation is reversible and support for stream writing is included so the string can be written and read from a stream.
The class is designed to process the data as a block of strings. Strings are superior to streams for many reasons, mainly simplicity and reliability and use. Streams are a lower form of data.
Definition at line 36 of file streamconversion.h.
| void digdiv::eval | ( | T & | fn | ) | [inline] |
| void digdiv::forward | ( | string const & | in | ) |
Read the string into vi as blocks.
Definition at line 74 of file streamconversion.cpp.
Referenced by rsatest::test01().
00075 { 00076 assert(blksz>0); 00077 00078 uintc sz = in.size(); 00079 uint i=0; 00080 vi.clear(); 00081 i += blksz; 00082 for ( ; i<=sz; ) 00083 { 00084 vi.push_back(in.substr(i-blksz,blksz)); 00085 i += blksz; 00086 } 00087 00088 if ((sz%blksz)!=0) 00089 { 00090 pad = blksz - (sz%blksz); 00091 string s; 00092 for (uint k=0; k<pad; ++k) 00093 s += '0'; 00094 s += in.substr(i-blksz); 00095 vi.push_back(s); 00096 } 00097 else 00098 pad=0; 00099 }
| void digdiv::restore | ( | istream & | in | ) |
Restore this object to the former state.
Definition at line 154 of file streamconversion.cpp.
00155 { 00156 if (in.eof()==false) 00157 in >> pad; 00158 else 00159 return; 00160 00161 if (in.eof()==false) 00162 in >> blksz; 00163 else 00164 return; 00165 00166 string s; 00167 in >> s; 00168 while (in.eof()==false) 00169 { 00170 vi.push_back(s); 00171 s.clear(); 00172 in >> s; 00173 } 00174 }
| void digdiv::reverse | ( | string & | os | ) |
Write the blocks in vi out as a continuous string.
Definition at line 101 of file streamconversion.cpp.
Referenced by rsatest::test01().
00102 { 00103 if (vi.empty()) 00104 return; 00105 00106 os.clear(); 00107 00108 uintc sz = vi.size(); 00109 00110 // Correct the block sizes 00111 for (uint i=0; i<sz; ++i) 00112 { 00113 uintc si = vi[i].size(); 00114 if (si != blksz) 00115 { 00116 if (si<blksz) 00117 { 00118 string tmp; 00119 for (uint k=si; k<blksz; ++k) 00120 tmp += '0'; 00121 tmp += vi[i]; 00122 vi[i] = tmp; 00123 } 00124 else 00125 { 00126 // A function should reduce the block size. 00127 assert(false); 00128 } 00129 } 00130 } 00131 00132 if (pad==0) 00133 { 00134 for (uint i=0; i<sz; ++i) 00135 os += vi[i]; 00136 return; 00137 } 00138 00139 string last = vi[sz-1]; 00140 last = last.substr(pad); 00141 for (uint i=0; i<sz-1; ++i) 00142 os += vi[i]; 00143 os += last; 00144 }
| void digdiv::save | ( | ostream & | os | ) | const |
Block size.
Definition at line 43 of file streamconversion.h.
Referenced by forward(), restore(), reverse(), save(), and rsatest::test01().
| vector<string> digdiv::vi |
1.5.8