GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-int.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2004-2023 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_ov_base_int_h)
27 #define octave_ov_base_int_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "mx-base.h"
37 #include "str-vec.h"
38 
39 #include "error.h"
40 #include "ov-base.h"
41 #include "ov-base-mat.h"
42 #include "ov-base-scalar.h"
43 #include "ov-typeinfo.h"
44 
45 // base int matrix values.
46 
47 template <typename T>
48 class
49 OCTINTERP_API
51 {
52 public:
53 
55 
56  octave_base_int_matrix (const T& nda) : octave_base_matrix<T> (nda) { }
57 
58  ~octave_base_int_matrix (void) = default;
59 
60  octave_base_value * clone (void) const
61  { return new octave_base_int_matrix (*this); }
62 
64  { return new octave_base_int_matrix (); }
65 
66  OCTINTERP_API octave_base_value * try_narrowing_conversion (void);
67 
68  bool isreal (void) const { return true; }
69 
70  // void increment (void) { matrix += 1; }
71 
72  // void decrement (void) { matrix -= 1; }
73 
74  OCTINTERP_API void
75  print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
76 
77  OCTINTERP_API octave_value
78  convert_to_str_internal (bool, bool, char type) const;
79 
80  OCTINTERP_API octave_value as_double (void) const;
81  OCTINTERP_API octave_value as_single (void) const;
82 
83  OCTINTERP_API octave_value as_int8 (void) const;
84  OCTINTERP_API octave_value as_int16 (void) const;
85  OCTINTERP_API octave_value as_int32 (void) const;
86  OCTINTERP_API octave_value as_int64 (void) const;
87 
88  OCTINTERP_API octave_value as_uint8 (void) const;
89  OCTINTERP_API octave_value as_uint16 (void) const;
90  OCTINTERP_API octave_value as_uint32 (void) const;
91  OCTINTERP_API octave_value as_uint64 (void) const;
92 
93  OCTINTERP_API std::string
94  edit_display (const float_display_format& fmt,
95  octave_idx_type i, octave_idx_type j) const;
96 
97  OCTINTERP_API bool save_ascii (std::ostream& os);
98 
99  OCTINTERP_API bool load_ascii (std::istream& is);
100 
101  OCTINTERP_API bool save_binary (std::ostream& os, bool);
102 
103  OCTINTERP_API bool
104  load_binary (std::istream& is, bool swap, octave::mach_info::float_format);
105 
106 protected:
107 
108  OCTINTERP_API bool
109  save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
110  const char *name, bool);
111 
112  OCTINTERP_API bool
113  load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
114  const char *name);
115 };
116 
117 // base int scalar values.
118 
119 template <typename T>
120 class
121 OCTINTERP_API
123 {
124 public:
125 
127 
128  octave_base_int_scalar (const T& s) : octave_base_scalar<T> (s) { }
129 
130  ~octave_base_int_scalar (void) = default;
131 
132  octave_base_value * clone (void) const
133  { return new octave_base_int_scalar (*this); }
135  { return new octave_base_int_scalar (); }
136 
137  octave_base_value * try_narrowing_conversion (void) { return nullptr; }
138 
139  bool isreal (void) const { return true; }
140 
141  bool is_real_scalar (void) const { return true; }
142 
143  // void increment (void) { scalar += 1; }
144 
145  // void decrement (void) { scalar -= 1; }
146 
147  OCTINTERP_API octave_value
148  convert_to_str_internal (bool, bool, char type) const;
149 
150  OCTINTERP_API octave_value as_double (void) const;
151  OCTINTERP_API octave_value as_single (void) const;
152 
153  OCTINTERP_API octave_value as_int8 (void) const;
154  OCTINTERP_API octave_value as_int16 (void) const;
155  OCTINTERP_API octave_value as_int32 (void) const;
156  OCTINTERP_API octave_value as_int64 (void) const;
157 
158  OCTINTERP_API octave_value as_uint8 (void) const;
159  OCTINTERP_API octave_value as_uint16 (void) const;
160  OCTINTERP_API octave_value as_uint32 (void) const;
161  OCTINTERP_API octave_value as_uint64 (void) const;
162 
163  OCTINTERP_API std::string
164  edit_display (const float_display_format& fmt,
165  octave_idx_type i, octave_idx_type j) const;
166 
167  OCTINTERP_API bool save_ascii (std::ostream& os);
168 
169  OCTINTERP_API bool load_ascii (std::istream& is);
170 
171  OCTINTERP_API bool save_binary (std::ostream& os, bool);
172 
173  OCTINTERP_API bool load_binary (std::istream& is, bool swap,
175 protected:
176 
177  OCTINTERP_API bool
178  save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
179  const char *name, bool);
180 
181  OCTINTERP_API bool
182  load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
183  const char *name);
184 };
185 
186 #endif
octave_base_int_matrix(const T &nda)
Definition: ov-base-int.h:56
bool isreal(void) const
Definition: ov-base-int.h:68
~octave_base_int_matrix(void)=default
octave_base_value * clone(void) const
Definition: ov-base-int.h:60
octave_base_value * empty_clone(void) const
Definition: ov-base-int.h:63
~octave_base_int_scalar(void)=default
bool isreal(void) const
Definition: ov-base-int.h:139
octave_base_value * clone(void) const
Definition: ov-base-int.h:132
bool is_real_scalar(void) const
Definition: ov-base-int.h:141
octave_base_int_scalar(const T &s)
Definition: ov-base-int.h:128
octave_base_value * empty_clone(void) const
Definition: ov-base-int.h:134
octave_base_value * try_narrowing_conversion(void)
Definition: ov-base-int.h:137
save_type
Definition: data-conv.h:87
float_format
Definition: mach-info.h:38
int64_t octave_hdf5_id
static double as_double(OCTAVE_TIME_T sec, long usec)
Definition: oct-time.h:35