Cadabra
Computer algebra system for field theory problems
PythonCdb.hh
Go to the documentation of this file.
1 /*
2 
3  Cadabra: a field-theory motivated computer algebra system.
4  Copyright (C) 2001-2014 Kasper Peeters <kasper.peeters@phi-sci.com>
5 
6  This program is free software: you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation, either version 3 of the
9  License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #pragma once
22 
23 #include <boost/python.hpp>
24 #include <stdexcept>
25 #include "Storage.hh"
26 #include "Kernel.hh"
27 #include "Algorithm.hh"
28 
34 
35 bool __eq__Ex_Ex(const cadabra::Ex&, const cadabra::Ex&);
36 
40 
41 bool __eq__Ex_int(const cadabra::Ex&, int);
42 
44 
45 std::shared_ptr<cadabra::Ex> fetch_from_python(const std::string& nm);
46 
50 
51 std::string Ex_str_(const cadabra::Ex&);
52 std::string Ex_repr_(const cadabra::Ex&);
53 
65 
66 std::string Ex_latex_(const cadabra::Ex&);
67 
77 
78 boost::python::object Ex_to_Sympy(const cadabra::Ex&);
79 
80 
84 
85 cadabra::Ex operator+(const cadabra::Ex& ex1, const cadabra::Ex& ex2);
86 
90 
91 cadabra::Ex operator-(const cadabra::Ex& ex1, const cadabra::Ex& ex2);
92 
97 
98 class BaseProperty {
99 };
100 
126 
127 template<class T>
128 class Property : public BaseProperty {
129  public:
130  Property(std::shared_ptr<cadabra::Ex> obj, std::shared_ptr<cadabra::Ex> params=0);
131 
133  std::string str_() const;
134 
136  std::string latex_() const;
137 
139  std::string repr_() const;
140 
141 
142  private:
143  // We keep a pointer to the C++ property, so it is possible to
144  // query properties using the Python interface. However, this C++
145  // object is owned by the C++ kernel and does not get destroyed
146  // when the Python object goes out of scope.
147 
148  // When the Python object survives the local scope, results are
149  // undefined.
150  T *prop;
151 
152  // We also keep a shared pointer to the expression for which we
153  // have defined this property, so that we can print sensible
154  // information.
155  std::shared_ptr<cadabra::Ex> for_obj;
156 };
157 
158 
220 
224 
232 
234 
239 
243 
cadabra::Kernel * create_scope_from_global()
Definition: PythonCdb.cc:780
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:130
cadabra::Ex operator+(const cadabra::Ex &ex1, const cadabra::Ex &ex2)
Add two expressions, adding a top-level node if required.
Definition: PythonCdb.cc:494
bool __eq__Ex_Ex(const cadabra::Ex &, const cadabra::Ex &)
Comparison operator for Ex objects in Python.
Definition: PythonCdb.cc:391
T * prop
Definition: PythonCdb.hh:150
cadabra::Kernel * create_empty_scope()
Definition: PythonCdb.cc:787
cadabra::Kernel * create_scope()
Setup of kernels in current scope, callable from Python.
Definition: PythonCdb.cc:773
cadabra::Ex operator-(const cadabra::Ex &ex1, const cadabra::Ex &ex2)
Subtract two expressions, adding a top-level node if required.
Definition: PythonCdb.cc:530
std::string Ex_latex_(const cadabra::Ex &)
The Python &#39;print&#39; function always calls the &#39;str&#39; member on objects to be printed.
Definition: PythonCdb.cc:308
std::string Ex_str_(const cadabra::Ex &)
Generate the Python str() and repr() representation of the Ex object.
Definition: PythonCdb.cc:294
cadabra::Kernel * get_kernel_from_scope()
Get a pointer to the currently visible kernel.
Definition: PythonCdb.cc:724
void call_post_process(cadabra::Kernel &, cadabra::Ex &ex)
Run the post-process Python function (if defined) on the given expression.
Definition: PythonCdb.cc:957
std::shared_ptr< cadabra::Ex > fetch_from_python(const std::string &nm)
Fetch an Ex object from the Python side using its Python identifier.
Definition: PythonCdb.cc:348
boost::python::object Ex_to_Sympy(const cadabra::Ex &)
Convert a Cadabra &#39;Ex&#39; to a Sympy expression.
Definition: PythonCdb.cc:324
Helper class to ensure that all Python property objects derive from the same base class...
Definition: PythonCdb.hh:98
Property is a templated wrapper around a C++ property object.
Definition: PythonCdb.hh:128
std::shared_ptr< cadabra::Ex > for_obj
Definition: PythonCdb.hh:155
Definition: Kernel.hh:15
void inject_defaults(cadabra::Kernel *)
Inject properties directly into the Kernel, even if the kernel is not yet on the Python stack (needed...
Definition: PythonCdb.cc:793
std::string Ex_repr_(const cadabra::Ex &)
Definition: PythonCdb.cc:316
bool __eq__Ex_int(const cadabra::Ex &, int)
Comparison operator for Ex objects in Python.
Definition: PythonCdb.cc:396