1 //////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (C) 2004-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_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 octave_base_int_matrix : public octave_base_matrix<T> 50 { 51 public: 52 octave_base_int_matrix(void)53 octave_base_int_matrix (void) : octave_base_matrix<T> () { } 54 octave_base_int_matrix(const T & nda)55 octave_base_int_matrix (const T& nda) : octave_base_matrix<T> (nda) { } 56 57 ~octave_base_int_matrix (void) = default; 58 clone(void)59 octave_base_value * clone (void) const 60 { return new octave_base_int_matrix (*this); } 61 empty_clone(void)62 octave_base_value * empty_clone (void) const 63 { return new octave_base_int_matrix (); } 64 65 octave_base_value * try_narrowing_conversion (void); 66 isreal(void)67 bool isreal (void) const { return true; } 68 69 // void increment (void) { matrix += 1; } 70 71 // void decrement (void) { matrix -= 1; } 72 73 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; 74 75 octave_value convert_to_str_internal (bool, bool, char type) const; 76 77 octave_value as_double (void) const; 78 octave_value as_single (void) const; 79 80 octave_value as_int8 (void) const; 81 octave_value as_int16 (void) const; 82 octave_value as_int32 (void) const; 83 octave_value as_int64 (void) const; 84 85 octave_value as_uint8 (void) const; 86 octave_value as_uint16 (void) const; 87 octave_value as_uint32 (void) const; 88 octave_value as_uint64 (void) const; 89 90 std::string edit_display (const float_display_format& fmt, 91 octave_idx_type i, octave_idx_type j) const; 92 93 bool save_ascii (std::ostream& os); 94 95 bool load_ascii (std::istream& is); 96 97 bool save_binary (std::ostream& os, bool); 98 99 bool load_binary (std::istream& is, bool swap, 100 octave::mach_info::float_format); 101 102 protected: 103 104 bool save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type, 105 const char *name, bool); 106 107 bool load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type, 108 const char *name); 109 }; 110 111 // base int scalar values. 112 113 template <typename T> 114 class 115 octave_base_int_scalar : public octave_base_scalar<T> 116 { 117 public: 118 octave_base_int_scalar(void)119 octave_base_int_scalar (void) : octave_base_scalar<T> () { } 120 octave_base_int_scalar(const T & s)121 octave_base_int_scalar (const T& s) : octave_base_scalar<T> (s) { } 122 123 ~octave_base_int_scalar (void) = default; 124 clone(void)125 octave_base_value * clone (void) const 126 { return new octave_base_int_scalar (*this); } empty_clone(void)127 octave_base_value * empty_clone (void) const 128 { return new octave_base_int_scalar (); } 129 try_narrowing_conversion(void)130 octave_base_value * try_narrowing_conversion (void) { return nullptr; } 131 isreal(void)132 bool isreal (void) const { return true; } 133 is_real_scalar(void)134 bool is_real_scalar (void) const { return true; } 135 136 // void increment (void) { scalar += 1; } 137 138 // void decrement (void) { scalar -= 1; } 139 140 octave_value convert_to_str_internal (bool, bool, char type) const; 141 142 octave_value as_double (void) const; 143 octave_value as_single (void) const; 144 145 octave_value as_int8 (void) const; 146 octave_value as_int16 (void) const; 147 octave_value as_int32 (void) const; 148 octave_value as_int64 (void) const; 149 150 octave_value as_uint8 (void) const; 151 octave_value as_uint16 (void) const; 152 octave_value as_uint32 (void) const; 153 octave_value as_uint64 (void) const; 154 155 std::string edit_display (const float_display_format& fmt, 156 octave_idx_type i, octave_idx_type j) const; 157 158 bool save_ascii (std::ostream& os); 159 160 bool load_ascii (std::istream& is); 161 162 bool save_binary (std::ostream& os, bool); 163 164 bool load_binary (std::istream& is, bool swap, 165 octave::mach_info::float_format); 166 protected: 167 168 bool save_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type, 169 const char *name, bool); 170 171 bool load_hdf5_internal (octave_hdf5_id loc_id, octave_hdf5_id save_type, 172 const char *name); 173 }; 174 175 #endif 176