GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-base-int.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2004-2025 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
47extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<int8NDArray>;
48extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<int16NDArray>;
49extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<int32NDArray>;
50extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<int64NDArray>;
51extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<uint8NDArray>;
52extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<uint16NDArray>;
53extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<uint32NDArray>;
54extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<uint64NDArray>;
55
56template <typename T>
57class OCTINTERP_TEMPLATE_API octave_base_int_matrix : public octave_base_matrix<T>
58{
59public:
60
61 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_int_matrix ()
62 : octave_base_matrix<T> ()
63 { }
64
65 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_int_matrix (const T& nda)
66 : octave_base_matrix<T> (nda)
67 { }
68
70
72 { return new octave_base_int_matrix (*this); }
73
75 { return new octave_base_int_matrix (); }
76
77 OCTINTERP_API octave_base_value * try_narrowing_conversion ();
78
79 OCTINTERP_OVERRIDABLE_FUNC_API bool isreal () const { return true; }
80
81 // void increment () { matrix += 1; }
82
83 // void decrement () { matrix -= 1; }
84
85 OCTINTERP_API void
86 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
87
88 OCTINTERP_API octave_value
89 convert_to_str_internal (bool, bool, char type) const;
90
91 OCTINTERP_API octave_value as_double () const;
92 OCTINTERP_API octave_value as_single () const;
93
94 OCTINTERP_API octave_value as_int8 () const;
95 OCTINTERP_API octave_value as_int16 () const;
96 OCTINTERP_API octave_value as_int32 () const;
97 OCTINTERP_API octave_value as_int64 () const;
98
99 OCTINTERP_API octave_value as_uint8 () const;
100 OCTINTERP_API octave_value as_uint16 () const;
101 OCTINTERP_API octave_value as_uint32 () const;
102 OCTINTERP_API octave_value as_uint64 () const;
103
104 OCTINTERP_API std::string
105 edit_display (const float_display_format& fmt,
107
108 OCTINTERP_API bool save_ascii (std::ostream& os);
109
110 OCTINTERP_API bool load_ascii (std::istream& is);
111
112 OCTINTERP_API bool save_binary (std::ostream& os, bool);
113
114 OCTINTERP_API bool
115 load_binary (std::istream& is, bool swap, octave::mach_info::float_format);
116
117protected:
118
119 OCTINTERP_API bool
120 save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
121 const char *name, bool);
122
123 OCTINTERP_API bool
124 load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
125 const char *name);
126};
127
128// base int scalar values.
129
130extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_int8>;
131extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_int16>;
132extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_int32>;
133extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_int64>;
134extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_uint8>;
135extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_uint16>;
136extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_uint32>;
137extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<octave_uint64>;
138
139template <typename T>
140class OCTINTERP_TEMPLATE_API octave_base_int_scalar : public octave_base_scalar<T>
141{
142public:
143
144 OCTINTERP_OVERRIDABLE_FUNC_API
146
147 OCTINTERP_OVERRIDABLE_FUNC_API
149
150 OCTINTERP_OVERRIDABLE_FUNC_API ~octave_base_int_scalar () = default;
151
152 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_value * clone () const
153 { return new octave_base_int_scalar (*this); }
154 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_value * empty_clone () const
155 { return new octave_base_int_scalar (); }
156
157 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_value *
159 { return nullptr; }
160
161 OCTINTERP_OVERRIDABLE_FUNC_API bool is_maybe_function () const
162 { return false; }
163
164 OCTINTERP_OVERRIDABLE_FUNC_API bool isreal () const
165 { return true; }
166
167 OCTINTERP_OVERRIDABLE_FUNC_API bool is_real_scalar () const
168 { return true; }
169
170 // void increment () { scalar += 1; }
171
172 // void decrement () { scalar -= 1; }
173
174 OCTINTERP_API octave_value
175 convert_to_str_internal (bool, bool, char type) const;
176
177 OCTINTERP_API octave_value as_double () const;
178 OCTINTERP_API octave_value as_single () const;
179
180 OCTINTERP_API octave_value as_int8 () const;
181 OCTINTERP_API octave_value as_int16 () const;
182 OCTINTERP_API octave_value as_int32 () const;
183 OCTINTERP_API octave_value as_int64 () const;
184
185 OCTINTERP_API octave_value as_uint8 () const;
186 OCTINTERP_API octave_value as_uint16 () const;
187 OCTINTERP_API octave_value as_uint32 () const;
188 OCTINTERP_API octave_value as_uint64 () const;
189
190 OCTINTERP_API std::string
191 edit_display (const float_display_format& fmt,
193
194 OCTINTERP_API bool save_ascii (std::ostream& os);
195
196 OCTINTERP_API bool load_ascii (std::istream& is);
197
198 OCTINTERP_API bool save_binary (std::ostream& os, bool);
199
200 OCTINTERP_API bool load_binary (std::istream& is, bool swap,
201 octave::mach_info::float_format);
202protected:
203
204 OCTINTERP_API bool
205 save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
206 const char *name, bool);
207
208 OCTINTERP_API bool
209 load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
210 const char *name);
211};
212
213#endif
octave_base_int_matrix(const T &nda)
Definition ov-base-int.h:65
~octave_base_int_matrix()=default
octave_base_value * empty_clone() const
Definition ov-base-int.h:74
octave_base_value * clone() const
Definition ov-base-int.h:71
octave_base_value * clone() const
octave_base_value * empty_clone() const
~octave_base_int_scalar()=default
octave_base_value * try_narrowing_conversion()
octave_base_int_scalar(const T &s)
bool is_real_scalar() const
bool is_maybe_function() const
save_type
Definition data-conv.h:85
int64_t octave_hdf5_id