Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataCell.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <string>
5 #include <mutex>
6 
7 #include "tree.hh"
8 #include "json/json.h"
9 
10 namespace cadabra {
11 
26 
27  class DataCell {
28  public:
29 
33 
34  enum class CellType {
35  document,
36  python,
37  latex,
38  output,
39  verbatim,
40  latex_view,
41  input_form,
42  image_png,
43  error,
44  // section
45  };
46 
50 
51  class id_t {
52  public:
53  id_t();
54 
55  uint64_t id;
57 
58  bool operator<(const id_t& other) const;
59  };
60 
62 
63  DataCell(CellType t=CellType::python, const std::string& str="", bool hidden=false);
64 
67 
68  DataCell(id_t, CellType t=CellType::python, const std::string& str="", bool hidden=false);
69 
71 
72  DataCell(const DataCell&);
73 
75 
80 
81  std::string textbuf;
82 
87 
88  bool hidden;
89  bool sensitive;
90 
94 
95  bool running;
96 
97  id_t id() const;
98 
99  private:
100 
101  static std::mutex serial_mutex;
103  static uint64_t max_serial_number; // on the client, server keeps track separately.
104  };
105 
106  typedef tree<DataCell> DTree;
107 
110 
111  std::string JSON_serialise(const DTree&);
112  void JSON_recurse(const DTree&, DTree::iterator, Json::Value&);
113 
115 
116  void JSON_deserialise(const std::string&, DTree&);
117  void JSON_in_recurse(DTree& doc, DTree::iterator loc, const Json::Value& cells);
118 
120 
121  std::string export_as_HTML(const DTree& doc, bool for_embedding=false, std::string title="");
122  void HTML_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str,
123  const std::string& preamble_string,
124  bool for_embedding=false, std::string title="");
125 
128 
129  std::string latex_to_html(const std::string&);
130 
132 
133  std::string export_as_LaTeX(const DTree& doc);
134  void LaTeX_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str, const std::string& preamble_string);
135 
138 
139  std::string export_as_python(const DTree& doc);
140  void python_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str);
141 
142 }
output: cell showing LaTeX text for errors
DataCells are the basic building blocks for a document.
Definition: DataCell.hh:27
DataCell(CellType t=CellType::python, const std::string &str="", bool hidden=false)
Standard constructor, generates a new unique id for this DataCell.
Definition: DataCell.cc:31
id_t()
Definition: DataCell.cc:24
output: cell showing python stdout, verbatim
CellType cell_type
Definition: DataCell.hh:74
id_t serial_number
Definition: DataCell.hh:102
input : editor cell for code in latex
void HTML_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str, const std::string &preamble_string, bool for_embedding=false, std::string title="")
Definition: DataCell.cc:145
bool running
Indicator whether this cell is currently being evaluated by the server.
Definition: DataCell.hh:95
uint64_t id
Definition: DataCell.hh:55
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition: DataCell.hh:51
output: cell showing a base64 encoded PNG image
std::string JSON_serialise(const DTree &)
Serialise a document into .cj format, which is a JSON version of the document tree.
Definition: DataCell.cc:256
bool sensitive
Definition: DataCell.hh:89
void JSON_in_recurse(DTree &doc, DTree::iterator loc, const Json::Value &cells)
Definition: DataCell.cc:353
input : editor cell for code in python
bool operator<(const id_t &other) const
Definition: DataCell.cc:17
output: cell containing input form of preceding output cell
std::string export_as_LaTeX(const DTree &doc)
Export a document to a single self-contained LaTeX file.
Definition: DataCell.cc:464
bool created_by_client
Definition: DataCell.hh:56
output: cell showing LaTeX text formatted using LaTeX
id_t id() const
Definition: DataCell.cc:459
std::string latex_to_html(const std::string &)
Convert various LaTeX constructions to HTML-with-Mathjax, e.g.
Definition: DataCell.cc:76
output: cell showing other verbatim output
std::string export_as_HTML(const DTree &doc, bool for_embedding=false, std::string title="")
Export a document to a single self-contained HTML file containing inline CSS.
Definition: DataCell.cc:58
static std::mutex serial_mutex
Definition: DataCell.hh:101
void JSON_recurse(const DTree &, DTree::iterator, Json::Value &)
Definition: DataCell.cc:267
static uint64_t max_serial_number
Definition: DataCell.hh:103
tree< DataCell > DTree
Definition: DataCell.hh:106
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition: DataCell.hh:34
bool hidden
Flag indicating whether this cell should be hidden from view.
Definition: DataCell.hh:88
std::string export_as_python(const DTree &doc)
Export a document to a python-like file (converting text cells to comments and python cells to python...
Definition: DataCell.cc:586
void LaTeX_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str, const std::string &preamble_string)
Definition: DataCell.cc:483
void python_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str)
Definition: DataCell.cc:594
head node, only one per document
std::string textbuf
Textual representation of the cell content.
Definition: DataCell.hh:81
void JSON_deserialise(const std::string &, DTree &)
Load a document from .cj format, i.e. the inverse of the above.
Definition: DataCell.cc:333