annotate libinterp/corefcn/oct-handle.h @ 19075:14bb81940528 stable

doc: Update docstring for datenum to describe format argument (bug #43181) * datenum.m: Update docstring to describe the format argument exactly like the docstring for datevec. Add test using format argument.
author Mike Miller <mtmiller@ieee.org>
date Wed, 10 Sep 2014 08:19:43 -0400
parents ebb3ef964372
children 4197fc428c7d
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
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17544
diff changeset
3 Copyright (C) 2007-2013 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 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 double tval = a.double_value ();
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 if (! error_state)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 val = tval;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 else
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 error ("invalid handle");
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 }
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 octave_handle (int a) : val (a) { }
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 (double 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 (const octave_handle& a) : val (a.val) { }
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& operator = (const octave_handle& a)
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 if (&a != this)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 val = a.val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 return *this;
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 ~octave_handle (void) { }
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 double value (void) const { return val; }
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 octave_value as_octave_value (void) const
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 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
75 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 // Prefix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 octave_handle& operator ++ (void)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 ++val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 octave_handle& operator -- (void)
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 --val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 return *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 // Postfix increment/decrement operators.
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 const octave_handle operator ++ (int)
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 ++(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 const octave_handle operator -- (int)
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 octave_handle old_value = *this;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 --(*this);
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 return old_value;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 }
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 bool ok (void) const { return ! xisnan (val); }
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 private:
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 double val;
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 };
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 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
113 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 return a.value () == b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 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
119 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 return a.value () != b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 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
125 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 return a.value () < b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 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
131 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 return a.value () <= b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 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
137 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 return a.value () >= b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 inline bool
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 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
143 {
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 return a.value () > b.value ();
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
fc31cd1bd503 extract handle object to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 #endif