1#ifndef UTIL_BINARY_FILE_O_ARCHIVE_H
2#define UTIL_BINARY_FILE_O_ARCHIVE_H
14#include <util/space/Vector.h>
15#include <util/space/IntVector.h>
68 std::ofstream&
file();
101 template <
typename T,
size_t N>
111 template <
typename T,
size_t N>
121 template <
typename T>
122 void pack(
const T& data);
130 template <
typename T>
131 void pack(
const T* array,
int n);
144 template <
typename T>
145 void pack(
const T* array,
int m,
int n,
int np);
150 std::ofstream* filePtr_;
153 unsigned int version_;
173 template <
typename T>
176 serialize(*
this, data, version_);
183 template <
typename T>
186 serialize(*
this, data, version_);
193 template <
typename T,
size_t N>
196 for (
size_t i=0; i < N; ++i) {
197 serialize(*
this, data[i], version_);
205 template <
typename T,
size_t N>
208 for (
size_t i=0; i < N; ++i) {
209 serialize(*
this, data[i], version_);
219 template <
typename T>
221 { filePtr_->write( (
char*)(&data),
sizeof(T)); }
226 template <
typename T>
229 for (
int i=0; i < n; ++i) {
230 filePtr_->write( (
char*)(&array[i]),
sizeof(T));
237 template <
typename T>
241 for (i=0; i < m; ++i) {
242 for (j=0; j < n; ++j) {
243 filePtr_->write( (
char*)(&array[i*np + j]),
sizeof(T));
255 const unsigned int version)
262 inline void serialize(BinaryFileOArchive& ar,
char& data,
263 const unsigned int version)
270 inline void serialize(BinaryFileOArchive& ar,
unsigned int& data,
271 const unsigned int version)
278 inline void serialize(BinaryFileOArchive& ar,
int& data,
279 const unsigned int version)
286 inline void serialize(BinaryFileOArchive& ar,
unsigned long& data,
287 const unsigned int version)
294 inline void serialize(BinaryFileOArchive& ar,
long& data,
295 const unsigned int version)
302 inline void serialize(BinaryFileOArchive& ar,
float& data,
303 const unsigned int version)
310 inline void serialize(BinaryFileOArchive& ar,
double& data,
311 const unsigned int version)
317 template <
typename T>
318 void serialize(BinaryFileOArchive& ar, std::vector<T>& data,
319 const unsigned int version)
321 size_t size = data.size();
323 for (
size_t i = 0; i < size; ++i) {
335 void serialize(BinaryFileOArchive& ar, std::complex<float>& data,
336 const unsigned int version)
344 void serialize(BinaryFileOArchive& ar, std::complex<double>& data,
345 const unsigned int version)
352 inline void serialize(BinaryFileOArchive& ar, std::string& data,
353 const unsigned int version)
355 size_t size = data.size() + 1;
357 const char* temp = data.c_str();
367 inline void serialize(BinaryFileOArchive& ar, Vector& data,
368 const unsigned int version)
375 inline void serialize(BinaryFileOArchive& ar, IntVector& data,
376 const unsigned int version)
Saving / output archive for binary ostream.
static bool is_loading()
Returns false;.
BinaryFileOArchive & operator<<(T &data)
Save (write) one object of type T via the << operator.
BinaryFileOArchive()
Constructor.
BinaryFileOArchive & operator&(T &data)
Save (write) one object of type T via the & operator.
std::ofstream & file()
Get the underlying ifstream by reference.
static bool is_saving()
Returns true;.
virtual ~BinaryFileOArchive()
Destructor.
void pack(const T &data)
Pack one object of type T.
Utility classes for scientific computation.