annotate src/ov-base-scalar.cc @ 8874:bd1b1fe9c6e9 ss-3-1-53

bump version info for snapshot
author John W. Eaton <jwe@octave.org>
date Wed, 25 Feb 2009 18:35:47 -0500
parents 1dce30ab0e72
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
1 /*
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 1999, 2000, 2002, 2004, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
5
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
7
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 option) any later version.
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
12
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
16 for more details.
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
17
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
20 <http://www.gnu.org/licenses/>.
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
21
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
22 */
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
23
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
26 #endif
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
27
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3277
diff changeset
28 #include <iostream>
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
29
4055
7690958e7726 [project @ 2002-08-18 01:56:58 by jwe]
jwe
parents: 3933
diff changeset
30 #include "oct-obj.h"
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
31 #include "ov-base.h"
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
32 #include "ov-cx-mat.h"
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
33 #include "ov-re-mat.h"
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
34 #include "ov-base-scalar.h"
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
35 #include "pr-output.h"
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
36
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
37 template <class ST>
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
38 octave_value
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4219
diff changeset
39 octave_base_scalar<ST>::subsref (const std::string& type,
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4192
diff changeset
40 const std::list<octave_value_list>& idx)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
41 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
42 octave_value retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
43
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
44 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
45 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
46 case '(':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
47 retval = do_index_op (idx.front ());
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
48 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
49
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
50 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
51 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
52 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
53 std::string nm = type_name ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
54 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
55 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
56 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
57
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
58 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
59 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
60 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
61
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
62 return retval.next_subsref (type, idx);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
63 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
64
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
65 template <class ST>
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
66 octave_value
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4219
diff changeset
67 octave_base_scalar<ST>::subsasgn (const std::string& type,
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4192
diff changeset
68 const std::list<octave_value_list>& idx,
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
69 const octave_value& rhs)
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
70 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
71 octave_value retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
72
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
73 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
74 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
75 case '(':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
76 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
77 if (type.length () == 1)
8437
f00578b495e9 remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
78 retval = numeric_assign (type, idx, rhs);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
79 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
80 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
81 std::string nm = type_name ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
82 error ("in indexed assignment of %s, last rhs index must be ()",
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
83 nm.c_str ());
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
84 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
85 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
86 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
87
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
88 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
89 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
90 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
91 std::string nm = type_name ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
92 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
93 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
94 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
95
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
96 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
97 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
98 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
99
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
100 return retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
101 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
102
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
103 template <class ST>
8626
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
104 bool
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
105 octave_base_scalar<ST>::is_true (void) const
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
106 {
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
107 bool retval = false;
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
108
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
109 if (xisnan (scalar))
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
110 error ("invalid conversion from NaN to logical");
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
111 else
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
112 retval = (scalar != ST ());
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
113
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
114 return retval;
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
115 }
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
116
1dce30ab0e72 don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents: 8437
diff changeset
117 template <class ST>
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
118 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
119 octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) const
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
120 {
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
121 print_raw (os, pr_as_read_syntax);
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
122 newline (os);
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
123 }
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
124
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
125 template <class ST>
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
126 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
127 octave_base_scalar<ST>::print_raw (std::ostream& os,
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
128 bool pr_as_read_syntax) const
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
129 {
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
130 indent (os);
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
131 octave_print_internal (os, scalar, pr_as_read_syntax);
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
132 }
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
133
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
134 template <class ST>
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
135 bool
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
136 octave_base_scalar<ST>::print_name_tag (std::ostream& os,
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3523
diff changeset
137 const std::string& name) const
3277
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
138 {
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
139 indent (os);
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
140 os << name << " = ";
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
141 return false;
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
142 }
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
143
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
144 /*
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
145 ;;; Local Variables: ***
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
146 ;;; mode: C++ ***
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
147 ;;; End: ***
9a1ac83591c0 [project @ 1999-10-12 06:03:19 by jwe]
jwe
parents:
diff changeset
148 */