GiNaC 1.8.8
print.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2025 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, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef GINAC_PRINT_H
24#define GINAC_PRINT_H
25
26#include "class_info.h"
27
28#include <iosfwd>
29#include <memory>
30
31namespace GiNaC {
32
35public:
36 print_context_options(const char *n, const char *p, unsigned i)
37 : name(n), parent_name(p), id(i) {}
38
39 const char *get_name() const { return name; }
40 const char *get_parent_name() const { return parent_name; }
41 unsigned get_id() const { return id; }
42
43private:
44 const char *name;
45 const char *parent_name;
46 unsigned id;
47};
48
50
51
54public:
55 enum {
57 };
58};
59
60
62#define GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
63public: \
64 friend class function_options; \
65 friend class registered_class_options; \
66 static const GiNaC::print_context_class_info &get_class_info_static(); \
67 classname();
68
69#define GINAC_DECLARE_PRINT_CONTEXT_BASE(classname) \
70 GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
71 virtual const GiNaC::print_context_class_info &get_class_info() const { return classname::get_class_info_static(); } \
72 virtual const char *class_name() const { return classname::get_class_info_static().options.get_name(); } \
73 virtual classname * duplicate() const { return new classname(*this); } \
74private:
75
80#define GINAC_DECLARE_PRINT_CONTEXT(classname, supername) \
81 GINAC_DECLARE_PRINT_CONTEXT_COMMON(classname) \
82 typedef supername inherited; \
83 const GiNaC::print_context_class_info &get_class_info() const override { return classname::get_class_info_static(); } \
84 const char *class_name() const override { return classname::get_class_info_static().options.get_name(); } \
85 classname * duplicate() const override { return new classname(*this); } \
86private:
87
89#define GINAC_IMPLEMENT_PRINT_CONTEXT(classname, supername) \
90const GiNaC::print_context_class_info &classname::get_class_info_static() \
91{ \
92 static GiNaC::print_context_class_info reg_info = GiNaC::print_context_class_info(GiNaC::print_context_options(#classname, #supername, GiNaC::next_print_context_id++)); \
93 return reg_info; \
94}
95
96
97extern unsigned next_print_context_id;
98
99
102{
104public:
105 print_context(std::ostream &, unsigned options = 0);
106 virtual ~print_context() {}
107
108 std::ostream & s;
109 unsigned options;
110};
111
114{
116public:
117 print_dflt(std::ostream &, unsigned options = 0);
118};
119
122{
124public:
125 print_latex(std::ostream &, unsigned options = 0);
126};
127
130{
132public:
133 print_python(std::ostream &, unsigned options = 0);
134};
135
138{
140public:
141 print_python_repr(std::ostream &, unsigned options = 0);
142};
143
146{
148public:
149 print_tree(unsigned d);
150 print_tree(std::ostream &, unsigned options = 0, unsigned d = 4);
151
152 const unsigned delta_indent;
153};
154
157{
159public:
160 print_csrc(std::ostream &, unsigned options = 0);
161};
162
165{
167public:
168 print_csrc_float(std::ostream &, unsigned options = 0);
169};
170
173{
175public:
176 print_csrc_double(std::ostream &, unsigned options = 0);
177};
178
181{
183public:
184 print_csrc_cl_N(std::ostream &, unsigned options = 0);
185};
186
188template <class T>
189inline bool is_a(const print_context & obj)
190{ return dynamic_cast<const T *>(&obj) != nullptr; }
191
192
193class basic;
194
197public:
199 virtual print_functor_impl *duplicate() const = 0;
200 virtual void operator()(const basic & obj, const print_context & c, unsigned level) const = 0;
201};
202
204template <class T, class C>
206public:
207 typedef void (*F)(const T &, const C &, unsigned);
208
210 print_ptrfun_handler *duplicate() const override { return new print_ptrfun_handler(*this); }
211
212 void operator()(const basic & obj, const print_context & c, unsigned level) const override
213 {
214 // Call the supplied function
215 f(dynamic_cast<const T &>(obj), dynamic_cast<const C &>(c), level);
216 }
217
218private:
220};
221
223template <class T, class C>
225public:
226 typedef void (T::*F)(const C & c, unsigned level) const;
227
229 print_memfun_handler *duplicate() const override { return new print_memfun_handler(*this); }
230
231 void operator()(const basic & obj, const print_context & c, unsigned level) const override
232 {
233 // Call the supplied member function
234 return (dynamic_cast<const T &>(obj).*f)(dynamic_cast<const C &>(c), level);
235 }
236
237private:
239};
240
248public:
249 print_functor() : impl(nullptr) {}
250 print_functor(const print_functor & other) : impl(other.impl.get() ? other.impl->duplicate() : 0) {}
251 print_functor(std::unique_ptr<print_functor_impl> impl_) : impl(std::move(impl_)) {}
252
253 template <class T, class C>
254 print_functor(void f(const T &, const C &, unsigned)) : impl(new print_ptrfun_handler<T, C>(f)) {}
255
256 template <class T, class C>
257 print_functor(void (T::*f)(const C &, unsigned) const) : impl(new print_memfun_handler<T, C>(f)) {}
258
260 {
261 if (this != &other) {
262 print_functor_impl *p = other.impl.get();
263 impl.reset(p ? other.impl->duplicate() : nullptr);
264 }
265 return *this;
266 }
267
268 void operator()(const basic & obj, const print_context & c, unsigned level) const
269 {
270 (*impl)(obj, c, level);
271 }
272
273 bool is_valid() const { return impl.get(); }
274
275private:
276 std::unique_ptr<print_functor_impl> impl;
277};
278
279
280} // namespace GiNaC
281
282#endif // ndef GINAC_BASIC_H
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition basic.h:105
This class stores information about a registered print_context class.
Definition print.h:34
const char * get_parent_name() const
Definition print.h:40
const char * name
Class name.
Definition print.h:44
const char * get_name() const
Definition print.h:39
unsigned id
ID number (assigned automatically).
Definition print.h:46
print_context_options(const char *n, const char *p, unsigned i)
Definition print.h:36
unsigned get_id() const
Definition print.h:41
const char * parent_name
Name of superclass.
Definition print.h:45
Base class for print_contexts.
Definition print.h:102
unsigned options
option flags
Definition print.h:109
std::ostream & s
stream to output to
Definition print.h:108
virtual ~print_context()
Definition print.h:106
Context for C source output using CLN numbers.
Definition print.h:181
Context for C source output using double precision.
Definition print.h:173
Context for C source output using float precision.
Definition print.h:165
Base context for C source output.
Definition print.h:157
Context for default (ginsh-parsable) output.
Definition print.h:114
Base class for print_functor handlers.
Definition print.h:196
virtual ~print_functor_impl()
Definition print.h:198
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:247
print_functor(void f(const T &, const C &, unsigned))
Definition print.h:254
print_functor(const print_functor &other)
Definition print.h:250
bool is_valid() const
Definition print.h:273
void operator()(const basic &obj, const print_context &c, unsigned level) const
Definition print.h:268
print_functor(void(T::*f)(const C &, unsigned) const)
Definition print.h:257
std::unique_ptr< print_functor_impl > impl
Definition print.h:276
print_functor(std::unique_ptr< print_functor_impl > impl_)
Definition print.h:251
print_functor & operator=(const print_functor &other)
Definition print.h:259
Context for latex-parsable output.
Definition print.h:122
print_functor handler for member functions of class T, context type C
Definition print.h:224
void(T::* F)(const C &c, unsigned level) const
Definition print.h:226
print_memfun_handler * duplicate() const override
Definition print.h:229
void operator()(const basic &obj, const print_context &c, unsigned level) const override
Definition print.h:231
Flags to control the behavior of a print_context.
Definition print.h:53
@ print_index_dimensions
print the dimensions of indices
Definition print.h:56
print_functor handler for pointer-to-functions of class T, context type C
Definition print.h:205
print_ptrfun_handler * duplicate() const override
Definition print.h:210
void operator()(const basic &obj, const print_context &c, unsigned level) const override
Definition print.h:212
void(* F)(const T &, const C &, unsigned)
Definition print.h:207
Context for python-parsable output.
Definition print.h:138
Context for python pretty-print output.
Definition print.h:130
Context for tree-like output for debugging.
Definition print.h:146
const unsigned delta_indent
size of indentation step
Definition print.h:152
Helper templates to provide per-class information for class hierarchies.
size_t n
Definition factor.cpp:1432
size_t c
Definition factor.cpp:757
Definition add.cpp:36
unsigned next_print_context_id
Next free ID for print_context types.
Definition print.cpp:30
bool is_a(const basic &obj)
Check if obj is a T, including base classes.
Definition basic.h:313
class_info< print_context_options > print_context_class_info
Definition print.h:49
Definition ex.h:988
#define GINAC_DECLARE_PRINT_CONTEXT_BASE(classname)
Definition print.h:69
#define GINAC_DECLARE_PRINT_CONTEXT(classname, supername)
Macro for inclusion in the declaration of a print_context class.
Definition print.h:80

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