Cadabra
Computer algebra system for field theory problems
DocumentThread.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <queue>
5 #include <mutex>
6 #include <stack>
7 #include <map>
8 
9 #include "DataCell.hh"
10 #include "tree.hh"
11 
12 namespace cadabra {
13 
14  class ActionBase;
15  class ActionAddCell;
16  class ActionPositionCursor;
17  class ActionRemoveCell;
18  class ActionSetRunStatus;
19  class ActionSplitCell;
20  class ActionInsertText;
21  class ActionCompleteText;
22  class ActionEraseText;
23  class ComputeThread;
24  class GUIBase;
25 
38 
39 
41  public:
43 
47 
48  DocumentThread(const DocumentThread&)=delete;
49 
53 
54  virtual void set_compute_thread(ComputeThread *);
55 
60 
62 
68 
69  void queue_action(std::shared_ptr<ActionBase>);
70 
72 
73  void new_document();
74 
78 
79  void load_from_string(const std::string&);
80 
81  virtual void on_interactive_output(const nlohmann::json& msg);
82 
84  void undo();
85 
87  std::pair<DTree::iterator, size_t> find_string(DTree::iterator start_it, size_t start_pos, const std::string& f, bool case_ins) const;
88 
89  friend ActionBase;
90  friend ActionAddCell;
98 
99  class Prefs {
100  public:
101  using ColorMap = std::map<std::string, std::string>;
102  Prefs(bool use_defaults = false);
103  void save();
105  bool highlight;
108  std::map<std::string, ColorMap> colours;
109  std::string git_path;
110  std::string python_path;
113  private:
114  nlohmann::json data;
115  std::string config_path;
116  };
118 
121 
122  void set_user_details(const std::string& name, const std::string& email, const std::string& affiliation);
123 
124  protected:
127 
133 
135 
141 
142  std::mutex stack_mutex;
143  typedef std::stack<std::shared_ptr<ActionBase> > ActionStack;
145  std::queue<std::shared_ptr<ActionBase> > pending_actions;
147 
150 
151  void process_action_queue();
152 
153 
154 
156  enum class help_t { algorithm, property, latex, none };
157  bool help_type_and_topic(const std::string& before, const std::string& after,
158  help_t& help_type, std::string& help_topic) const;
159 
160  };
161 
162  }
friend ActionCompleteText
Definition: DocumentThread.hh:96
DocumentThread(GUIBase *)
Definition: DocumentThread.cc:24
Abstract base class with methods that need to be implemented by any GUI.
Definition: GUIBase.hh:16
ComputeThread * compute
Definition: DocumentThread.hh:126
GUIBase * gui
Definition: DocumentThread.hh:125
Prefs(bool use_defaults=false)
Definition: DocumentThread.cc:197
bool is_anonymous
Definition: DocumentThread.hh:107
std::pair< DTree::iterator, size_t > find_string(DTree::iterator start_it, size_t start_pos, const std::string &f, bool case_ins) const
Find string, return match, or a (doc.end(), std::string::npos).
Definition: DocumentThread.cc:137
A base class with all the logic to manipulate a Cadabra notebook document.
Definition: DocumentThread.hh:40
help_t
Help system.
Definition: DocumentThread.hh:156
std::string config_path
Definition: DocumentThread.hh:115
void save()
Definition: DocumentThread.cc:275
bool is_registered
Definition: DocumentThread.hh:106
void new_document()
Setup an empty new document with a single Python input cell.
Definition: DocumentThread.cc:47
const char email[]
Definition: Snoop.hh:340
void process_action_queue()
Process the action queue.
Definition: DocumentThread.cc:167
void build_visual_representation()
Ensure that the gui has an up-to-date representation of the dtree.
Definition: DocumentThread.cc:101
std::string python_path
Definition: DocumentThread.hh:110
friend ActionRemoveCell
Definition: DocumentThread.hh:92
ActionStack undo_stack
Definition: DocumentThread.hh:144
void undo()
One undo step.
Definition: DocumentThread.cc:80
friend ActionAddCell
Definition: DocumentThread.hh:90
bool tab_completion
Definition: DocumentThread.hh:112
std::stack< std::shared_ptr< ActionBase > > ActionStack
Definition: DocumentThread.hh:143
friend ActionEraseText
Definition: DocumentThread.hh:97
friend ActionInsertText
Definition: DocumentThread.hh:95
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
Prefs prefs
Definition: DocumentThread.hh:117
std::queue< std::shared_ptr< ActionBase > > pending_actions
Definition: DocumentThread.hh:145
friend ActionSplitCell
Definition: DocumentThread.hh:93
bool highlight
Definition: DocumentThread.hh:105
virtual void on_interactive_output(const nlohmann::json &msg)
Definition: DocumentThread.cc:37
void queue_action(std::shared_ptr< ActionBase >)
All changes to the document should be made by submitting ActionBase derived objects to the &#39;queue_act...
Definition: DocumentThread.cc:160
virtual void set_compute_thread(ComputeThread *)
Let the notebook know about the ComputeThread so that it can send cells for evaluation.
Definition: DocumentThread.cc:42
DTree doc
The actual document tree.
Definition: DocumentThread.hh:134
std::mutex stack_mutex
The action undo/redo/todo stacks and logic to execute them.
Definition: DocumentThread.hh:142
std::map< std::string, std::string > ColorMap
Definition: DocumentThread.hh:101
bool disable_stacks
Definition: DocumentThread.hh:146
void load_from_string(const std::string &)
Load a new notebook from a JSON string.
Definition: DocumentThread.cc:70
friend ActionSetRunStatus
Definition: DocumentThread.hh:94
tree< DataCell > DTree
Definition: DataCell.hh:108
friend ActionBase
Definition: DocumentThread.hh:89
void set_user_details(const std::string &name, const std::string &email, const std::string &affiliation)
Set user details which will be sent to the Cadabra log server.
Definition: DocumentThread.cc:297
Base class which talks to the server and sends Action objects back to the DocumentThread.
Definition: ComputeThread.hh:35
ActionStack redo_stack
Definition: DocumentThread.hh:144
friend ActionPositionCursor
Definition: DocumentThread.hh:91
std::string git_path
Definition: DocumentThread.hh:109
std::map< std::string, ColorMap > colours
Definition: DocumentThread.hh:108
nlohmann::json data
Definition: DocumentThread.hh:114
Definition: DocumentThread.hh:99
bool help_type_and_topic(const std::string &before, const std::string &after, help_t &help_type, std::string &help_topic) const
Definition: DocumentThread.cc:306
bool move_into_new_cell
Definition: DocumentThread.hh:111
int font_step
Definition: DocumentThread.hh:104