Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
csldatahandler.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 "csl.h"
26 #include <map>
27 #include <vector>
28 #include <functional>
29 
30 namespace JSON {
31  class Node;
32 }
33 namespace mty::doc {
34 
36 
37 public:
38 
39  std::vector<std::shared_ptr<csl::Space>> getOwnSpaces() const {
40  return ownSpaces;
41  }
42 
43  csl::Expr read(
44  csl::Expr const &expr,
45  bool abbrev = false
46  );
47  void readJSON(std::string const &fileName);
48 
49  std::vector<csl::Expr> readSequence(
50  std::vector<csl::Expr>::const_iterator first,
51  std::vector<csl::Expr>::const_iterator last
52  )
53  {
54  std::vector<csl::Expr> res(last - first);
55  auto res_iter = res.begin();
56  while (first != last) {
57  *res_iter = read(*first, false);
58  ++res_iter;
59  ++first;
60  }
61  return res;
62  }
63 
64  template<class ExprType, class Translator>
65  csl::Expr read(
66  ExprType const &expr,
67  Translator translator
68  )
69  {
70  return read(translator(expr), false);
71  }
72 
73  template<class Iterator, class Translator>
74  std::vector<csl::Expr> readSequence(
75  Iterator first,
76  Iterator last,
77  Translator translator
78  )
79  {
80  std::vector<csl::Expr> res(last - first);
81  auto res_iter = res.begin();
82  while (first != last) {
83  *res_iter = read(*first, translator);
84  ++res_iter;
85  ++first;
86  }
87  return res;
88  }
89 
90  void print(std::ostream &out = std::cout) const;
91  void printCode(std::ostream &out = std::cout) const;
92 
93  void printJSON(std::string const &fileName) const;
94 
95 protected:
96 
97  void printComBlock(
98  std::string_view com,
99  std::ostream &out,
100  std::string_view indent
101  ) const;
102 
103  void printCSLDefinition(
104  csl::Tensor tensor,
105  std::ostream &out,
106  size_t indentSize
107  ) const;
108 
109  void parseAbbreviations(csl::Expr const &expr);
110  void parseTensors(csl::Expr const &expr);
111  void parseLiterals(csl::Expr const &expr);
112  void parseIndices(csl::Expr &expr);
113 
114  std::unique_ptr<JSON::Node> getSpaceList(
115  std::vector<csl::Space const*> const &spaces
116  ) const;
117 
118  csl::Space const *treatSpace(
119  std::string const &name,
120  int dim
121  );
122  csl::Tensor treatTensor(
123  std::string const &name,
124  std::vector<csl::Space const*> const &spaces,
125  bool isComplex = false
126  );
127  csl::Expr treatLiteral(
128  std::string const &name,
129  bool isComplex = false
130  );
131  void treatIndices(
132  csl::Space const *space,
133  size_t N
134  );
135 
136 protected:
137 
138  std::vector<csl::Expr> expressions;
139 
140  std::vector<csl::Space const*> spaces;
141  std::vector<csl::Parent> abbreviations;
142  std::vector<csl::Tensor> tensors;
143  std::vector<csl::Expr> literal;
144 
145  std::map<csl::Space const*, size_t> nIndices;
146  std::vector<std::shared_ptr<csl::Space>> ownSpaces;
147 };
148 
149 
150 }
Inherits from JSON::Object, specialized in JSON Node. A Node owns a vector of Object. The Node&#39;s children can either be Leaf or other Node objects. This allows to store the tree structure of a .json file.
Definition: jsonObject.h:97
Definition: checkpoint.h:38
Definition: csldatahandler.h:35
Contains all objects related to JSON reading / writing.
Definition: csldatahandler.h:30