1#ifndef UTIL_TEXT_FILE_O_ARCHIVE_H
2#define UTIL_TEXT_FILE_O_ARCHIVE_H
14#include <util/space/Vector.h>
15#include <util/space/IntVector.h>
68 std::ofstream&
file();
99 template <
typename T,
size_t N>
109 template <
typename T,
size_t N>
119 template <
typename T>
120 void pack(
const T& data);
128 template <
typename T>
129 void pack(
const T* array,
int n);
139 template <
typename T>
140 void pack(
const T* array,
int m,
int n,
int np);
145 std::ofstream* filePtr_;
148 unsigned int version_;
168 template <
typename T>
171 serialize(*
this, data, version_);
178 template <
typename T>
181 serialize(*
this, data, version_);
188 template <
typename T,
size_t N>
191 for (
size_t i = 0; i < N; ++i) {
192 serialize(*
this, data[i], version_);
200 template <
typename T,
size_t N>
203 for (
size_t i = 0; i < N; ++i) {
204 serialize(*
this, data[i], version_);
214 template <
typename T>
216 { *filePtr_ << data << std::endl; }
224 filePtr_->setf(std::ios::scientific);
226 filePtr_->precision(17);
227 *filePtr_ << data << std::endl;
233 template <
typename T>
236 for (
int i=0; i < n; ++i) {
237 *filePtr_ << array[i] <<
" ";
239 *filePtr_ << std::endl;
245 template <
typename T>
249 for (i = 0; i < m; ++i) {
250 for (j = 0; j < n; ++j) {
251 *filePtr_ << array[i*np + j] <<
" ";
253 *filePtr_ << std::endl;
263 filePtr_->setf(std::ios::scientific);
264 filePtr_->precision(16);
265 for (
int i=0; i < n; ++i) {
267 *filePtr_ << array[i] <<
" ";
269 *filePtr_ << std::endl;
278 inline void serialize(TextFileOArchive& ar,
bool& data,
279 const unsigned int version)
286 inline void serialize(TextFileOArchive& ar,
char& data,
287 const unsigned int version)
294 inline void serialize(TextFileOArchive& ar,
unsigned int& data,
295 const unsigned int version)
302 inline void serialize(TextFileOArchive& ar,
int& data,
303 const unsigned int version)
310 inline void serialize(TextFileOArchive& ar,
unsigned long& data,
311 const unsigned int version)
318 inline void serialize(TextFileOArchive& ar,
long& data,
319 const unsigned int version)
326 inline void serialize(TextFileOArchive& ar,
float& data,
327 const unsigned int version)
334 inline void serialize(TextFileOArchive& ar,
double& data,
335 const unsigned int version)
341 template <
typename T>
342 void serialize(TextFileOArchive& ar, std::vector<T>& data,
343 const unsigned int version)
345 size_t size = data.size();
347 for (
size_t i = 0; i < size; ++i) {
362 void serialize(TextFileOArchive& ar, std::complex<float>& data,
363 const unsigned int version)
374 void serialize(TextFileOArchive& ar, std::complex<double>& data,
375 const unsigned int version)
382 inline void serialize(TextFileOArchive& ar, std::string& data,
383 const unsigned int version)
385 int size = data.size();
398 inline void serialize(TextFileOArchive& ar, Vector& data,
399 const unsigned int version)
406 inline void serialize(TextFileOArchive& ar, IntVector& data,
407 const unsigned int version)
Saving archive for character based ostream.
TextFileOArchive & operator<<(T &data)
Save one T object to this archive via the << (insertion) operator.
TextFileOArchive()
Constructor.
static bool is_loading()
Returns false;.
static bool is_saving()
Returns true;.
virtual ~TextFileOArchive()
Destructor.
TextFileOArchive & operator&(T &data)
Save one T object to this archive.
std::ofstream & file()
Get the underlying ifstream by reference.
void pack(const T &data)
Save one T object to this archive.
Utility classes for scientific computation.