GNU Octave  9.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-2024 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 
59 
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 ();
67 
68  bool isreal () const { return true; }
69 
70  // void increment () { matrix += 1; }
71 
72  // void decrement () { 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 () const;
81  OCTINTERP_API octave_value as_single () const;
82 
83  OCTINTERP_API octave_value as_int8 () const;
84  OCTINTERP_API octave_value as_int16 () const;
85  OCTINTERP_API octave_value as_int32 () const;
86  OCTINTERP_API octave_value as_int64 () const;
87 
88  OCTINTERP_API octave_value as_uint8 () const;
89  OCTINTERP_API octave_value as_uint16 () const;
90  OCTINTERP_API octave_value as_uint32 () const;
91  OCTINTERP_API octave_value as_uint64 () 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 
131 
133  { return new octave_base_int_scalar (*this); }
135  { return new octave_base_int_scalar (); }
136 
138 
139  bool is_maybe_function () const { return false; }
140 
141  bool isreal () const { return true; }
142 
143  bool is_real_scalar () const { return true; }
144 
145  // void increment () { scalar += 1; }
146 
147  // void decrement () { scalar -= 1; }
148 
149  OCTINTERP_API octave_value
150  convert_to_str_internal (bool, bool, char type) const;
151 
152  OCTINTERP_API octave_value as_double () const;
153  OCTINTERP_API octave_value as_single () const;
154 
155  OCTINTERP_API octave_value as_int8 () const;
156  OCTINTERP_API octave_value as_int16 () const;
157  OCTINTERP_API octave_value as_int32 () const;
158  OCTINTERP_API octave_value as_int64 () const;
159 
160  OCTINTERP_API octave_value as_uint8 () const;
161  OCTINTERP_API octave_value as_uint16 () const;
162  OCTINTERP_API octave_value as_uint32 () const;
163  OCTINTERP_API octave_value as_uint64 () const;
164 
165  OCTINTERP_API std::string
166  edit_display (const float_display_format& fmt,
167  octave_idx_type i, octave_idx_type j) const;
168 
169  OCTINTERP_API bool save_ascii (std::ostream& os);
170 
171  OCTINTERP_API bool load_ascii (std::istream& is);
172 
173  OCTINTERP_API bool save_binary (std::ostream& os, bool);
174 
175  OCTINTERP_API bool load_binary (std::istream& is, bool swap,
177 protected:
178 
179  OCTINTERP_API bool
180  save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
181  const char *name, bool);
182 
183  OCTINTERP_API bool
184  load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type,
185  const char *name);
186 };
187 
188 #endif
octave_base_int_matrix(const T &nda)
Definition: ov-base-int.h:56
octave_base_value * empty_clone() const
Definition: ov-base-int.h:63
octave_base_value * clone() const
Definition: ov-base-int.h:60
~octave_base_int_matrix()=default
bool isreal() const
Definition: ov-base-int.h:68
octave_base_value * empty_clone() const
Definition: ov-base-int.h:134
~octave_base_int_scalar()=default
octave_base_value * clone() const
Definition: ov-base-int.h:132
octave_base_value * try_narrowing_conversion()
Definition: ov-base-int.h:137
octave_base_int_scalar(const T &s)
Definition: ov-base-int.h:128
bool is_real_scalar() const
Definition: ov-base-int.h:143
bool is_maybe_function() const
Definition: ov-base-int.h:139
save_type
Definition: data-conv.h:87
float_format
Definition: mach-info.h:38
int64_t octave_hdf5_id