Mercurial > octave
changeset 32122:920e88fd8ab7
new octave_value_factory class
* ov-inline.h: New file.
* libinterp/octave-value/module.mk: Update.
author | Petter T. <petter.vilhelm@gmail.com> |
---|---|
date | Wed, 14 Jun 2023 16:11:54 -0400 |
parents | ae588860b6fa |
children | f31cbed22bf6 |
files | libinterp/octave-value/module.mk libinterp/octave-value/ov-inline.h |
diffstat | 2 files changed, 136 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/module.mk Wed Jun 14 16:09:36 2023 -0400 +++ b/libinterp/octave-value/module.mk Wed Jun 14 16:11:54 2023 -0400 @@ -51,6 +51,7 @@ %reldir%/ov-flt-cx-mat.h \ %reldir%/ov-flt-re-diag.h \ %reldir%/ov-flt-re-mat.h \ + %reldir%/ov-inline.h \ %reldir%/ov-java.h \ %reldir%/ov-lazy-idx.h \ %reldir%/ov-legacy-range.h \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/octave-value/ov-inline.h Wed Jun 14 16:11:54 2023 -0400 @@ -0,0 +1,135 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 1996-2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_ov_inline_h) +#define octave_ov_inline_h 1 + +#include "octave-config.h" + +#include "ov.h" + +#include "ov-scalar.h" +#include "ov-float.h" +#include "ov-complex.h" +#include "ov-flt-complex.h" +#include "ov-bool.h" +#include "ov-base.h" + + +// class to construct octave_value:s inline + +class octave_value_factory +{ + public: + + static octave_value make (double d) + { + return octave_value (0, new octave_scalar (d)); + } + + static octave_value make (float d) + { + return octave_value (0, new octave_float_scalar (d)); + } + + static octave_value make (short int i) + { + return octave_value (0, new octave_scalar (i)); + } + + static octave_value make (unsigned short int i) + { + return octave_value (0, new octave_scalar (i)); + } + + static octave_value make (int i) + { + return octave_value (0, new octave_scalar (i)); + } + + static octave_value make (unsigned int i) + { + return octave_value (0, new octave_scalar (i)); + } + + static octave_value make (long int i) + { + return octave_value (0, new octave_scalar (i)); + } + + static octave_value make (unsigned long int i) + { + return octave_value (0, new octave_scalar (i)); + } + +#if defined (OCTAVE_HAVE_LONG_LONG_INT) + static octave_value make (long long int i) + { + return octave_value (0, new octave_scalar (i)); + } +#endif + +#if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) + static octave_value make (unsigned long long int i) + { + return octave_value (0, new octave_scalar (i)); + } +#endif + + static octave_value make (octave::sys::time t) + { + return octave_value (0, new octave_scalar (t.double_value ())); + } + + static octave_value make (const Complex& C) + { + octave_value ov(0, new octave_complex (C)); + ov.maybe_mutate (); // Fold e.g. 1+0i to 1 + return ov; + } + + static octave_value make (const FloatComplex& C) + { + octave_value ov(0, new octave_float_complex (C)); + ov.maybe_mutate (); + return ov; + } + + static octave_value make (bool b) + { + return octave_value (0, new octave_bool (b)); + } + + static octave_value make_copy (octave_base_value *rep) + { + return octave_value (0, 0, rep); + } + + private: + ~octave_value_factory () = delete; + octave_value_factory () = delete; +}; + +#endif