GiNaC 1.8.10
print.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2026 Johannes Gutenberg University Mainz, Germany
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef GINAC_PRINT_H
23#define GINAC_PRINT_H
24
25#include "class_info.h"
26
27#include <iosfwd>
28#include <memory>
29
30namespace GiNaC {
31
34public:
35 print_context_options(const char *n, const char *p, unsigned i)
36 : name(n), parent_name(p), id(i) {}
37
38 const char *get_name() const { return name; }
39 const char *get_parent_name() const { return parent_name; }
40 unsigned get_id() const { return id; }
41
42private:
43 const char *name;
44 const char *parent_name;
45 unsigned id;
46};
47
49
50
53public:
54 enum {
56 };
57};
58
59
61#define GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
62public: \
63 friend class function_options; \
64 friend class registered_class_options; \
65 static const GiNaC::print_context_class_info &get_class_info_static(); \
66 classname();
67
68#define GINAC_DECLARE_PRINT_CONTEXT_BASE(classname) \
69 GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
70 virtual const GiNaC::print_context_class_info &get_class_info() const { return classname::get_class_info_static(); } \
71 virtual const char *class_name() const { return classname::get_class_info_static().options.get_name(); } \
72 virtual classname * duplicate() const { return new classname(*this); } \
73private:
74
79#define GINAC_DECLARE_PRINT_CONTEXT(classname, supername) \
80 GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
81 typedef supername inherited; \
82 const GiNaC::print_context_class_info &get_class_info() const override { return classname::get_class_info_static(); } \
83 const char *class_name() const override { return classname::get_class_info_static().options.get_name(); } \
84 classname * duplicate() const override { return new classname(*this); } \
85private:
86
88#define GINAC_IMPLEMENT_PRINT_CONTEXT(classname, supername) \
89const GiNaC::print_context_class_info &classname::get_class_info_static() \
90{ \
91 static GiNaC::print_context_class_info reg_info = GiNaC::print_context_class_info(GiNaC::print_context_options(#classname, #supername, GiNaC::next_print_context_id++)); \
92 return reg_info; \
93}
94
95
96extern unsigned next_print_context_id;
97
98
101{
103public:
104 print_context(std::ostream &, unsigned options = 0);
105 virtual ~print_context() {}
106
107 std::ostream & s;
108 unsigned options;
109};
110
113{
115public:
116 print_dflt(std::ostream &, unsigned options = 0);
117};
118
121{
123public:
124 print_latex(std::ostream &, unsigned options = 0);
125};
126
129{
131public:
132 print_python(std::ostream &, unsigned options = 0);
133};
134
137{
139public:
140 print_python_repr(std::ostream &, unsigned options = 0);
141};
142
145{
147public:
148 print_tree(unsigned d);
149 print_tree(std::ostream &, unsigned options = 0, unsigned d = 4);
150
151 const unsigned delta_indent;
152};
153
156{
158public:
159 print_csrc(std::ostream &, unsigned options = 0);
160};
161
164{
166public:
167 print_csrc_float(std::ostream &, unsigned options = 0);
168};
169
172{
174public:
175 print_csrc_double(std::ostream &, unsigned options = 0);
176};
177
180{
182public:
183 print_csrc_cl_N(std::ostream &, unsigned options = 0);
184};
185
187template <class T>
188inline bool is_a(const print_context & obj)
189{ return dynamic_cast<const T *>(&obj) != nullptr; }
190
191
192class basic;
193
196public:
198 virtual print_functor_impl *duplicate() const = 0;
199 virtual void operator()(const basic & obj, const print_context & c, unsigned level) const = 0;
200};
201
203template <class T, class C>
205public:
206 typedef void (*F)(const T &, const C &, unsigned);
207
209 print_ptrfun_handler *duplicate() const override { return new print_ptrfun_handler(*this); }
210
211 void operator()(const basic & obj, const print_context & c, unsigned level) const override
212 {
213 // Call the supplied function
214 f(dynamic_cast<const T &>(obj), dynamic_cast<const C &>(c), level);
215 }
216
217private:
219};
220
222template <class T, class C>
224public:
225 typedef void (T::*F)(const C & c, unsigned level) const;
226
228 print_memfun_handler *duplicate() const override { return new print_memfun_handler(*this); }
229
230 void operator()(const basic & obj, const print_context & c, unsigned level) const override
231 {
232 // Call the supplied member function
233 return (dynamic_cast<const T &>(obj).*f)(dynamic_cast<const C &>(c), level);
234 }
235
236private:
238};
239
247public:
248 print_functor() : impl(nullptr) {}
249 print_functor(const print_functor & other) : impl(other.impl.get() ? other.impl->duplicate() : 0) {}
250 print_functor(std::unique_ptr<print_functor_impl> impl_) : impl(std::move(impl_)) {}
251
252 template <class T, class C>
253 print_functor(void f(const T &, const C &, unsigned)) : impl(new print_ptrfun_handler<T, C>(f)) {}
254
255 template <class T, class C>
256 print_functor(void (T::*f)(const C &, unsigned) const) : impl(new print_memfun_handler<T, C>(f)) {}
257
259 {
260 if (this != &other) {
261 print_functor_impl *p = other.impl.get();
262 impl.reset(p ? other.impl->duplicate() : nullptr);
263 }
264 return *this;
265 }
266
267 void operator()(const basic & obj, const print_context & c, unsigned level) const
268 {
269 (*impl)(obj, c, level);
270 }
271
272 bool is_valid() const { return impl.get(); }
273
274private:
275 std::unique_ptr<print_functor_impl> impl;
276};
277
278
279} // namespace GiNaC
280
281#endif // ndef GINAC_BASIC_H
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition basic.h:104
This class stores information about a registered print_context class.
Definition print.h:33
const char * get_parent_name() const
Definition print.h:39
const char * name
Class name.
Definition print.h:43
const char * get_name() const
Definition print.h:38
unsigned id
ID number (assigned automatically).
Definition print.h:45
print_context_options(const char *n, const char *p, unsigned i)
Definition print.h:35
unsigned get_id() const
Definition print.h:40
const char * parent_name
Name of superclass.
Definition print.h:44
Base class for print_contexts.
Definition print.h:101
unsigned options
option flags
Definition print.h:108
std::ostream & s
stream to output to
Definition print.h:107
virtual ~print_context()
Definition print.h:105
Context for C source output using CLN numbers.
Definition print.h:180
Context for C source output using double precision.
Definition print.h:172
Context for C source output using float precision.
Definition print.h:164
Base context for C source output.
Definition print.h:156
Context for default (ginsh-parsable) output.
Definition print.h:113
Base class for print_functor handlers.
Definition print.h:195
virtual ~print_functor_impl()
Definition print.h:197
virtual print_functor_impl * duplicate() const =0
virtual void operator()(const basic &obj, const print_context &c, unsigned level) const =0
This class represents a print method for a certain algebraic class and print_context type.
Definition print.h:246
print_functor(void f(const T &, const C &, unsigned))
Definition print.h:253
print_functor(const print_functor &other)
Definition print.h:249
bool is_valid() const
Definition print.h:272
void operator()(const basic &obj, const print_context &c, unsigned level) const
Definition print.h:267
print_functor(void(T::*f)(const C &, unsigned) const)
Definition print.h:256
std::unique_ptr< print_functor_impl > impl
Definition print.h:275
print_functor(std::unique_ptr< print_functor_impl > impl_)
Definition print.h:250
print_functor & operator=(const print_functor &other)
Definition print.h:258
Context for latex-parsable output.
Definition print.h:121
print_functor handler for member functions of class T, context type C
Definition print.h:223
void(T::* F)(const C &c, unsigned level) const
Definition print.h:225
print_memfun_handler * duplicate() const override
Definition print.h:228
void operator()(const basic &obj, const print_context &c, unsigned level) const override
Definition print.h:230
Flags to control the behavior of a print_context.
Definition print.h:52
@ print_index_dimensions
print the dimensions of indices
Definition print.h:55
print_functor handler for pointer-to-functions of class T, context type C
Definition print.h:204
print_ptrfun_handler * duplicate() const override
Definition print.h:209
void operator()(const basic &obj, const print_context &c, unsigned level) const override
Definition print.h:211
void(* F)(const T &, const C &, unsigned)
Definition print.h:206
Context for python-parsable output.
Definition print.h:137
Context for python pretty-print output.
Definition print.h:129
Context for tree-like output for debugging.
Definition print.h:145
const unsigned delta_indent
size of indentation step
Definition print.h:151
Helper templates to provide per-class information for class hierarchies.
size_t n
Definition factor.cpp:1431
size_t c
Definition factor.cpp:756
Definition add.cpp:35
unsigned next_print_context_id
Next free ID for print_context types.
Definition print.cpp:29
bool is_a(const basic &obj)
Check if obj is a T, including base classes.
Definition basic.h:312
class_info< print_context_options > print_context_class_info
Definition print.h:48
Definition ex.h:987
#define GINAC_DECLARE_PRINT_CONTEXT_BASE(classname)
Definition print.h:68
#define GINAC_DECLARE_PRINT_CONTEXT(classname, supername)
Macro for inclusion in the declaration of a print_context class.
Definition print.h:79

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.