Cadabra
Computer algebra system for field theory problems
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  Json::UInt64 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:
101  };
102 
103  typedef tree<DataCell> DTree;
104 
107 
108  std::string JSON_serialise(const DTree&);
109  void JSON_recurse(const DTree&, DTree::iterator, Json::Value&);
110 
112 
113  void JSON_deserialise(const std::string&, DTree&);
114  void JSON_in_recurse(DTree& doc, DTree::iterator loc, const Json::Value& cells);
115 
117 
118  std::string export_as_HTML(const DTree& doc, bool for_embedding=false, bool
119  strip_code=false, std::string title="");
120  void HTML_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str,
121  const std::string& preamble_string,
122  bool for_embedding=false, bool strip_code=false, std::string title="");
123 
126 
127  std::string latex_to_html(const std::string&);
128 
131 
132  std::string export_as_LaTeX(const DTree& doc, const std::string& image_file_base);
133  void LaTeX_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str,
134  const std::string& preamble_string, const std::string& image_file_base,
135  int& image_num);
136 
139 
140  std::string export_as_python(const DTree& doc);
141  void python_recurse(const DTree& doc, DTree::iterator it, std::ostringstream& str);
142 
144  // std::string replace_all(std::string, const std::string& old, const std::string& nw);
145  }
cadabra::DataCell::sensitive
bool sensitive
Definition: DataCell.hh:89
cadabra::python_recurse
void python_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str)
Definition: DataCell.cc:618
cadabra::JSON_deserialise
void JSON_deserialise(const std::string &, DTree &)
Load a document from .cj format, i.e. the inverse of the above.
Definition: DataCell.cc:351
cadabra::DataCell::CellType::input_form
output: cell containing input form of preceding output cell
cadabra::DataCell::running
bool running
Indicator whether this cell is currently being evaluated by the server.
Definition: DataCell.hh:95
cadabra::DataCell::CellType::latex
input : editor cell for code in latex
cadabra::DataCell::id_t::created_by_client
bool created_by_client
Definition: DataCell.hh:56
cadabra::LaTeX_recurse
void LaTeX_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str, const std::string &preamble_string, const std::string &image_file_base, int &image_num)
Definition: DataCell.cc:502
cadabra::DataCell::CellType::verbatim
output: cell showing other verbatim output
cadabra::DataCell
Definition: DataCell.hh:27
cadabra::JSON_serialise
std::string JSON_serialise(const DTree &)
Serialise a document into .cj format, which is a JSON version of the document tree.
Definition: DataCell.cc:272
cadabra::export_as_HTML
std::string export_as_HTML(const DTree &doc, bool for_embedding=false, bool strip_code=false, std::string title="")
Export a document to a single self-contained HTML file containing inline CSS.
Definition: DataCell.cc:56
cadabra::DataCell::id_t::id
Json::UInt64 id
Definition: DataCell.hh:55
cadabra::DataCell::CellType::output
output: cell showing python stdout, verbatim
cadabra::DataCell::CellType::error
output: cell showing LaTeX text for errors
cadabra::DataCell::hidden
bool hidden
Flag indicating whether this cell should be hidden from view.
Definition: DataCell.hh:88
cadabra::JSON_in_recurse
void JSON_in_recurse(DTree &doc, DTree::iterator loc, const Json::Value &cells)
Definition: DataCell.cc:371
cadabra::DataCell::id_t::id_t
id_t()
Definition: DataCell.cc:23
cadabra::DataCell::DataCell
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:29
cadabra::DataCell::cell_type
CellType cell_type
Definition: DataCell.hh:74
cadabra::DTree
tree< DataCell > DTree
Definition: DataCell.hh:103
cadabra::DataCell::CellType::document
head node, only one per document
cadabra::HTML_recurse
void HTML_recurse(const DTree &doc, DTree::iterator it, std::ostringstream &str, const std::string &preamble_string, bool for_embedding=false, bool strip_code=false, std::string title="")
Definition: DataCell.cc:156
cadabra::DataCell::CellType::image_png
output: cell showing a base64 encoded PNG image
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1045
cadabra::DataCell::CellType::python
input : editor cell for code in python
cadabra::export_as_LaTeX
std::string export_as_LaTeX(const DTree &doc, const std::string &image_file_base)
Export a document to a single self-contained LaTeX file, with the exception of images which get saved...
Definition: DataCell.cc:482
cadabra::DataCell::CellType
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition: DataCell.hh:34
cadabra::latex_to_html
std::string latex_to_html(const std::string &)
Convert various LaTeX constructions to HTML-with-Mathjax, e.g.
Definition: DataCell.cc:74
cadabra::DataCell::textbuf
std::string textbuf
Textual representation of the cell content.
Definition: DataCell.hh:81
cadabra::DataCell::id_t::operator<
bool operator<(const id_t &other) const
Definition: DataCell.cc:16
cadabra::DataCell::id_t
Each cell is identified by a serial number 'id' which is used to keep track of it across network call...
Definition: DataCell.hh:51
cadabra::export_as_python
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:610
cadabra::DataCell::serial_number
id_t serial_number
Definition: DataCell.hh:100
cadabra::JSON_recurse
void JSON_recurse(const DTree &, DTree::iterator, Json::Value &)
Definition: DataCell.cc:283
cadabra::DataCell::id
id_t id() const
Definition: DataCell.cc:477
cadabra::DataCell::CellType::latex_view
output: cell showing LaTeX text formatted using LaTeX