35 #ifndef MADNESS_WORLD_ARCHIVE_H__INCLUDED
36 #define MADNESS_WORLD_ARCHIVE_H__INCLUDED
428 #define ARCHIVE_COOKIE "archive"
429 #define ARCHIVE_MAJOR_VERSION 0
430 #define ARCHIVE_MINOR_VERSION 1
434 #ifdef MAD_ARCHIVE_DEBUG_ENABLE
435 #define MAD_ARCHIVE_DEBUG(s) s
438 #define MAD_ARCHIVE_DEBUG(s)
445 template <
typename T>
class Tensor;
462 #ifdef MAD_ARCHIVE_TYPE_NAMES_CC
465 extern const char *archive_type_names[256];
470 template <
typename T>
476 template <
typename T>
482 #if defined(ARCHIVE_REGISTER_TYPE_INSTANTIATE_HERE) && defined(ARCHIVE_REGISTER_TYPE_IBMBUG)
483 #define ARCHIVE_REGISTER_TYPE_XLC_EXTRA(T) \
484 ; const unsigned char archive_typeinfo< T >::cookie
486 #define ARCHIVE_REGISTER_TYPE_XLC_EXTRA(T)
501 #define ARCHIVE_REGISTER_TYPE(T, cooky) \
502 template <> struct archive_typeinfo< T > { \
503 static const unsigned char cookie = cooky; \
505 ARCHIVE_REGISTER_TYPE_XLC_EXTRA(T)
507 #define ARCHIVE_REGISTER_TYPE_AND_PTR(T, cooky) \
508 ARCHIVE_REGISTER_TYPE(T, cooky); \
509 ARCHIVE_REGISTER_TYPE(T*, cooky+64)
511 #define ATN ::madness::archive::archive_type_names
512 #define ATI ::madness::archive::archive_typeinfo
513 #define ARCHIVE_REGISTER_TYPE_NAME(T) \
514 if (strcmp(ATN[ATI< T >::cookie],"invalid")) {\
515 std::cout << "archive_register_type_name: slot/cookie already in use! "<< #T << " " << ATN[ATI< T >::cookie]<< std::endl; \
516 MADNESS_EXCEPTION("archive_register_type_name: slot/cookie already in use!", 0); \
518 ATN[ATI< T >::cookie] = #T
520 #define ARCHIVE_REGISTER_TYPE_AND_PTR_NAMES(T) \
521 ARCHIVE_REGISTER_TYPE_NAME(T); \
522 ARCHIVE_REGISTER_TYPE_NAME(T*)
593 template <
typename T>
601 template <
typename T>
609 template <
typename T>
613 template <
class Archive,
class T>
622 template <
class Archive,
class T>
631 template <
class Archive,
class T>
635 for (
unsigned int i=0; i<n; ++i) ar & t[i];
640 template <
class Archive,
class T>
644 unsigned char cookie;
648 std::sprintf(msg,
"InputArchive type mismatch: expected cookie "
649 "%u (%s) but got %u (%s) instead",
650 ck, archive_type_names[ck],
651 cookie,archive_type_names[cookie]);
652 std::cerr << msg << std::endl;
656 MAD_ARCHIVE_DEBUG(std::cout <<
"read cookie " << archive_type_names[cookie] << std::endl);
665 MAD_ARCHIVE_DEBUG(std::cout <<
"wrote cookie " << archive_type_names[ck] << std::endl);
678 template <
class Archive,
class T>
687 template <
class Archive,
class T>
691 MAD_ARCHIVE_DEBUG(std::cout <<
"serialize(ar,t) -> serialize(ar,&t,1)" << std::endl);
697 template <
class Archive,
class T>
701 MAD_ARCHIVE_DEBUG(std::cout <<
"serialize(ar,t) -> ArchiveSerializeImpl" << std::endl);
707 template <
class Archive,
class T>
709 static inline void store(
const Archive& ar,
const T& t) {
717 template <
class Archive,
class T>
719 static inline void load(
const Archive& ar,
const T& t) {
727 template <
class Archive,
class T>
729 static inline const Archive&
wrap_store(
const Archive& ar,
const T& t) {
737 static inline const Archive&
wrap_load(
const Archive& ar,
const T& t) {
748 template <
class Archive,
class T>
757 template <
class Archive,
class T>
766 template <
class Archive,
class T>
775 template <
class Archive,
class T>
796 template <
class Archive>
806 class archive_array {
841 template <
class Archive,
class T>
871 template <
class Archive,
class T, std::
size_t n>
873 static inline const Archive&
wrap_store(
const Archive& ar,
const T(&t)[n]) {
879 static inline const Archive&
wrap_load(
const Archive& ar,
const T(&t)[n]) {
888 template <
class Archive,
typename T>
890 static inline void store(
const Archive& ar,
const std::complex<T>&
c) {
892 ar & c.real() & c.imag();
898 template <
class Archive,
typename T>
900 static inline void load(
const Archive& ar, std::complex<T>&
c) {
904 c = std::complex<T>(r,i);
910 template <
class Archive,
typename T>
912 static inline void store(
const Archive& ar,
const std::vector<T>& v) {
915 ar &
wrap(&v[0],v.size());
921 template <
class Archive,
typename T>
923 static void load(
const Archive& ar, std::vector<T>& v) {
931 ar &
wrap((
T *) &v[0],n);
936 template <
class Archive>
938 static inline void store(
const Archive& ar,
const std::vector<bool>& v) {
940 std::size_t n = v.size();
941 bool*
b =
new bool[n];
942 for (std::size_t i=0; i<n; ++i) b[i] = v[i];
943 ar & n &
wrap(b,v.size());
950 template <
class Archive>
952 static void load(
const Archive& ar, std::vector<bool>& v) {
960 bool*
b =
new bool[n];
961 ar &
wrap(b,v.size());
962 for (std::size_t i=0; i<n; ++i) v[i] = b[i];
968 template <
class Archive>
973 ar &
wrap((
const char*) &v[0],v.size());
979 template <
class Archive>
989 ar &
wrap((
char*) &v[0],n);
995 template <
class Archive,
typename T,
typename Q>
997 static inline void serialize(
const Archive& ar, std::pair<T,Q>& t) {
999 ar & t.first & t.second;
1005 template <
class Archive,
typename T,
typename Q>
1007 static void store(
const Archive& ar,
const std::map<T,Q>& t) {
1010 for (
typename std::map<T,Q>::const_iterator p = t.begin();
1011 p != t.end(); ++p) {
1017 std::pair<T,Q> pp = *p;
1025 template <
class Archive,
typename T,
typename Q>
1027 static void load(
const Archive& ar, std::map<T,Q>& t) {
1034 t[p.first] = p.second;
1044 #endif // MADNESS_WORLD_ARCHIVE_H__INCLUDED
static const bool is_parallel_archive
Definition: archive.h:569
archive_ptr< T > wrap_ptr(T *p)
Definition: archive.h:802
static void postamble_store(const Archive &)
By default there is no postamble.
Definition: archive.h:673
archive_array()
Definition: archive.h:813
const char * get_type_name()
Definition: archive.h:477
Base class for all archives classes.
Definition: archive.h:564
archive_array< T > wrap(const T *, unsigned int)
Factory function to wrap dynamically allocated pointer as typed archive_array.
Definition: archive.h:820
static const Archive & wrap_store(const Archive &ar, const archive_array< T > &t)
Definition: archive.h:843
::std::string string
Definition: gtest-port.h:872
void archive_initialize_type_names()
Definition: archive_type_names.cc:51
Grossly simplified Boost-like type traits and templates.
Definition: mpreal.h:3066
Default symmetric serialization of a non-fundamental thingy.
Definition: archive.h:679
static void preamble_store(const Archive &ar)
Serialize a cookie for type checking.
Definition: archive.h:662
enable_if< is_input_archive< Archive >, const Archive & >::type operator>>(const Archive &ar, const T &t)
Definition: archive.h:760
static void load(const Archive &ar, std::map< T, Q > &t)
Definition: archive.h:1027
static void store(const Archive &ar, const T &t)
Definition: archive.h:709
Default implementation of pre/postamble.
Definition: archive.h:641
Wrapper for opaque pointer ... bitwise copy of the pointer ... no remapping performed.
Definition: archive.h:788
T & operator*()
Definition: archive.h:794
Default store of a thingy via serialize(ar,t)
Definition: archive.h:708
unsigned int n
Definition: archive.h:809
ARCHIVE_REGISTER_TYPE_AND_PTR(unsigned char, 0)
archive_array(const T *ptr, unsigned int n)
Definition: archive.h:811
const T * ptr
Definition: archive.h:808
static void store(const Archive &ar, const std::map< T, Q > &t)
Definition: archive.h:1007
const char * archive_type_names[256]
static const Archive & wrap_load(const Archive &ar, const T(&t)[n])
Definition: archive.h:879
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
T * ptr
Definition: archive.h:790
static const Archive & wrap_load(const Archive &ar, const T &t)
Definition: archive.h:737
BaseArchive()
Definition: archive.h:570
Checks that T is an output archive type.
Definition: archive.h:610
Base class for output archives classes.
Definition: archive.h:583
Checks that T is an archive type.
Definition: archive.h:594
Default load of a thingy via serialize(ar,t)
Definition: archive.h:718
void serialize(const Archive &ar)
Definition: archive.h:797
static void load(const Archive &ar, const T &t)
Definition: archive.h:719
enable_if< is_output_archive< Archive >, const Archive & >::type operator&(const Archive &ar, const T &t)
Definition: archive.h:769
static void serialize(const Archive &ar, std::pair< T, Q > &t)
Definition: archive.h:997
enable_if_c from Boost for conditionally instantiating templates based on type
Definition: enable_if.h:46
Default implementation of wrap_store and wrap_load.
Definition: archive.h:728
enable_if_c< is_serializable< T >::value &&is_output_archive< Archive >::value >::type serialize(const Archive &ar, const T *t, unsigned int n)
Definition: archive.h:615
#define MAD_ARCHIVE_DEBUG(s)
Definition: archive.h:438
Wrapper for dynamic arrays and pointers.
Definition: archive.h:451
static void load(const Archive &ar, std::vector< T > &v)
Definition: archive.h:923
static void store(const Archive &ar, const std::vector< T > &v)
Definition: archive.h:912
static const unsigned char cookie
255 indicates unknown type
Definition: archive.h:472
static void load(const Archive &ar, std::string &v)
Definition: archive.h:981
archive_array< unsigned char > wrap_opaque(const T *, unsigned int)
Factory function to wrap pointer to contiguous data as opaque (uchar) archive_array.
Definition: archive.h:827
static void store(const Archive &ar, const std::string &v)
Definition: archive.h:970
archive_ptr(T *t=0)
Definition: archive.h:792
static void preamble_load(const Archive &ar)
Definition: archive.h:642
static const Archive & wrap_store(const Archive &ar, const T &t)
Definition: archive.h:729
Implements MadnessException.
Definition: archive.h:471
static void store(const Archive &ar, const std::complex< T > &c)
Definition: archive.h:890
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
static void load(const Archive &ar, std::complex< T > &c)
Definition: archive.h:900
static const Archive & wrap_store(const Archive &ar, const T(&t)[n])
Definition: archive.h:873
enable_if from Boost for conditionally instantiating templates based on type
Definition: enable_if.h:60
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
enable_if< is_output_archive< Archive >, const Archive & >::type operator<<(const Archive &ar, const T &t)
Definition: archive.h:751
const double c
Definition: gfit.cc:200
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
Definition: type_traits_bits.h:183
static void store(const Archive &ar, const std::vector< bool > &v)
Definition: archive.h:938
static const Archive & wrap_load(const Archive &ar, const archive_array< T > &t)
Definition: archive.h:854
static void serialize(const Archive &ar, T &t)
Definition: archive.h:680
static void load(const Archive &ar, std::vector< bool > &v)
Definition: archive.h:952
static void postamble_load(const Archive &)
By default there is no postamble.
Definition: archive.h:670