annotate libinterp/corefcn/oct-handle.h @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents c547458dc10e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
3 Copyright (C) 2007-2015 John W. Eaton
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 option) any later version.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 for more details.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17744
diff changeset
23 #if !defined (octave_oct_handle_h)
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 #define octave_oct_handle_h 1
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #include "dMatrix.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include "lo-ieee.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "ov.h"
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 // ---------------------------------------------------------------------
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 class octave_handle
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 public:
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 octave_handle (void) : val (octave_NaN) { }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 octave_handle (const octave_value& a)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 : val (octave_NaN)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 if (a.is_empty ())
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 /* do nothing */;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 else
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 {
20577
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
45 try
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
46 {
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
47 val = a.double_value ();
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
48 }
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
49 catch (const octave_execution_exception&)
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
50 {
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
51 error ("invalid handle");
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
52 }
17544
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 octave_handle (int a) : val (a) { }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 octave_handle (double a) : val (a) { }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 octave_handle (const octave_handle& a) : val (a.val) { }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 octave_handle& operator = (const octave_handle& a)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if (&a != this)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 val = a.val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 ~octave_handle (void) { }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 double value (void) const { return val; }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 octave_value as_octave_value (void) const
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 return ok () ? octave_value (val) : octave_value (Matrix ());
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 // Prefix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 octave_handle& operator ++ (void)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 ++val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 octave_handle& operator -- (void)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 --val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 // Postfix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 const octave_handle operator ++ (int)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 ++(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 const octave_handle operator -- (int)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 --(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 bool ok (void) const { return ! xisnan (val); }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 private:
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 double val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 };
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 operator == (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 return a.value () == b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 operator != (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 return a.value () != b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 operator < (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 return a.value () < b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 operator <= (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 return a.value () <= b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 operator >= (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 return a.value () >= b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 operator > (const octave_handle& a, const octave_handle& b)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 return a.value () > b.value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 #endif