GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-inline.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2023-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_inline_h)
27 #define octave_ov_inline_h 1
28 
29 #include "octave-config.h"
30 
31 #include "ov.h"
32 
33 #include "ov-scalar.h"
34 #include "ov-float.h"
35 #include "ov-complex.h"
36 #include "ov-flt-complex.h"
37 #include "ov-bool.h"
38 #include "ov-base.h"
39 
40 
41 // class to construct octave_value:s inline
42 
44 {
45 public:
46 
47  static octave_value make (double d)
48  {
49  return octave_value (new octave_scalar (d));
50  }
51 
52  static octave_value make (float d)
53  {
54  return octave_value (new octave_float_scalar (d));
55  }
56 
57  static octave_value make (short int i)
58  {
59  return octave_value (new octave_scalar (i));
60  }
61 
62  static octave_value make (unsigned short int i)
63  {
64  return octave_value (new octave_scalar (i));
65  }
66 
67  static octave_value make (int i)
68  {
69  return octave_value (new octave_scalar (i));
70  }
71 
72  static octave_value make (unsigned int i)
73  {
74  return octave_value (new octave_scalar (i));
75  }
76 
77  static octave_value make (long int i)
78  {
79  return octave_value (new octave_scalar (i));
80  }
81 
82  static octave_value make (unsigned long int i)
83  {
84  return octave_value (new octave_scalar (i));
85  }
86 
87 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
88  static octave_value make (long long int i)
89  {
90  return octave_value (new octave_scalar (i));
91  }
92 #endif
93 
94 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
95  static octave_value make (unsigned long long int i)
96  {
97  return octave_value (new octave_scalar (i));
98  }
99 #endif
100 
101  static octave_value make (octave::sys::time t)
102  {
103  return octave_value (new octave_scalar (t.double_value ()));
104  }
105 
106  static octave_value make (const Complex& C)
107  {
108  octave_value ov (new octave_complex (C));
109  ov.maybe_mutate (); // Fold e.g. 1+0i to 1
110  return ov;
111  }
112 
113  static octave_value make (const FloatComplex& C)
114  {
116  ov.maybe_mutate ();
117  return ov;
118  }
119 
120  static octave_value make (bool b)
121  {
122  return octave_value (new octave_bool (b));
123  }
124 
125  // FIXME: The octave_value (octave_base_value *rep, bool) constructor
126  // is already defined in the ov.h header file so is the
127  // octave_value_factory::make_copy function really necessary?
128 
130  {
131  return octave_value (rep, true);
132  }
133 
134 private:
135 
136  ~octave_value_factory () = delete;
137  octave_value_factory () = delete;
138 };
139 
140 #endif
#define C(a, b)
Definition: Faddeeva.cc:259
static octave_value make(unsigned short int i)
Definition: ov-inline.h:62
static octave_value make(double d)
Definition: ov-inline.h:47
static octave_value make_copy(octave_base_value *rep)
Definition: ov-inline.h:129
static octave_value make(octave::sys::time t)
Definition: ov-inline.h:101
static octave_value make(short int i)
Definition: ov-inline.h:57
static octave_value make(long int i)
Definition: ov-inline.h:77
static octave_value make(int i)
Definition: ov-inline.h:67
static octave_value make(bool b)
Definition: ov-inline.h:120
static octave_value make(unsigned int i)
Definition: ov-inline.h:72
static octave_value make(unsigned long int i)
Definition: ov-inline.h:82
static octave_value make(const Complex &C)
Definition: ov-inline.h:106
static octave_value make(float d)
Definition: ov-inline.h:52
static octave_value make(const FloatComplex &C)
Definition: ov-inline.h:113
void maybe_mutate()
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))