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  }
cadabra::Kernel
Definition: Kernel.hh:15
cadabra::DisplayBase::dispatch
virtual void dispatch(std::ostream &, Ex::iterator)=0
Storage.hh
cadabra::DisplayBase::output
void output(std::ostream &)
Definition: DisplayBase.cc:11
Props.hh
cadabra::DisplayBase::needs_brackets
virtual bool needs_brackets(Ex::iterator it)=0
Determine if a node needs extra brackets around it.
cadabra::DisplayBase::DisplayBase
DisplayBase(const Kernel &, const Ex &)
Definition: DisplayBase.cc:6
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
cadabra::Ex
Definition: Storage.hh:140
cadabra::DisplayBase::tree
const Ex & tree
Definition: DisplayBase.hh:37
cadabra::DisplayBase::kernel
const Kernel & kernel
Definition: DisplayBase.hh:38
cadabra::DisplayBase
Definition: DisplayBase.hh:19
cadabra::ex_to_string
std::string ex_to_string(const Kernel &kernel, const Ex &ex)
Definition: DisplayBase.hh:42