GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_pr_output_h)
24 #define octave_pr_output_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iosfwd>
29 
30 #include "oct-cmplx.h"
31 #include "oct-inttypes-fwd.h"
32 
33 #include "pr-flt-fmt.h"
34 
35 template <typename T> class Array;
36 class ComplexMatrix;
37 class FloatComplexMatrix;
38 class ComplexDiagMatrix;
40 class ComplexNDArray;
42 class Matrix;
43 class FloatMatrix;
44 class DiagMatrix;
45 class FloatDiagMatrix;
46 class NDArray;
47 class FloatNDArray;
48 class Range;
49 class boolMatrix;
50 class boolNDArray;
51 class charMatrix;
52 class charNDArray;
53 class PermMatrix;
54 class Cell;
55 class octave_value;
56 
57 template <typename T> class intNDArray;
58 
59 template <typename T>
61 make_format (const std::complex<T>&)
62 {
63  return float_display_format ();
64 }
65 
66 template <>
68 make_format (const std::complex<double>& c);
69 
70 template <>
72 make_format (const std::complex<float>& fc);
73 
74 template <typename T>
76 make_format (const T&)
77 {
78  return float_display_format ();
79 }
80 
81 template <>
83 make_format (const double& d);
84 
85 template <>
87 make_format (const float& f);
88 
89 template <>
91 make_format (const Range& r);
92 
93 template <>
95 make_format (const Matrix& m);
96 
97 template <>
99 make_format (const FloatMatrix& m);
100 
101 template <>
103 make_format (const ComplexMatrix& m);
104 
105 template <>
108 
109 template <>
111 make_format (const boolNDArray& nda);
112 
113 template <>
116 
117 template <>
120 
121 template <>
124 
125 template <>
128 
129 template <>
132 
133 template <>
136 
137 template <>
140 
141 template <>
144 
145 template <>
147 make_format (const octave_int8& nda);
148 
149 template <>
151 make_format (const octave_int16& nda);
152 
153 template <>
155 make_format (const octave_int32& nda);
156 
157 template <>
159 make_format (const octave_int64& nda);
160 
161 template <>
163 make_format (const octave_uint8& nda);
164 
165 template <>
167 make_format (const octave_uint16& nda);
168 
169 template <>
171 make_format (const octave_uint32& nda);
172 
173 template <>
175 make_format (const octave_uint64& nda);
176 
177 // FIXME: templates plus specializations might help here.
178 
179 extern OCTINTERP_API void
180 octave_print_internal (std::ostream& os, const float_display_format& fmt,
181  bool d, bool pr_as_read_syntax = false);
182 
183 extern OCTINTERP_API void
184 octave_print_internal (std::ostream& os, bool d,
185  bool pr_as_read_syntax = false);
186 
187 extern OCTINTERP_API void
188 octave_print_internal (std::ostream& os, const float_display_format& fmt,
189  char c, bool pr_as_read_syntax = false);
190 
191 inline void
192 octave_print_internal (std::ostream& os, char c,
193  bool pr_as_read_syntax = false)
194 {
195  float_display_format fmt (float_format (0, 0));
196  octave_print_internal (os, fmt, c, pr_as_read_syntax);
197 }
198 
199 extern OCTINTERP_API void
200 octave_print_internal (std::ostream& os, const float_display_format& fmt,
201  double d, bool pr_as_read_syntax = false);
202 
203 inline void
204 octave_print_internal (std::ostream& os, double d,
205  bool pr_as_read_syntax = false)
206 {
207  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
208 }
209 
210 extern OCTINTERP_API void
211 octave_print_internal (std::ostream& os, const float_display_format& fmt,
212  float d, bool pr_as_read_syntax = false);
213 
214 inline void
215 octave_print_internal (std::ostream& os, float d,
216  bool pr_as_read_syntax = false)
217 {
218  octave_print_internal (os, make_format (d), d, pr_as_read_syntax);
219 }
220 
221 extern OCTINTERP_API void
222 octave_print_internal (std::ostream& os, const Matrix& m,
223  bool pr_as_read_syntax = false,
224  int extra_indent = 0);
225 
226 extern OCTINTERP_API void
227 octave_print_internal (std::ostream& os, const FloatMatrix& m,
228  bool pr_as_read_syntax = false,
229  int extra_indent = 0);
230 
231 extern OCTINTERP_API void
232 octave_print_internal (std::ostream& os, const DiagMatrix& m,
233  bool pr_as_read_syntax = false,
234  int extra_indent = 0);
235 
236 extern OCTINTERP_API void
237 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
238  bool pr_as_read_syntax = false,
239  int extra_indent = 0);
240 
241 extern OCTINTERP_API void
242 octave_print_internal (std::ostream& os, const NDArray& nda,
243  bool pr_as_read_syntax = false,
244  int extra_indent = 0);
245 
246 extern OCTINTERP_API void
247 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
248  bool pr_as_read_syntax = false,
249  int extra_indent = 0);
250 
251 extern OCTINTERP_API void
252 octave_print_internal (std::ostream& os, const float_display_format& fmt,
253  const Complex& c, bool pr_as_read_syntax = false);
254 
255 inline void
256 octave_print_internal (std::ostream& os, const Complex& c,
257  bool pr_as_read_syntax = false)
258 {
259  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
260 }
261 
262 extern OCTINTERP_API void
263 octave_print_internal (std::ostream& os, const float_display_format& fmt,
264  const FloatComplex& c, bool pr_as_read_syntax = false);
265 
266 inline void
267 octave_print_internal (std::ostream& os, const FloatComplex& c,
268  bool pr_as_read_syntax = false)
269 {
270  octave_print_internal (os, make_format (c), c, pr_as_read_syntax);
271 }
272 
273 extern OCTINTERP_API void
274 octave_print_internal (std::ostream& os, const ComplexMatrix& cm,
275  bool pr_as_read_syntax = false,
276  int extra_indent = 0);
277 
278 extern OCTINTERP_API void
279 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
280  bool pr_as_read_syntax = false,
281  int extra_indent = 0);
282 
283 extern OCTINTERP_API void
284 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
285  bool pr_as_read_syntax = false,
286  int extra_indent = 0);
287 
288 extern OCTINTERP_API void
289 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm,
290  bool pr_as_read_syntax = false,
291  int extra_indent = 0);
292 
293 extern OCTINTERP_API void
294 octave_print_internal (std::ostream& os, const ComplexNDArray& nda,
295  bool pr_as_read_syntax = false,
296  int extra_indent = 0);
297 
298 extern OCTINTERP_API void
299 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
300  bool pr_as_read_syntax = false,
301  int extra_indent = 0);
302 
303 extern OCTINTERP_API void
304 octave_print_internal (std::ostream& os, const PermMatrix& m,
305  bool pr_as_read_syntax = false,
306  int extra_indent = 0);
307 
308 extern OCTINTERP_API void
309 octave_print_internal (std::ostream& os, const Range& r,
310  bool pr_as_read_syntax = false,
311  int extra_indent = 0);
312 
313 extern OCTINTERP_API void
314 octave_print_internal (std::ostream& os, const boolMatrix& m,
315  bool pr_as_read_syntax = false,
316  int extra_indent = 0);
317 
318 extern OCTINTERP_API void
319 octave_print_internal (std::ostream& os, const boolNDArray& m,
320  bool pr_as_read_syntax = false,
321  int extra_indent = 0);
322 
323 extern OCTINTERP_API void
324 octave_print_internal (std::ostream& os, const charMatrix& chm,
325  bool pr_as_read_syntax = false,
326  int extra_indent = 0,
327  bool pr_as_string = false);
328 
329 extern OCTINTERP_API void
330 octave_print_internal (std::ostream& os, const charNDArray& nda,
331  bool pr_as_read_syntax = false,
332  int extra_indent = 0,
333  bool pr_as_string = false);
334 
335 extern OCTINTERP_API void
336 octave_print_internal (std::ostream& os, const std::string& s,
337  bool pr_as_read_syntax = false,
338  int extra_indent = 0);
339 
340 extern OCTINTERP_API void
341 octave_print_internal (std::ostream& os, const Array<std::string>& sa,
342  bool pr_as_read_syntax = false,
343  int extra_indent = 0);
344 
345 extern OCTINTERP_API void
346 octave_print_internal (std::ostream& os, const intNDArray<octave_int8>& sa,
347  bool pr_as_read_syntax = false,
348  int extra_indent = 0);
349 
350 extern OCTINTERP_API void
351 octave_print_internal (std::ostream& os, const intNDArray<octave_uint8>& sa,
352  bool pr_as_read_syntax = false,
353  int extra_indent = 0);
354 
355 extern OCTINTERP_API void
356 octave_print_internal (std::ostream& os, const intNDArray<octave_int16>& sa,
357  bool pr_as_read_syntax = false,
358  int extra_indent = 0);
359 
360 extern OCTINTERP_API void
361 octave_print_internal (std::ostream& os, const intNDArray<octave_uint16>& sa,
362  bool pr_as_read_syntax = false,
363  int extra_indent = 0);
364 
365 extern OCTINTERP_API void
366 octave_print_internal (std::ostream& os, const intNDArray<octave_int32>& sa,
367  bool pr_as_read_syntax = false,
368  int extra_indent = 0);
369 
370 extern OCTINTERP_API void
371 octave_print_internal (std::ostream& os, const intNDArray<octave_uint32>& sa,
372  bool pr_as_read_syntax = false,
373  int extra_indent = 0);
374 
375 extern OCTINTERP_API void
376 octave_print_internal (std::ostream& os, const intNDArray<octave_int64>& sa,
377  bool pr_as_read_syntax = false,
378  int extra_indent = 0);
379 
380 extern OCTINTERP_API void
381 octave_print_internal (std::ostream& os, const intNDArray<octave_uint64>& sa,
382  bool pr_as_read_syntax = false,
383  int extra_indent = 0);
384 
385 extern void
386 octave_print_internal (std::ostream& os, const float_display_format&,
387  const octave_int<int8_t>& sa,
388  bool pr_as_read_syntax = false);
389 
390 inline OCTINTERP_API void
391 octave_print_internal (std::ostream& os, const octave_int<int8_t>& sa,
392  bool pr_as_read_syntax = false)
393 {
394  float_display_format fmt (float_format (0, 0));
395  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
396 }
397 
398 extern void
399 octave_print_internal (std::ostream& os, const float_display_format&,
400  const octave_int<uint8_t>& sa,
401  bool pr_as_read_syntax = false);
402 
403 inline OCTINTERP_API void
404 octave_print_internal (std::ostream& os, const octave_int<uint8_t>& sa,
405  bool pr_as_read_syntax = false)
406 {
407  float_display_format fmt (float_format (0, 0));
408  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
409 }
410 
411 extern void
412 octave_print_internal (std::ostream& os, const float_display_format&,
413  const octave_int<int16_t>& sa,
414  bool pr_as_read_syntax = false);
415 
416 inline OCTINTERP_API void
417 octave_print_internal (std::ostream& os, const octave_int<int16_t>& sa,
418  bool pr_as_read_syntax = false)
419 {
420  float_display_format fmt (float_format (0, 0));
421  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
422 }
423 
424 extern void
425 octave_print_internal (std::ostream& os, const float_display_format&,
426  const octave_int<uint16_t>& sa,
427  bool pr_as_read_syntax = false);
428 
429 inline OCTINTERP_API void
431  bool pr_as_read_syntax = false)
432 {
433  float_display_format fmt (float_format (0, 0));
434  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
435 }
436 
437 extern void
438 octave_print_internal (std::ostream& os, const float_display_format&,
439  const octave_int<int32_t>& sa,
440  bool pr_as_read_syntax = false);
441 
442 inline OCTINTERP_API void
443 octave_print_internal (std::ostream& os, const octave_int<int32_t>& sa,
444  bool pr_as_read_syntax = false)
445 {
446  float_display_format fmt (float_format (0, 0));
447  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
448 }
449 
450 extern void
451 octave_print_internal (std::ostream& os, const float_display_format&,
452  const octave_int<uint32_t>& sa,
453  bool pr_as_read_syntax = false);
454 
455 inline OCTINTERP_API void
457  bool pr_as_read_syntax = false)
458 {
459  float_display_format fmt (float_format (0, 0));
460  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
461 }
462 
463 extern void
464 octave_print_internal (std::ostream& os, const float_display_format&,
465  const octave_int<int64_t>& sa,
466  bool pr_as_read_syntax = false);
467 
468 inline OCTINTERP_API void
469 octave_print_internal (std::ostream& os, const octave_int<int64_t>& sa,
470  bool pr_as_read_syntax = false)
471 {
472  float_display_format fmt (float_format (0, 0));
473  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
474 }
475 
476 extern void
477 octave_print_internal (std::ostream& os, const float_display_format&,
478  const octave_int<uint64_t>& sa,
479  bool pr_as_read_syntax = false);
480 
481 inline OCTINTERP_API void
483  bool pr_as_read_syntax = false)
484 {
485  float_display_format fmt (float_format (0, 0));
486  octave_print_internal (os, fmt, sa, pr_as_read_syntax);
487 }
488 
489 extern OCTINTERP_API void
490 octave_print_internal (std::ostream& os, const Cell& cell,
491  bool pr_as_read_syntax = false,
492  int extra_indent = 0,
493  bool pr_as_string = false);
494 
495 inline void
497  const Cell& cell, bool pr_as_read_syntax = false,
498  int extra_indent = 0, bool pr_as_string = false)
499 {
500  octave_print_internal (os, cell, pr_as_read_syntax, extra_indent,
501  pr_as_string);
502 }
503 
504 extern OCTINTERP_API void
505 octave_print_internal (std::ostream& os, const octave_value& ov,
506  bool pr_as_read_syntax = false);
507 
508 template <typename T>
509 class
511 {
512 public:
513 
515 
516  T m_val;
517 
518  int exponent (void) const;
519 
520  T mantissa (void) const;
521 
523  : m_ff (ff), m_val (val) { }
524 
526  : m_ff (fdf.real_format ()), m_val (val) { }
527 };
528 
529 template <typename T>
530 class
532 {
533 public:
534 
536 
537  T m_val;
538 
540  : m_ff (ff), m_val (val) { }
541 
543  : m_ff (fdf.real_format ()), m_val (val) { }
544 };
545 
546 template <typename T>
547 class
549 {
550 public:
551 
553 
554  T m_val;
555 
557  : m_ff (ff), m_val (val) { }
558 
560  : m_ff (fdf.real_format ()), m_val (val) { }
561 };
562 
563 template <typename T>
564 extern std::ostream&
565 operator << (std::ostream& os, const pr_engineering_float<T>& pef);
566 
567 template <typename T>
568 extern std::ostream&
569 operator << (std::ostream& os, const pr_formatted_float<T>& pff);
570 
571 template <typename T>
572 extern std::ostream&
573 operator << (std::ostream& os, const pr_rational_float<T>& prf);
574 
575 // TRUE means that the dimensions of empty objects should be printed
576 // like this: x = [](2x0).
577 extern bool Vprint_empty_dimensions;
578 
579 // TRUE means don't put empty lines in output
580 extern bool Vcompact_format;
581 
582 #endif
Definition: Cell.h:37
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
const float_format m_ff
Definition: pr-output.h:535
Definition: Range.h:33
bool Vprint_empty_dimensions
Definition: pr-output.cc:68
pr_engineering_float(const float_format &ff, T val)
Definition: pr-output.h:522
pr_formatted_float(const float_display_format &fdf, T val)
Definition: pr-output.h:542
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
s
Definition: file-io.cc:2729
const float_format m_ff
Definition: pr-output.h:514
pr_rational_float(const float_format &ff, T val)
Definition: pr-output.h:556
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
float_display_format make_format(const std::complex< T > &)
Definition: pr-output.h:61
pr_formatted_float(const float_format &ff, T val)
Definition: pr-output.h:539
pr_rational_float(const float_display_format &fdf, T val)
Definition: pr-output.h:559
const float_format m_ff
Definition: pr-output.h:552
Definition: dMatrix.h:36
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:1780
pr_engineering_float(const float_display_format &fdf, T val)
Definition: pr-output.h:525
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
std::complex< double > Complex
Definition: oct-cmplx.h:31
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
bool Vcompact_format
Definition: pr-output.cc:99
octave::stream os
Definition: file-io.cc:627