GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-handle.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_oct_handle_h)
24 #define octave_oct_handle_h 1
25 
26 #include "octave-config.h"
27 
28 #include "dMatrix.h"
29 #include "lo-ieee.h"
30 
31 #include "ov.h"
32 
33 // ---------------------------------------------------------------------
34 
36 {
37 public:
38  octave_handle (void) : val (octave::numeric_limits<double>::NaN ()) { }
39 
41  : val (octave::numeric_limits<double>::NaN ())
42  {
43  if (a.isempty ())
44  ; // do nothing
45  else
46  {
47  try
48  {
49  val = a.double_value ();
50  }
51  catch (octave::execution_exception& e)
52  {
53  error (e, "invalid handle");
54  }
55  }
56  }
57 
58  octave_handle (int a) : val (a) { }
59 
60  octave_handle (double a) : val (a) { }
61 
62  octave_handle (const octave_handle& a) : val (a.val) { }
63 
65  {
66  if (&a != this)
67  val = a.val;
68 
69  return *this;
70  }
71 
72  ~octave_handle (void) = default;
73 
74  double value (void) const { return val; }
75 
77  {
78  return ok () ? octave_value (val) : octave_value (Matrix ());
79  }
80 
81  // Prefix increment/decrement operators.
83  {
84  ++val;
85  return *this;
86  }
87 
89  {
90  --val;
91  return *this;
92  }
93 
94  // Postfix increment/decrement operators.
96  {
97  octave_handle old_value = *this;
98  ++(*this);
99  return old_value;
100  }
101 
103  {
104  octave_handle old_value = *this;
105  --(*this);
106  return old_value;
107  }
108 
109  bool ok (void) const { return ! octave::math::isnan (val); }
110 
111 private:
112  double val;
113 };
114 
115 inline bool
117 {
118  return a.value () == b.value ();
119 }
120 
121 inline bool
123 {
124  return a.value () != b.value ();
125 }
126 
127 inline bool
129 {
130  return a.value () < b.value ();
131 }
132 
133 inline bool
135 {
136  return a.value () <= b.value ();
137 }
138 
139 inline bool
141 {
142  return a.value () >= b.value ();
143 }
144 
145 inline bool
147 {
148  return a.value () > b.value ();
149 }
150 
151 #endif
bool ok(void) const
Definition: oct-handle.h:109
octave_handle(void)
Definition: oct-handle.h:38
octave_handle(double a)
Definition: oct-handle.h:60
bool operator>(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:146
double value(void) const
Definition: oct-handle.h:74
octave_handle & operator=(const octave_handle &a)
Definition: oct-handle.h:64
bool isnan(bool)
Definition: lo-mappers.h:187
void error(const char *fmt,...)
Definition: error.cc:578
bool operator<(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:128
bool operator==(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:116
bool operator>=(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:140
i e
Definition: data.cc:2591
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
octave_handle & operator--(void)
Definition: oct-handle.h:88
bool operator!=(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:122
octave_value as_octave_value(void) const
Definition: oct-handle.h:76
octave_handle(const octave_handle &a)
Definition: oct-handle.h:62
Definition: dMatrix.h:36
octave_handle & operator++(void)
Definition: oct-handle.h:82
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol NaN(Not a Number). NaN is the result of operations which do not produce a well defined 0 result. Common operations which produce a NaN are arithmetic with infinity ex($\infty - \infty$)
octave_handle(int a)
Definition: oct-handle.h:58
b
Definition: cellfun.cc:400
bool operator<=(const octave_handle &a, const octave_handle &b)
Definition: oct-handle.h:134
octave_handle(const octave_value &a)
Definition: oct-handle.h:40
~octave_handle(void)=default