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 "py_ex.hh"
10 #include "py_kernel.hh"
11 #include "py_tableau.hh"
12 #include "properties/LaTeXForm.hh"
13 
14 namespace cadabra {
16  : public std::enable_shared_from_this<BoundPropertyBase>
17  {
18  public:
21  virtual ~BoundPropertyBase();
22 
24  std::string str_() const;
26  std::string latex_() const;
28  std::string repr_() const;
29 
30  static Kernel& get_kernel();
31  static Properties& get_props();
32  Ex& get_ex() const;
33  Ex::iterator get_it() const;
34 
35  // We keep a pointer to the C++ property, so it is possible to
36  // query properties using the Python interface. However, this C++
37  // object is owned by the C++ kernel and does not get destroyed
38  // when the Python object goes out of scope.
39  const property* prop;
40 
41  // We also keep a shared pointer to the expression for which we
42  // have defined this property, so that we can print sensible
43  // information.
45  };
46 
47 
48  template <typename PropT, typename... ParentTs>
50  : virtual public ParentTs...
51  {
52  public:
53  using cpp_type = PropT;
54  using py_type = pybind11::class_<BoundProperty, std::shared_ptr<BoundProperty>, ParentTs...>;
55 
56  // Default construct with null pointers
57  BoundProperty();
58  // Construct new property from expression and argument list
59  BoundProperty(Ex_ptr ex, Ex_ptr param);
60  // Construct from existing cpp property object
61  BoundProperty(const PropT* prop, Ex_ptr for_obj);
62 
64  std::string str_() const;
66  std::string latex_() const;
68  std::string repr_() const;
70  void attach(Ex_ptr ex) const;
71 
72  // Get existing cpp property by querying kernel
73  static std::shared_ptr<BoundProperty> get_from_kernel(Ex::iterator ex, const std::string& label, bool ignore_parent_rel);
74 
75  // Return type is not the same as BoundPropertyBase, but this is ok
76  // by the standard as cpp_type* is convertible to property*
77  const cpp_type* get_prop() const;
78  };
79 
80  template <typename PropT> std::string get_name();
81 
82  template <typename BoundPropT> typename BoundPropT::py_type def_abstract_prop(pybind11::module& m);
83  template <typename BoundPropT> typename BoundPropT::py_type def_prop(pybind11::module& m);
84 
85  pybind11::list list_properties();
86 
87  void init_properties(pybind11::module& m);
88 
89  }
std::string str_() const
Human-readable form in text, i.e. no special formatting.
Definition: py_properties.cc:203
std::string get_name()
virtual ~BoundPropertyBase()
Definition: py_properties.cc:76
BoundProperty()
Definition: py_properties.cc:142
Definition: py_properties.hh:49
Ex_ptr for_obj
Definition: py_properties.hh:44
std::string repr_() const
Python-parseable form. FIXME: not correct right now.
Definition: py_properties.cc:114
Ex::iterator get_it() const
Definition: py_properties.cc:135
Definition: py_properties.hh:15
Definition: Kernel.hh:14
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:140
static Properties & get_props()
Definition: py_properties.cc:125
BoundPropertyBase()
Definition: py_properties.cc:62
static Kernel & get_kernel()
Definition: py_properties.cc:120
std::shared_ptr< Ex > Ex_ptr
Definition: py_ex.hh:9
void attach(Ex_ptr ex) const
Attach this property to a different symbol.
Definition: py_properties.cc:191
Base class for all properties, handling argument parsing and defining the interface.
Definition: Props.hh:126
std::string str_() const
Human-readable form in text, i.e. no special formatting.
Definition: py_properties.cc:81
static std::shared_ptr< BoundProperty > get_from_kernel(Ex::iterator ex, const std::string &label, bool ignore_parent_rel)
Definition: py_properties.cc:166
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
const property * prop
Definition: py_properties.hh:39
void init_properties(py::module &m)
Definition: py_properties.cc:307
BoundPropT::py_type def_prop(pybind11::module &m)
Definition: py_properties.cc:237
std::string repr_() const
Python-parseable form. FIXME: not correct right now.
Definition: py_properties.cc:215
std::string latex_() const
Human-readable form using LaTeX markup.
Definition: py_properties.cc:209
pybind11::list list_properties()
Definition: py_properties.cc:257
pybind11::class_< BoundProperty, std::shared_ptr< BoundProperty >, ParentTs... > py_type
Definition: py_properties.hh:54
std::string latex_() const
Human-readable form using LaTeX markup.
Definition: py_properties.cc:91
PropT cpp_type
Definition: py_properties.hh:53
Class holding a collection of properties attached to expressions.
Definition: Props.hh:233
const cpp_type * get_prop() const
Definition: py_properties.cc:185
BoundPropT::py_type def_abstract_prop(pybind11::module &m, const std::string &name)
Definition: py_properties.cc:221
Ex & get_ex() const
Definition: py_properties.cc:130