Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
checkpoint.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #pragma once
24 
25 #include <vector>
26 #include <string>
27 #include <string_view>
28 #include <iostream>
29 #include <type_traits>
30 #include <memory>
31 #include <cxxabi.h>
32 #include "csl.h"
33 #include "fileData.h"
34 #include "mtyversion.h"
35 #include "csldatahandler.h"
37 
38 namespace mty::doc {
39 
40 class FileData;
41 
43 
44 public:
45 
47  std::string_view t_name,
48  std::string_view t_nameComparator = ""
49  )
50  :name(t_name),
51  nameComparator(t_nameComparator)
52  {}
53 
54  virtual ~CheckPoint_Base() {}
55 
56  std::string const &getName() const { return name; }
57  std::string const &getNameComparator() const { return nameComparator; }
58 
59  void print(FileData &fileData) const {
60  printHeader(fileData);
61  printSource(fileData);
62  }
63  virtual void printHeader(FileData &fileData) const = 0;
64  virtual void printSource(FileData &fileData) const = 0;
65 
66  virtual bool hasCSLData() const { return false; }
67  virtual void updateCSLData(CSLDataHandler &) {}
68 
69  template<class Type>
70  static std::unique_ptr<char const> typeName()
71  {
72  [[maybe_unused]] int success;
73  char const *typeName = abi::__cxa_demangle(
74  typeid(std::remove_cv_t<std::remove_reference_t<Type>>).name(),
75  nullptr,
76  nullptr,
77  &success
78  );
79  return std::unique_ptr<char const>(typeName);
80  }
81 
82 protected:
83  std::string name;
84  std::string nameComparator;
85 };
86 
87 template<class ValueType>
89 
90 public:
91 
92  IMPLEMENTS_STD_VECTOR(ValueType, data)
93 
94  virtual ~CheckPoint_Implementation() {}
95 
96  void declareFunction(
97  std::ostream &out,
98  std::string_view name,
99  std::string_view indent,
100  FileData::Mode mode
101  ) const
102  {
103  out << indent << "std::vector<";
104  out << CheckPoint_Base::typeName<ValueType>().get() << "> ";
105  out << name << "()";
106  if (mode == FileData::Header)
107  out << ";\n";
108  out << '\n';
109  }
110 
111 protected:
112 
113  std::vector<ValueType> data;
114 };
115 
116 template<class ValueType>
118 
119 template<>
120 class CheckPoint<csl::Expr>
121  :public CheckPoint_Base,
122  public CheckPoint_Implementation<csl::Expr>
123 {
124 public:
125 
126  CheckPoint(
127  std::string_view t_name,
128  std::string_view t_nameComparator = ""
129  )
130  :CheckPoint_Base(t_name, t_nameComparator),
132  {}
133 
134  void printHeader(FileData &fileData) const override {
135  auto &out = fileData.getStream(FileData::Header);
136  declareFunction(out, name, "", FileData::Header);
137  }
138  void printSource(FileData &fileData) const override {
139  auto &out = fileData.getStream(FileData::Source);
140  auto const &indent = fileData.indent();
141  declareFunction(out, name, "", FileData::Source);
142  out << "{\n";
143  out << indent << "std::vector<csl::Expr> res(" << size() << ");\n";
144  out << indent << "auto iter = res.begin();\n\n";
145  for (const auto &expr : *this) {
146  out << indent << "*iter++ = ";
147  expr->printCode(0, out);
148  out << ";\n\n";
149  }
150  out << indent << "return res;\n";
151  out << "}\n\n";
152  }
153 
154  bool hasCSLData() const override { return true; }
155  void updateCSLData(CSLDataHandler &cslData) override {
156  data = cslData.readSequence(data.begin(), data.end());
157  }
158 };
159 
160 
161 }
Definition: checkpoint.h:88
Definition: fileData.h:34
Definition: checkpoint.h:38
Definition: checkpoint.h:42
Definition: csldatahandler.h:35
File data utility for doc brown&#39;s debugger.
Contains macros for MARTY&#39;s version in particular for doc brown&#39;s debugger.
Contains the handler of CSL data for doc brown&#39;s debugger.
Definition: checkpoint.h:117