GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pr-output.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_pr_output_h)
27 #define octave_pr_output_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 
33 #include "oct-cmplx.h"
34 #include "oct-inttypes-fwd.h"
35 
36 #include "pr-flt-fmt.h"
37 
38 template <typename T> class Array;
39 class ComplexMatrix;
40 class FloatComplexMatrix;
41 class ComplexDiagMatrix;
43 class ComplexNDArray;
45 class Matrix;
46 class FloatMatrix;
47 class DiagMatrix;
48 class FloatDiagMatrix;
49 class NDArray;
50 class FloatNDArray;
51 class Range;
52 class boolMatrix;
53 class boolNDArray;
54 class charMatrix;
55 class charNDArray;
56 class PermMatrix;
57 class Cell;
58 class octave_value;
59 
60 template <typename T> class intNDArray;
61 
62 template <typename T>
64 make_format (const std::complex<T>&)
65 {
66  return float_display_format ();
67 }
68 
69 template <>
71 make_format (const std::complex<double>& c);
72 
73 template <>
75 make_format (const std::complex<float>& fc);
76 
77 template <typename T>
79 make_format (const T&)
80 {
81  return float_display_format ();
82 }
83 
84 template <>
86 make_format (const double& d);
87 
88 template <>
90 make_format (const float& f);
91 
92 template <>
94 make_format (const Range& r);
95 
96 template <>
98 make_format (const Matrix& m);
99 
100 template <>
102 make_format (const FloatMatrix& m);
103 
104 template <>
106 make_format (const ComplexMatrix& m);
107 
108 template <>
111 
112 template <>
114 make_format (const boolNDArray& nda);
115 
116 template <>
119 
120 template <>
123 
124 template <>
127 
128 template <>
131 
132 template <>
135 
136 template <>
139 
140 template <>
143 
144 template <>
147 
148 template <>
150 make_format (const octave_int8& nda);
151 
152 template <>
154 make_format (const octave_int16& nda);
155 
156 template <>
158 make_format (const octave_int32& nda);
159 
160 template <>
162 make_format (const octave_int64& nda);
163 
164 template <>
166 make_format (const octave_uint8& nda);
167 
168 template <>
170 make_format (const octave_uint16& nda);
171 
172 template <>
174 make_format (const octave_uint32& nda);
175 
176 template <>
178 make_format (const octave_uint64& nda);
179 
180 // FIXME: templates plus specializations might help here.
181 
182 extern OCTINTERP_API void
183 octave_print_internal (std::ostream& os, const float_display_format& fmt,
184  bool d, bool pr_as_read_syntax = false);
185 
186 extern OCTINTERP_API void
187 octave_print_internal (std::ostream& os, bool d,
188  bool pr_as_read_syntax = false);
189 
190 extern OCTINTERP_API void
191 octave_print_internal (std::ostream& os, const float_display_format& fmt,
192  char c, bool pr_as_read_syntax = false);
193 
194 inline void
195 octave_print_internal (std::ostream& os, char c,
196  bool pr_as_read_syntax = false)
197 {
198  float_display_format fmt (float_format (0, 0));
199  octave_print_internal (os, fmt, c, pr_as_read_syntax);
200 }
201 
202 extern OCTINTERP_API void
203 octave_print_internal (std::ostream& os, const float_display_format& fmt,
204  double d, bool pr_as_read_syntax = false);
205 
206 inline void
207 octave_print_internal (std::ostream& os, double d,
208  bool pr_as_read_syntax = false)
209 {
210  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
211 }
212 
213 extern OCTINTERP_API void
214 octave_print_internal (std::ostream& os, const float_display_format& fmt,
215  float d, bool pr_as_read_syntax = false);
216 
217 inline void
218 octave_print_internal (std::ostream& os, float d,
219  bool pr_as_read_syntax = false)
220 {
221  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
222 }
223 
224 extern OCTINTERP_API void
225 octave_print_internal (std::ostream& os, const Matrix& m,
226  bool pr_as_read_syntax = false,
227  int extra_indent = 0);
228 
229 extern OCTINTERP_API void
230 octave_print_internal (std::ostream& os, const FloatMatrix& m,
231  bool pr_as_read_syntax = false,
232  int extra_indent = 0);
233 
234 extern OCTINTERP_API void
235 octave_print_internal (std::ostream& os, const DiagMatrix& m,
236  bool pr_as_read_syntax = false,
237  int extra_indent = 0);
238 
239 extern OCTINTERP_API void
240 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
241  bool pr_as_read_syntax = false,
242  int extra_indent = 0);
243 
244 extern OCTINTERP_API void
245 octave_print_internal (std::ostream& os, const NDArray& nda,
246  bool pr_as_read_syntax = false,
247  int extra_indent = 0);
248 
249 extern OCTINTERP_API void
250 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
251  bool pr_as_read_syntax = false,
252  int extra_indent = 0);
253 
254 extern OCTINTERP_API void
255 octave_print_internal (std::ostream& os, const float_display_format& fmt,
256  const Complex& c, bool pr_as_read_syntax = false);
257 
258 inline void
259 octave_print_internal (std::ostream& os, const Complex& c,
260  bool pr_as_read_syntax = false)
261 {
262  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
263 }
264 
265 extern OCTINTERP_API void
266 octave_print_internal (std::ostream& os, const float_display_format& fmt,
267  const FloatComplex& c, bool pr_as_read_syntax = false);
268 
269 inline void
270 octave_print_internal (std::ostream& os, const FloatComplex& c,
271  bool pr_as_read_syntax = false)
272 {
273  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
274 }
275 
276 extern OCTINTERP_API void
277 octave_print_internal (std::ostream& os, const ComplexMatrix& cm,
278  bool pr_as_read_syntax = false,
279  int extra_indent = 0);
280 
281 extern OCTINTERP_API void
282 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
283  bool pr_as_read_syntax = false,
284  int extra_indent = 0);
285 
286 extern OCTINTERP_API void
287 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
288  bool pr_as_read_syntax = false,
289  int extra_indent = 0);
290 
291 extern OCTINTERP_API void
292 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm,
293  bool pr_as_read_syntax = false,
294  int extra_indent = 0);
295 
296 extern OCTINTERP_API void
297 octave_print_internal (std::ostream& os, const ComplexNDArray& nda,
298  bool pr_as_read_syntax = false,
299  int extra_indent = 0);
300 
301 extern OCTINTERP_API void
302 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
303  bool pr_as_read_syntax = false,
304  int extra_indent = 0);
305 
306 extern OCTINTERP_API void
307 octave_print_internal (std::ostream& os, const PermMatrix& m,
308  bool pr_as_read_syntax = false,
309  int extra_indent = 0);
310 
311 extern OCTINTERP_API void
312 octave_print_internal (std::ostream& os, const Range& r,
313  bool pr_as_read_syntax = false,
314  int extra_indent = 0);
315 
316 extern OCTINTERP_API void
317 octave_print_internal (std::ostream& os, const boolMatrix& m,
318  bool pr_as_read_syntax = false,
319  int extra_indent = 0);
320 
321 extern OCTINTERP_API void
322 octave_print_internal (std::ostream& os, const boolNDArray& m,
323  bool pr_as_read_syntax = false,
324  int extra_indent = 0);
325 
326 extern OCTINTERP_API void
327 octave_print_internal (std::ostream& os, const charMatrix& chm,
328  bool pr_as_read_syntax = false,
329  int extra_indent = 0,
330  bool pr_as_string = false);
331 
332 extern OCTINTERP_API void
333 octave_print_internal (std::ostream& os, const charNDArray& nda,
334  bool pr_as_read_syntax = false,
335  int extra_indent = 0,
336  bool pr_as_string = false);
337 
338 extern OCTINTERP_API void
339 octave_print_internal (std::ostream& os, const std::string& s,
340  bool pr_as_read_syntax = false,
341  int extra_indent = 0);
342 
343 extern OCTINTERP_API void
344 octave_print_internal (std::ostream& os, const Array<std::string>& sa,
345  bool pr_as_read_syntax = false,
346  int extra_indent = 0);
347 
348 extern OCTINTERP_API void
349 octave_print_internal (std::ostream& os, const intNDArray<octave_int8>& sa,
350  bool pr_as_read_syntax = false,
351  int extra_indent = 0);
352 
353 extern OCTINTERP_API void
354 octave_print_internal (std::ostream& os, const intNDArray<octave_uint8>& sa,
355  bool pr_as_read_syntax = false,
356  int extra_indent = 0);
357 
358 extern OCTINTERP_API void
359 octave_print_internal (std::ostream& os, const intNDArray<octave_int16>& sa,
360  bool pr_as_read_syntax = false,
361  int extra_indent = 0);
362 
363 extern OCTINTERP_API void
364 octave_print_internal (std::ostream& os, const intNDArray<octave_uint16>& sa,
365  bool pr_as_read_syntax = false,
366  int extra_indent = 0);
367 
368 extern OCTINTERP_API void
369 octave_print_internal (std::ostream& os, const intNDArray<octave_int32>& sa,
370  bool pr_as_read_syntax = false,
371  int extra_indent = 0);
372 
373 extern OCTINTERP_API void
374 octave_print_internal (std::ostream& os, const intNDArray<octave_uint32>& sa,
375  bool pr_as_read_syntax = false,
376  int extra_indent = 0);
377 
378 extern OCTINTERP_API void
379 octave_print_internal (std::ostream& os, const intNDArray<octave_int64>& sa,
380  bool pr_as_read_syntax = false,
381  int extra_indent = 0);
382 
383 extern OCTINTERP_API void
384 octave_print_internal (std::ostream& os, const intNDArray<octave_uint64>& sa,
385  bool pr_as_read_syntax = false,
386  int extra_indent = 0);
387 
388 extern void
389 octave_print_internal (std::ostream& os, const float_display_format&,
390  const octave_int<int8_t>& sa,
391  bool pr_as_read_syntax = false);
392 
393 inline OCTINTERP_API void
394 octave_print_internal (std::ostream& os, const octave_int<int8_t>& sa,
395  bool pr_as_read_syntax = false)
396 {
397  float_display_format fmt (float_format (0, 0));
398  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
399 }
400 
401 extern void
402 octave_print_internal (std::ostream& os, const float_display_format&,
403  const octave_int<uint8_t>& sa,
404  bool pr_as_read_syntax = false);
405 
406 inline OCTINTERP_API void
407 octave_print_internal (std::ostream& os, const octave_int<uint8_t>& sa,
408  bool pr_as_read_syntax = false)
409 {
410  float_display_format fmt (float_format (0, 0));
411  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
412 }
413 
414 extern void
415 octave_print_internal (std::ostream& os, const float_display_format&,
416  const octave_int<int16_t>& sa,
417  bool pr_as_read_syntax = false);
418 
419 inline OCTINTERP_API void
420 octave_print_internal (std::ostream& os, const octave_int<int16_t>& sa,
421  bool pr_as_read_syntax = false)
422 {
423  float_display_format fmt (float_format (0, 0));
424  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
425 }
426 
427 extern void
428 octave_print_internal (std::ostream& os, const float_display_format&,
429  const octave_int<uint16_t>& sa,
430  bool pr_as_read_syntax = false);
431 
432 inline OCTINTERP_API void
433 octave_print_internal (std::ostream& os, const octave_int<uint16_t>& sa,
434  bool pr_as_read_syntax = false)
435 {
436  float_display_format fmt (float_format (0, 0));
437  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
438 }
439 
440 extern void
441 octave_print_internal (std::ostream& os, const float_display_format&,
442  const octave_int<int32_t>& sa,
443  bool pr_as_read_syntax = false);
444 
445 inline OCTINTERP_API void
446 octave_print_internal (std::ostream& os, const octave_int<int32_t>& sa,
447  bool pr_as_read_syntax = false)
448 {
449  float_display_format fmt (float_format (0, 0));
450  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
451 }
452 
453 extern void
454 octave_print_internal (std::ostream& os, const float_display_format&,
455  const octave_int<uint32_t>& sa,
456  bool pr_as_read_syntax = false);
457 
458 inline OCTINTERP_API void
459 octave_print_internal (std::ostream& os, const octave_int<uint32_t>& sa,
460  bool pr_as_read_syntax = false)
461 {
462  float_display_format fmt (float_format (0, 0));
463  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
464 }
465 
466 extern void
467 octave_print_internal (std::ostream& os, const float_display_format&,
468  const octave_int<int64_t>& sa,
469  bool pr_as_read_syntax = false);
470 
471 inline OCTINTERP_API void
472 octave_print_internal (std::ostream& os, const octave_int<int64_t>& sa,
473  bool pr_as_read_syntax = false)
474 {
475  float_display_format fmt (float_format (0, 0));
476  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
477 }
478 
479 extern void
480 octave_print_internal (std::ostream& os, const float_display_format&,
481  const octave_int<uint64_t>& sa,
482  bool pr_as_read_syntax = false);
483 
484 inline OCTINTERP_API void
485 octave_print_internal (std::ostream& os, const octave_int<uint64_t>& sa,
486  bool pr_as_read_syntax = false)
487 {
488  float_display_format fmt (float_format (0, 0));
489  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
490 }
491 
492 extern OCTINTERP_API void
493 octave_print_internal (std::ostream& os, const Cell& cell,
494  bool pr_as_read_syntax = false,
495  int extra_indent = 0,
496  bool pr_as_string = false);
497 
498 inline void
499 octave_print_internal (std::ostream& os, const float_display_format&,
500  const Cell& cell, bool pr_as_read_syntax = false,
501  int extra_indent = 0, bool pr_as_string = false)
502 {
503  octave_print_internal (os, cell, pr_as_read_syntax, extra_indent,
504  pr_as_string);
505 }
506 
507 extern OCTINTERP_API void
508 octave_print_internal (std::ostream& os, const octave_value& ov,
509  bool pr_as_read_syntax = false);
510 
511 template <typename T>
512 class
514 {
515 public:
516 
518 
519  T m_val;
520 
521  int exponent (void) const;
522 
523  T mantissa (void) const;
524 
526  : m_ff (ff), m_val (val) { }
527 
529  : m_ff (fdf.real_format ()), m_val (val) { }
530 };
531 
532 template <typename T>
533 class
535 {
536 public:
537 
539 
540  T m_val;
541 
542  pr_formatted_float (const float_format& ff, T val)
543  : m_ff (ff), m_val (val) { }
544 
546  : m_ff (fdf.real_format ()), m_val (val) { }
547 };
548 
549 template <typename T>
550 class
552 {
553 public:
554 
556 
557  T m_val;
558 
559  pr_rational_float (const float_format& ff, T val)
560  : m_ff (ff), m_val (val) { }
561 
563  : m_ff (fdf.real_format ()), m_val (val) { }
564 };
565 
566 template <typename T>
567 extern std::ostream&
568 operator << (std::ostream& os, const pr_engineering_float<T>& pef);
569 
570 template <typename T>
571 extern std::ostream&
572 operator << (std::ostream& os, const pr_formatted_float<T>& pff);
573 
574 template <typename T>
575 extern std::ostream&
576 operator << (std::ostream& os, const pr_rational_float<T>& prf);
577 
578 // TRUE means that the dimensions of empty objects should be printed
579 // like this: x = [](2x0).
580 extern bool Vprint_empty_dimensions;
581 
582 // TRUE means don't put empty lines in output
583 extern bool Vcompact_format;
584 
585 #endif
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:128
Definition: Cell.h:43
Definition: dMatrix.h:42
Definition: Range.h:40
pr_engineering_float(const float_format &ff, T val)
Definition: pr-output.h:525
pr_engineering_float(const float_display_format &fdf, T val)
Definition: pr-output.h:528
const float_format m_ff
Definition: pr-output.h:517
pr_formatted_float(const float_display_format &fdf, T val)
Definition: pr-output.h:545
pr_formatted_float(const float_format &ff, T val)
Definition: pr-output.h:542
const float_format m_ff
Definition: pr-output.h:538
const float_format m_ff
Definition: pr-output.h:555
pr_rational_float(const float_format &ff, T val)
Definition: pr-output.h:559
pr_rational_float(const float_display_format &fdf, T val)
Definition: pr-output.h:562
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE const F77_DBLE * f
T octave_idx_type m
Definition: mx-inlines.cc:773
T * r
Definition: mx-inlines.cc:773
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
float_display_format make_format(const std::complex< T > &)
Definition: pr-output.h:64
bool Vprint_empty_dimensions
Definition: pr-output.cc:71
std::ostream & operator<<(std::ostream &os, const pr_engineering_float< T > &pef)
Definition: pr-output.cc:187
OCTINTERP_API void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax=false)
Definition: pr-output.cc:1762
bool Vcompact_format
Definition: pr-output.cc:102