2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "defun.h" |
|
32 #include "gripes.h" |
|
33 #include "oct-obj.h" |
|
34 #include "ov-scalar.h" |
|
35 #include "ov-typeinfo.h" |
|
36 #include "pr-output.h" |
|
37 #include "xdiv.h" |
|
38 #include "xpow.h" |
|
39 |
|
40 int octave_scalar::t_id = -1; |
|
41 |
|
42 const string octave_scalar::t_name ("scalar"); |
|
43 |
|
44 static inline bool |
|
45 valid_scalar_indices (const octave_value_list& args) |
|
46 { |
|
47 int nargin = args.length (); |
|
48 |
|
49 for (int i = 0; i < nargin; i++) |
|
50 if (! args(i).valid_as_scalar_index ()) |
|
51 return false; |
|
52 |
|
53 return true; |
|
54 } |
|
55 |
|
56 octave_value |
|
57 octave_scalar::index (const octave_value_list& idx) const |
|
58 { |
|
59 octave_value retval; |
|
60 |
|
61 if (valid_scalar_indices (idx)) |
|
62 retval = scalar; |
|
63 else |
|
64 { |
|
65 // XXX FIXME XXX -- this doesn't solve the problem of |
|
66 // |
|
67 // a = 1; a([1,1], [1,1], [1,1]) |
|
68 // |
|
69 // and similar constructions. Hmm... |
|
70 |
|
71 octave_value tmp (matrix_value ()); |
|
72 |
|
73 retval = tmp.index (idx); |
|
74 } |
|
75 |
|
76 return retval; |
|
77 } |
|
78 |
|
79 octave_value |
|
80 octave_scalar::convert_to_str (void) const |
|
81 { |
|
82 octave_value retval; |
|
83 |
|
84 if (xisnan (scalar)) |
|
85 ::error ("invalid conversion from NaN to character"); |
|
86 else |
|
87 { |
|
88 // XXX FIXME XXX -- warn about out of range conversions? |
|
89 |
|
90 int i = NINT (scalar); |
|
91 char s[2]; |
|
92 s[0] = (char) i; |
|
93 s[1] = '\0'; |
|
94 retval = octave_value (s); |
|
95 } |
|
96 |
|
97 return retval; |
|
98 } |
|
99 |
|
100 void |
|
101 octave_scalar::print (ostream& os) |
|
102 { |
|
103 octave_print_internal (os, scalar, false); |
|
104 } |
|
105 |
|
106 /* |
|
107 ;;; Local Variables: *** |
|
108 ;;; mode: C++ *** |
|
109 ;;; End: *** |
|
110 */ |