comparison libinterp/corefcn/oct-handle.h @ 17544:fc31cd1bd503

extract handle object to a separate file * oct-handle.h: New file. * libinterp/corefcn/module.mk (COREFCN_INC): Add it to the list. * graphics.in.h, graphics.cc (graphics_handle class): move to oct-handle.h and rename octave_handle. (graphics_handle): Now a typedef for octave_handle.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Oct 2013 19:52:39 -0400
parents
children d63878346099
comparison
equal deleted inserted replaced
17543:dbda6edfe01d 17544:fc31cd1bd503
1 /*
2
3 Copyright (C) 2007-2012 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_handle_h)
24 #define octave_handle_h 1
25
26 #include "dMatrix.h"
27 #include "lo-ieee.h"
28
29 #include "ov.h"
30
31 // ---------------------------------------------------------------------
32
33 class octave_handle
34 {
35 public:
36 octave_handle (void) : val (octave_NaN) { }
37
38 octave_handle (const octave_value& a)
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
60 octave_handle& operator = (const octave_handle& a)
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
72 octave_value as_octave_value (void) const
73 {
74 return ok () ? octave_value (val) : octave_value (Matrix ());
75 }
76
77 // Prefix increment/decrement operators.
78 octave_handle& operator ++ (void)
79 {
80 ++val;
81 return *this;
82 }
83
84 octave_handle& operator -- (void)
85 {
86 --val;
87 return *this;
88 }
89
90 // Postfix increment/decrement operators.
91 const octave_handle operator ++ (int)
92 {
93 octave_handle old_value = *this;
94 ++(*this);
95 return old_value;
96 }
97
98 const octave_handle operator -- (int)
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
112 operator == (const octave_handle& a, const octave_handle& b)
113 {
114 return a.value () == b.value ();
115 }
116
117 inline bool
118 operator != (const octave_handle& a, const octave_handle& b)
119 {
120 return a.value () != b.value ();
121 }
122
123 inline bool
124 operator < (const octave_handle& a, const octave_handle& b)
125 {
126 return a.value () < b.value ();
127 }
128
129 inline bool
130 operator <= (const octave_handle& a, const octave_handle& b)
131 {
132 return a.value () <= b.value ();
133 }
134
135 inline bool
136 operator >= (const octave_handle& a, const octave_handle& b)
137 {
138 return a.value () >= b.value ();
139 }
140
141 inline bool
142 operator > (const octave_handle& a, const octave_handle& b)
143 {
144 return a.value () > b.value ();
145 }
146
147 #endif