Cadabra
Computer algebra system for field theory problems
py_properties.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <tuple>
5 #include <sstream>
6 #include <regex>
7 #include <memory>
8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include "py_ex.hh"
11 #include "py_kernel.hh"
12 #include "py_tableau.hh"
13 #include "properties/LaTeXForm.hh"
14 
15 namespace cadabra {
17  : public std::enable_shared_from_this<BoundPropertyBase>
18  {
19  public:
22  virtual ~BoundPropertyBase();
23 
25  std::string str_() const;
27  std::string latex_() const;
29  std::string repr_() const;
30 
31  static Kernel& get_kernel();
32  static Properties& get_props();
33  Ex& get_ex() const;
34  Ex::iterator get_it() const;
35 
36  // We keep a pointer to the C++ property, so it is possible to
37  // query properties using the Python interface. However, this C++
38  // object is owned by the C++ kernel and does not get destroyed
39  // when the Python object goes out of scope.
40  const property* prop;
41 
42  // We also keep a shared pointer to the expression for which we
43  // have defined this property, so that we can print sensible
44  // information.
46  };
47 
48 
49  template <typename PropT, typename... ParentTs>
51  : virtual public ParentTs...
52  {
53  public:
54  using cpp_type = PropT;
55  using py_type = pybind11::class_<BoundProperty, std::shared_ptr<BoundProperty>, ParentTs...>;
56 
57  // Default construct with null pointers
58  BoundProperty();
59  // Construct new property from expression and argument list
60  BoundProperty(Ex_ptr ex, Ex_ptr param);
61  // Construct from existing cpp property object
62  BoundProperty(const PropT* prop, Ex_ptr for_obj);
63 
65  std::string str_() const;
67  std::string latex_() const;
69  std::string repr_() const;
71  void attach(Ex_ptr ex) const;
72 
73  // Get existing cpp property by querying kernel
74  static std::shared_ptr<BoundProperty> get_from_kernel(Ex::iterator ex, const std::string& label, bool ignore_parent_rel);
75 
76  // Return type is not the same as BoundPropertyBase, but this is ok
77  // by the standard as cpp_type* is convertible to property*
78  const cpp_type* get_prop() const;
79  };
80 
81  template <typename PropT> std::string get_name();
82 
83  template <typename BoundPropT> typename BoundPropT::py_type def_abstract_prop(pybind11::module& m);
84  template <typename BoundPropT> typename BoundPropT::py_type def_prop(pybind11::module& m);
85 
86  pybind11::list list_properties();
87 
88  void init_properties(pybind11::module& m);
89 
90  }
cadabra::BoundProperty::get_prop
const cpp_type * get_prop() const
Definition: py_properties.cc:185
cadabra::BoundPropertyBase::get_it
Ex::iterator get_it() const
Definition: py_properties.cc:135
cadabra::get_name
std::string get_name()
cadabra::BoundPropertyBase::get_ex
Ex & get_ex() const
Definition: py_properties.cc:130
cadabra::Kernel
Definition: Kernel.hh:15
cadabra::BoundPropertyBase::~BoundPropertyBase
virtual ~BoundPropertyBase()
Definition: py_properties.cc:76
cadabra::BoundPropertyBase::str_
std::string str_() const
Human-readable form in text, i.e. no special formatting.
Definition: py_properties.cc:81
cadabra::BoundProperty::get_from_kernel
static std::shared_ptr< BoundProperty > get_from_kernel(Ex::iterator ex, const std::string &label, bool ignore_parent_rel)
Definition: py_properties.cc:166
cadabra::BoundPropertyBase::get_props
static Properties & get_props()
Definition: py_properties.cc:125
cadabra::BoundProperty::str_
std::string str_() const
Human-readable form in text, i.e. no special formatting.
Definition: py_properties.cc:203
cadabra::BoundProperty::attach
void attach(Ex_ptr ex) const
Attach this property to a different symbol.
Definition: py_properties.cc:191
cadabra::BoundPropertyBase::for_obj
Ex_ptr for_obj
Definition: py_properties.hh:45
cadabra::BoundProperty::latex_
std::string latex_() const
Human-readable form using LaTeX markup.
Definition: py_properties.cc:209
cadabra::BoundPropertyBase::prop
const property * prop
Definition: py_properties.hh:40
cadabra::Properties
Definition: Props.hh:234
cadabra::Ex_ptr
std::shared_ptr< Ex > Ex_ptr
Definition: py_ex.hh:9
py_ex.hh
cadabra::BoundProperty::cpp_type
PropT cpp_type
Definition: py_properties.hh:54
cadabra::property
FIXME: the above two need to be merged, because parse may need access to the actual pattern tree,...
Definition: Props.hh:127
cadabra::list_properties
pybind11::list list_properties()
Definition: py_properties.cc:257
cadabra::BoundPropertyBase
Definition: py_properties.hh:16
cadabra::BoundProperty
Definition: py_properties.hh:50
cadabra::BoundPropertyBase::BoundPropertyBase
BoundPropertyBase()
Definition: py_properties.cc:62
cadabra::BoundPropertyBase::get_kernel
static Kernel & get_kernel()
Definition: py_properties.cc:120
cadabra::BoundPropertyBase::repr_
std::string repr_() const
Python-parseable form. FIXME: not correct right now.
Definition: py_properties.cc:114
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
cadabra::Ex
Definition: Storage.hh:141
cadabra::init_properties
void init_properties(py::module &m)
Definition: py_properties.cc:328
cadabra::def_prop
BoundPropT::py_type def_prop(pybind11::module &m)
Definition: py_properties.cc:237
cadabra::BoundProperty::repr_
std::string repr_() const
Python-parseable form. FIXME: not correct right now.
Definition: py_properties.cc:215
LaTeXForm.hh
cadabra::BoundProperty::py_type
pybind11::class_< BoundProperty, std::shared_ptr< BoundProperty >, ParentTs... > py_type
Definition: py_properties.hh:55
cadabra::def_abstract_prop
BoundPropT::py_type def_abstract_prop(pybind11::module &m, const std::string &name)
Definition: py_properties.cc:221
py_tableau.hh
py_kernel.hh
cadabra::BoundProperty::BoundProperty
BoundProperty()
Definition: py_properties.cc:142
cadabra::BoundPropertyBase::latex_
std::string latex_() const
Human-readable form using LaTeX markup.
Definition: py_properties.cc:91