Re: GiNaC/doc/tutorial ginac.texi
On Mon, 9 Apr 2001, Christian Bauer wrote:
- added examples for specialized expression output by tree-traversal and with the aid of archives
These examples are very useful for understanding GiNaC archive stuff for GiNaC beginners like me. Thanks! However, I might have found even simpler way to extract protected attributes. Take, for example, indexed class that has protected attribute `seq'. It can be read outside of the indexed class as follows: class wrap_indexed: public indexed { public: const exvector & get_seq(void) const { return this->seq; } }; void somefunction (const indexed & obj) { const exvector & seq = ((const wrap_indexed &)obj).get_seq(); /* Use `seq' for something */ } Unfortunately it will not work for private attributes, of course. Is there any reason why minkmetric::pos_sig color::representation_label tensepsilon::minkowski could not be protected? Are they archived attributes? Regards, Pearu
On Mon, 9 Apr 2001, Pearu Peterson wrote:
On Mon, 9 Apr 2001, Christian Bauer wrote:
- added examples for specialized expression output by tree-traversal and with the aid of archives
These examples are very useful for understanding GiNaC archive stuff for GiNaC beginners like me. Thanks!
However, I might have found even simpler way to extract protected attributes. Take, for example, indexed class that has protected attribute `seq'. It can be read outside of the indexed class as follows:
class wrap_indexed: public indexed { public: const exvector & get_seq(void) const { return this->seq; } };
void somefunction (const indexed & obj) { const exvector & seq = ((const wrap_indexed &)obj).get_seq(); /* Use `seq' for something */ }
<preach> Hmm, you know that you are abusing the language, don't you? As a next step step you might #define private public before #include'ing <ginac/ginac.h>. That's just scary! Better stick to the interfaces provided by the library. </preach> Regards -richy. -- Richard Kreckel <Richard.Kreckel@Uni-Mainz.DE> <http://wwwthep.physik.uni-mainz.de/~kreckel/>
On Tue, 10 Apr 2001, Richard B. Kreckel wrote:
<preach> Hmm, you know that you are abusing the language, don't you? As a next step step you might #define private public before #include'ing <ginac/ginac.h>.
:-)
That's just scary! Better stick to the interfaces provided by the library. </preach>
Agreed. I would love to stick to the libriary interface! I am sure that for an ordinary GiNaC application the interface is quite adequate. But it is not for a wrapper to another language such as Python. The reason is that I want such a wrapper to reflect GiNaC's structure to Python as close as possible. And therefore these tricks were needed. You can learn more about what was needed for a Python interface to GiNaC in the following three files that as a part of pyGiNaC implement Python str and repr functions for GiNaC objects: http://cens.ioc.ee/cgi-bin/cvsweb/python/pyGiNaC/wrappers/wrap_classes.cpp?rev=1.1&content-type=text/x-cvsweb-markup http://cens.ioc.ee/cgi-bin/cvsweb/python/pyGiNaC/wrappers/python_repr.cpp?rev=1.2&content-type=text/x-cvsweb-markup http://cens.ioc.ee/cgi-bin/cvsweb/python/pyGiNaC/wrappers/python_str.cpp?rev=1.2&content-type=text/x-cvsweb-markup Regards, Pearu
participants (2)
-
Pearu Peterson
-
Richard B. Kreckel