MADNESS  version 0.9
binfsar.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 
36 #ifndef MADNESS_WORLD_BINFSAR_H__INCLUDED
37 #define MADNESS_WORLD_BINFSAR_H__INCLUDED
38 
41 
42 #include <fstream>
43 #include <madness/world/archive.h>
45 
46 
47 namespace madness {
48  namespace archive {
49 
52  static const std::size_t IOBUFSIZE = 4*1024*1024;
54  mutable std::ofstream os;
55  public:
56  BinaryFstreamOutputArchive(const char* filename = 0,
57  std::ios_base::openmode mode = std::ios_base::binary | \
58  std::ios_base::out | std::ios_base::trunc);
59 
60  template <class T>
61  inline
63  store(const T* t, long n) const {
64  os.write((const char *) t, n*sizeof(T));
65  }
66 
67  void open(const char* filename,
68  std::ios_base::openmode mode = std::ios_base::binary | \
69  std::ios_base::out | std::ios_base::trunc);
70 
71  void close();
72 
73  void flush();
74  };
75 
76 
79  static const std::size_t IOBUFSIZE = 4*1024*1024;
81  mutable std::ifstream is;
82  public:
83  BinaryFstreamInputArchive(const char* filename = 0, std::ios_base::openmode mode = std::ios_base::binary | std::ios_base::in);
84 
85  template <class T>
86  inline
88  load(T* t, long n) const {
89  is.read((char *) t, n*sizeof(T));
90  }
91 
92  void open(const char* filename, std::ios_base::openmode mode = std::ios_base::binary | std::ios_base::in);
93 
94  void close();
95  };
96  }
97 }
98 #endif // MADNESS_WORLD_BINFSAR_H__INCLUDED
Wraps an archive around a binary file stream for input.
Definition: binfsar.h:78
void close()
Definition: binfsar.cc:58
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::binary|std::ios_base::in)
Definition: binfsar.cc:75
void flush()
Definition: binfsar.cc:65
Interface templates for the archives (serialization)
madness::enable_if< madness::is_serializable< T >, void >::type load(T *t, long n) const
Definition: binfsar.h:88
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
BinaryFstreamInputArchive(const char *filename=0, std::ios_base::openmode mode=std::ios_base::binary|std::ios_base::in)
Definition: binfsar.cc:69
BinaryFstreamOutputArchive(const char *filename=0, std::ios_base::openmode mode=std::ios_base::binary|std::ios_base::out|std::ios_base::trunc)
Definition: binfsar.cc:42
Base class for output archives classes.
Definition: archive.h:583
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::binary|std::ios_base::out|std::ios_base::trunc)
Definition: binfsar.cc:48
Base class for input archives classes.
Definition: archive.h:576
const mpreal trunc(const mpreal &v)
Definition: mpreal.h:2618
madness::enable_if< madness::is_serializable< T >, void >::type store(const T *t, long n) const
Definition: binfsar.h:63
void close()
Definition: binfsar.cc:87
Wraps an archive around a binary file stream for output.
Definition: binfsar.h:51
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