32#ifndef MADNESS_WORLD_TEXT_FSTREAM_ARCHIVE_H__INCLUDED
33#define MADNESS_WORLD_TEXT_FSTREAM_ARCHIVE_H__INCLUDED
55 mutable std::ofstream
os;
65 std::ios_base::openmode mode=std::ios_base::binary | std::ios_base::out | std::ios_base::trunc)
79 snprintf(tag,
bufsize,
"<t%d>", cookie);
80 os << tag << std::endl;
92 snprintf(tag,
bufsize,
"</t%d>",cookie);
93 os << tag << std::endl;
104 typename std::enable_if< madness::is_ostreammable_v<T> >
::type
106 using madness::operators::operator<<;
107 for (
long i=0; i<n; ++i)
108 os << t[i] << std::endl;
114 void store(
const char* t,
long )
const;
120 void store(
const unsigned char* t,
long n)
const {
121 for (
long i=0; i<n; ++i)
122 os << (
unsigned int) t[i] << std::endl;
129 void open(
const char*
filename, std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc);
150 mutable std::ifstream
is;
163 std::ios_base::openmode mode = std::ios_base::in)
181 snprintf(tag,
bufsize,
"</t%d>",cookie);
183 snprintf(tag,
bufsize,
"<t%d>",cookie);
185 if (strcmp(tag,ftag) != 0) {
186 std::cout <<
"TextFstreamInputArchive: type mismatch: expected=" << tag
190 <<
" got=" << ftag << std::endl;
191 MADNESS_EXCEPTION(
"TextFstreamInputArchive: check_tag: types do not match/corrupt file", 1);
200 check_start_tag<T>(
true);
211 typename std::enable_if< madness::is_istreammable_v<T> >
::type
213 using madness::operators::operator>>;
214 for (
long i=0; i<n; ++i) is >> t[i];
222 void load(
unsigned char* t,
long n)
const;
228 void load(
char* t,
long n)
const;
235 std::ios_base::openmode mode = std::ios_base::in);
Interface templates for the archives (serialization).
#define MAD_ARCHIVE_DEBUG(s)
Macro for helping debug archive tools.
Definition archive.h:76
Base class for output archive classes.
Definition archive.h:382
Wraps an archive around a text filestream for input.
Definition text_fstream_archive.h:148
void check_end_tag() const
Read the closing "cookie" tag.
Definition text_fstream_archive.h:199
void close()
Close the filestream.
Definition text_fstream_archive.h:238
void eat_eol() const
Eat the EOL after each entry to enable a char-by-char read of strings.
Definition text_fstream_archive.cc:96
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in)
Open the filestream.
Definition text_fstream_archive.cc:141
void check_start_tag(bool end=false) const
Check the "cookie" tag in the archive for runtime type-checking.
Definition text_fstream_archive.h:175
TextFstreamInputArchive(const char *filename=nullptr, std::ios_base::openmode mode=std::ios_base::in)
Default constructor.
Definition text_fstream_archive.h:162
std::enable_if< madness::is_istreammable_v< T > >::type load(T *t, long n) const
Load from the filestream.
Definition text_fstream_archive.h:212
std::ifstream is
The filestream.
Definition text_fstream_archive.h:150
Wraps an archive around a text filestream for output.
Definition text_fstream_archive.h:54
std::enable_if< madness::is_ostreammable_v< T > >::type store(const T *t, long n) const
Store data to the filestream.
Definition text_fstream_archive.h:105
void close()
Close the filestream.
Definition text_fstream_archive.cc:87
void store_start_tag() const
Stores the cookie for runtime type-checking into the archive as a tag.
Definition text_fstream_archive.h:75
TextFstreamOutputArchive(const char *filename=nullptr, std::ios_base::openmode mode=std::ios_base::binary|std::ios_base::out|std::ios_base::trunc)
Default constructor.
Definition text_fstream_archive.h:64
~TextFstreamOutputArchive()
Destructor.
Definition text_fstream_archive.h:141
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::out|std::ios_base::trunc)
Open the filestream.
Definition text_fstream_archive.cc:66
std::ofstream os
The filestream.
Definition text_fstream_archive.h:55
void store(const unsigned char *t, long n) const
Store a character string, without escaping characters.
Definition text_fstream_archive.h:120
void flush()
Flush the filestream.
Definition text_fstream_archive.h:135
void store_end_tag() const
Closes the "cookie" tag for runtime type-checking.
Definition text_fstream_archive.h:88
const std::size_t bufsize
Definition derivatives.cc:16
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
const char * archive_type_names[256]
The list of type names for use in archives.
Definition archive_type_names.cc:46
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
static const char * filename
Definition legendre.cc:96
std::string type(const PairType &n)
Definition PNOParameters.h:18
Defines simple templates for printing to std::cout "a la Python".
static void preamble_load(const TextFstreamInputArchive &ar)
Load the preamble and perform type-checking.
Definition text_fstream_archive.h:271
static void postamble_load(const TextFstreamInputArchive &ar)
Load the postamble and perform type-checking.
Definition text_fstream_archive.h:278
static void postamble_store(const TextFstreamOutputArchive &ar)
Write the postamble to the archive.
Definition text_fstream_archive.h:258
static void preamble_store(const TextFstreamOutputArchive &ar)
Write the preamble to the archive.
Definition text_fstream_archive.h:251
Default implementation of the pre/postamble for type checking.
Definition archive.h:509
Used to enable type checking inside archives.
Definition archive.h:115