Cadabra
Computer algebra system for field theory problems
DisplayBase.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <sstream>
5 #include "Props.hh"
6 #include "Storage.hh"
7 
8 namespace cadabra {
9 
18 
19  class DisplayBase {
20  public:
21  DisplayBase(const Kernel&, const Ex&);
22 
23  void output(std::ostream&);
24  void output(std::ostream&, Ex::iterator);
25 
26  virtual void dispatch(std::ostream&, Ex::iterator)=0;
27 
28  protected:
34 
35  virtual bool needs_brackets(Ex::iterator it)=0;
36 
37  const Ex& tree;
38  const Kernel& kernel;
39 
40  };
41 
42  template <typename DisplayType> std::string ex_to_string(const Kernel& kernel, const Ex& ex)
43  {
44  std::ostringstream ss;
45  DisplayType dt(kernel, ex);
46  dt.output(ss);
47  return ss.str();
48  }
49 
50  template <typename DisplayType> std::string ex_to_string(const Kernel& kernel, Ex::iterator it)
51  {
52  return ex_to_string<DisplayType>(kernel, Ex(it));
53  }
54 
55 
56  }
Base class for all display classes.
Definition: DisplayBase.hh:19
virtual bool needs_brackets(Ex::iterator it)=0
Determine if a node needs extra brackets around it.
const Kernel & kernel
Definition: DisplayBase.hh:38
DisplayBase(const Kernel &, const Ex &)
Definition: DisplayBase.cc:6
const Ex & tree
Definition: DisplayBase.hh:37
void output(std::ostream &)
Definition: DisplayBase.cc:11
virtual void dispatch(std::ostream &, Ex::iterator)=0
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:142
Definition: Kernel.hh:15
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
std::string ex_to_string(const Kernel &kernel, const Ex &ex)
Definition: DisplayBase.hh:42