GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-handle.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2013 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_oct_handle_h)
24 #define octave_oct_handle_h 1
25 
26 #include "dMatrix.h"
27 #include "lo-ieee.h"
28 
29 #include "ov.h"
30 
31 // ---------------------------------------------------------------------
32 
34 {
35 public:
36  octave_handle (void) : val (octave_NaN) { }
37 
39  : val (octave_NaN)
40  {
41  if (a.is_empty ())
42  /* do nothing */;
43  else
44  {
45  double tval = a.double_value ();
46 
47  if (! error_state)
48  val = tval;
49  else
50  error ("invalid handle");
51  }
52  }
53 
54  octave_handle (int a) : val (a) { }
55 
56  octave_handle (double a) : val (a) { }
57 
58  octave_handle (const octave_handle& a) : val (a.val) { }
59 
61  {
62  if (&a != this)
63  val = a.val;
64 
65  return *this;
66  }
67 
68  ~octave_handle (void) { }
69 
70  double value (void) const { return val; }
71 
73  {
74  return ok () ? octave_value (val) : octave_value (Matrix ());
75  }
76 
77  // Prefix increment/decrement operators.
79  {
80  ++val;
81  return *this;
82  }
83 
85  {
86  --val;
87  return *this;
88  }
89 
90  // Postfix increment/decrement operators.
92  {
93  octave_handle old_value = *this;
94  ++(*this);
95  return old_value;
96  }
97 
99  {
100  octave_handle old_value = *this;
101  --(*this);
102  return old_value;
103  }
104 
105  bool ok (void) const { return ! xisnan (val); }
106 
107 private:
108  double val;
109 };
110 
111 inline bool
113 {
114  return a.value () == b.value ();
115 }
116 
117 inline bool
119 {
120  return a.value () != b.value ();
121 }
122 
123 inline bool
125 {
126  return a.value () < b.value ();
127 }
128 
129 inline bool
131 {
132  return a.value () <= b.value ();
133 }
134 
135 inline bool
137 {
138  return a.value () >= b.value ();
139 }
140 
141 inline bool
143 {
144  return a.value () > b.value ();
145 }
146 
147 #endif