ALPSCore reference
serializer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 #pragma once
7 
8 #include <alps/alea/core.hpp>
9 #include <iosfwd>
10 
11 namespace alps { namespace alea { namespace util {
12 
14  : public serializer
15 {
16 public:
18 
19  void enter(const std::string &) override { }
20 
21  void exit() override { }
22 
23  void write(const std::string &, ndview<const double>) override { }
24 
25  void write(const std::string &, ndview<const std::complex<double>>) override { }
26 
27  void write(const std::string &, ndview<const complex_op<double>>) override { }
28 
29  void write(const std::string &, ndview<const long>) override { }
30 
31  void write(const std::string &, ndview<const unsigned long>) override { }
32 
33  null_serializer *clone() override { return new null_serializer(*this); }
34 
36 };
37 
39  : public serializer
40 {
41 public:
42  debug_serializer(std::ostream &stream)
43  : str_(stream)
44  , inner_(nullptr)
45  {
46  static null_serializer null_instance;
47  inner_ = &null_instance;
48  }
49 
50  debug_serializer(std::ostream &stream, serializer &inner)
51  : str_(stream)
52  , inner_(&inner)
53  { }
54 
55  void enter(const std::string &group) override
56  {
57  str_ << "debug_serializer: entering group '" << group << "'\n";
58  inner_->enter(group);
59  }
60 
61  void exit() override
62  {
63  str_ << "debug_serializer: exitting group.\n";
64  inner_->exit();
65  }
66 
67  void write(const std::string &key, ndview<const double> value) override {
68  do_write(key, value);
69  }
70 
71  void write(const std::string &key, ndview<const std::complex<double>> value) override {
72  do_write(key, value);
73  }
74 
75  void write(const std::string &key, ndview<const complex_op<double>> value) override {
76  do_write(key, value);
77  }
78 
79  void write(const std::string &key, ndview<const long> value) override {
80  do_write(key, value);
81  }
82 
83  void write(const std::string &key, ndview<const unsigned long> value) override {
84  do_write(key, value);
85  }
86 
87 protected:
88  template <typename T>
89  void do_write(const std::string &key, ndview<const T> value)
90  {
91  str_ << "debug_serializer: writing data set '" << key
92  << "' of shape {";
93  for (size_t i = 0; i != value.ndim(); ++i)
94  str_ << value.shape()[i] << (i == 0 ? "" : ",");
95  str_ << "}\n";
96  inner_->write(key, value);
97  }
98 
99 private:
100  std::ostream &str_;
101  serializer *inner_;
102 };
103 
104 }}}
void write(const std::string &, ndview< const complex_op< double >>) override
Definition: serializer.hpp:27
void enter(const std::string &group) override
Definition: serializer.hpp:55
void do_write(const std::string &key, ndview< const T > value)
Definition: serializer.hpp:89
const size_t * shape() const
Definition: core.hpp:117
void enter(const std::string &) override
Definition: serializer.hpp:19
void write(const std::string &, ndview< const double >) override
Definition: serializer.hpp:23
void write(const std::string &, ndview< const std::complex< double >>) override
Definition: serializer.hpp:25
void write(const std::string &key, ndview< const unsigned long > value) override
Definition: serializer.hpp:83
null_serializer * clone() override
Definition: serializer.hpp:33
void write(const std::string &key, ndview< const double > value) override
Definition: serializer.hpp:67
void write(const std::string &, ndview< const long >) override
Definition: serializer.hpp:29
debug_serializer(std::ostream &stream)
Definition: serializer.hpp:42
debug_serializer(std::ostream &stream, serializer &inner)
Definition: serializer.hpp:50
size_t ndim() const
Definition: core.hpp:120
void write(const std::string &key, ndview< const long > value) override
Definition: serializer.hpp:79
void write(const std::string &key, ndview< const complex_op< double >> value) override
Definition: serializer.hpp:75
void write(const std::string &key, ndview< const std::complex< double >> value) override
Definition: serializer.hpp:71
void write(const std::string &, ndview< const unsigned long >) override
Definition: serializer.hpp:31