ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
archive.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * ALPS MPS DMRG Project
4  *
5  * Copyright (C) 2013 Institute for Theoretical Physics, ETH Zurich
6  * 2011-2011 by Bela Bauer <bauerb@phys.ethz.ch>
7  * 2011-2012 by Michele Dolfi <dolfim@phys.ethz.ch>
8  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
28 #ifndef STORAGE_ARCHIVE_H
29 #define STORAGE_ARCHIVE_H
30 
31 #include <boost/utility.hpp>
32 #include <alps/hdf5.hpp>
33 #include <alps/utility/encode.hpp>
34 
35 namespace storage {
36 
37  inline std::string once(std::string fp){
38  return fp;
39  }
40 
41  inline void uniq(std::string fp){
42  }
43 
44  class archive : boost::noncopyable {
45  public:
46  archive(std::string fp) : write(false), fp(fp) {
47  impl = new alps::hdf5::archive(fp);
48  }
49  archive(std::string fp, const char* rights) : write(strcmp(rights,"w") == 0), fp(fp) {
50  impl = new alps::hdf5::archive(once(fp), rights);
51  }
53  delete impl;
54  if(write) uniq(fp);
55  }
56  bool is_group(const char* path){
57  return impl->is_group(path);
58  }
59  bool is_scalar(const char* path){
60  return impl->is_scalar(path);
61  }
62  bool is_data(const char* path){
63  return impl->is_data(path);
64  }
65  template<typename T>
66  void operator << (const T& obj){
67  (*impl) << obj;
68  }
69  template<typename T>
70  void operator >> (T& obj){
71  (*impl) >> obj;
72  }
73  alps::hdf5::detail::archive_proxy<alps::hdf5::archive> operator[](std::string path){
74  return (*impl)[path];
75  }
76  private:
77  bool write;
78  std::string fp;
79  alps::hdf5::archive* impl;
80  };
81 
82  inline std::string encode(std::string const & s){
83  return alps::hdf5_name_encode(s);
84  }
85 }
86 
87 #endif
void operator<<(const T &obj)
Definition: archive.h:66
alps::hdf5::detail::archive_proxy< alps::hdf5::archive > operator[](std::string path)
Definition: archive.h:73
std::string encode(std::string const &s)
Definition: archive.h:82
void operator>>(T &obj)
Definition: archive.h:70
bool is_group(const char *path)
Definition: archive.h:56
std::string once(std::string fp)
Definition: archive.h:37
archive(std::string fp)
Definition: archive.h:46
bool is_data(const char *path)
Definition: archive.h:62
void uniq(std::string fp)
Definition: archive.h:41
bool is_scalar(const char *path)
Definition: archive.h:59
archive(std::string fp, const char *rights)
Definition: archive.h:49