GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-handle.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2007-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_oct_handle_h)
27#define octave_oct_handle_h 1
28
29#include "octave-config.h"
30
31#include "dMatrix.h"
32#include "lo-ieee.h"
33
34#include "error.h"
35#include "ov.h"
36
37// ---------------------------------------------------------------------
38
40{
41public:
42 octave_handle () : m_dval (octave::numeric_limits<double>::NaN ()) { }
43
45 : m_dval (octave::numeric_limits<double>::NaN ())
46 {
47 if (a.isempty ())
48 ; // do nothing
49 else
50 {
51 try
52 {
53 m_dval = a.double_value ();
54 }
55 catch (octave::execution_exception& ee)
56 {
57 error (ee, "invalid handle");
58 }
59 }
60 }
61
62 octave_handle (int a) : m_dval (a) { }
63
64 octave_handle (double a) : m_dval (a) { }
65
66 octave_handle (const octave_handle& a) : m_dval (a.m_dval) { }
67
69 {
70 if (&a != this)
71 m_dval = a.m_dval;
72
73 return *this;
74 }
75
76 ~octave_handle () = default;
77
78 double value () const { return m_dval; }
79
81 {
82 return ok () ? octave_value (m_dval) : octave_value (Matrix ());
83 }
84
85 // Prefix increment/decrement operators.
87 {
88 ++m_dval;
89 return *this;
90 }
91
93 {
94 --m_dval;
95 return *this;
96 }
97
98 // Postfix increment/decrement operators.
100 {
101 octave_handle old_value = *this;
102 ++(*this);
103 return old_value;
104 }
105
107 {
108 octave_handle old_value = *this;
109 --(*this);
110 return old_value;
111 }
112
113 bool ok () const { return ! octave::math::isnan (m_dval); }
114
115private:
116 double m_dval;
117};
118
119inline bool
121{
122 return a.value () == b.value ();
123}
124
125inline bool
127{
128 return a.value () != b.value ();
129}
130
131inline bool
132operator < (const octave_handle& a, const octave_handle& b)
133{
134 return a.value () < b.value ();
135}
136
137inline bool
138operator <= (const octave_handle& a, const octave_handle& b)
139{
140 return a.value () <= b.value ();
141}
142
143inline bool
145{
146 return a.value () >= b.value ();
147}
148
149inline bool
151{
152 return a.value () > b.value ();
153}
154
155#endif
#define NaN
Definition Faddeeva.cc:258
~octave_handle()=default
double value() const
Definition oct-handle.h:78
octave_handle(const octave_value &a)
Definition oct-handle.h:44
octave_handle & operator++()
Definition oct-handle.h:86
octave_handle(const octave_handle &a)
Definition oct-handle.h:66
octave_handle(int a)
Definition oct-handle.h:62
octave_handle & operator=(const octave_handle &a)
Definition oct-handle.h:68
bool ok() const
Definition oct-handle.h:113
octave_value as_octave_value() const
Definition oct-handle.h:80
octave_handle & operator--()
Definition oct-handle.h:92
octave_handle(double a)
Definition oct-handle.h:64
bool isempty() const
Definition ov.h:601
double double_value(bool frc_str_conv=false) const
Definition ov.h:847
void error(const char *fmt,...)
Definition error.cc:1003
bool operator==(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:120
bool operator<(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:132
bool operator!=(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:126
bool operator<=(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:138
bool operator>(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:150
bool operator>=(const octave_handle &a, const octave_handle &b)
Definition oct-handle.h:144