2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
2901
|
32 |
2376
|
33 #include "defun.h" |
|
34 #include "gripes.h" |
|
35 #include "oct-obj.h" |
|
36 #include "ov-scalar.h" |
3223
|
37 #include "ov-base.h" |
|
38 #include "ov-base-scalar.h" |
|
39 #include "ov-base-scalar.cc" |
2423
|
40 #include "ov-re-mat.h" |
2376
|
41 #include "ov-typeinfo.h" |
|
42 #include "pr-output.h" |
|
43 #include "xdiv.h" |
|
44 #include "xpow.h" |
|
45 |
3223
|
46 template class octave_base_scalar<double>; |
|
47 |
3219
|
48 DEFINE_OCTAVE_ALLOCATOR (octave_scalar); |
2376
|
49 |
3219
|
50 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_scalar, "scalar"); |
2376
|
51 |
|
52 octave_value |
3933
|
53 octave_scalar::do_index_op (const octave_value_list& idx, int resize_ok) |
2376
|
54 { |
|
55 octave_value retval; |
|
56 |
3933
|
57 if (idx.valid_scalar_indices ()) |
2376
|
58 retval = scalar; |
|
59 else |
|
60 { |
|
61 // XXX FIXME XXX -- this doesn't solve the problem of |
|
62 // |
|
63 // a = 1; a([1,1], [1,1], [1,1]) |
|
64 // |
|
65 // and similar constructions. Hmm... |
|
66 |
2423
|
67 // XXX FIXME XXX -- using this constructor avoids narrowing the |
|
68 // 1x1 matrix back to a scalar value. Need a better solution |
|
69 // to this problem. |
|
70 |
|
71 octave_value tmp (new octave_matrix (matrix_value ())); |
2376
|
72 |
3933
|
73 retval = tmp.do_index_op (idx, resize_ok); |
2376
|
74 } |
|
75 |
|
76 return retval; |
|
77 } |
|
78 |
|
79 octave_value |
4457
|
80 octave_scalar::convert_to_str_internal (bool, bool) const |
2376
|
81 { |
|
82 octave_value retval; |
|
83 |
|
84 if (xisnan (scalar)) |
|
85 ::error ("invalid conversion from NaN to character"); |
|
86 else |
|
87 { |
4100
|
88 int ival = NINT (scalar); |
|
89 |
|
90 if (ival < 0 || ival > UCHAR_MAX) |
|
91 { |
|
92 // XXX FIXME XXX -- is there something better we could do? |
|
93 |
|
94 ival = 0; |
|
95 |
|
96 ::warning ("range error for conversion to character value"); |
|
97 } |
|
98 |
|
99 retval = octave_value (std::string (1, static_cast<char> (ival))); |
2376
|
100 } |
|
101 |
|
102 return retval; |
|
103 } |
|
104 |
|
105 /* |
|
106 ;;; Local Variables: *** |
|
107 ;;; mode: C++ *** |
|
108 ;;; End: *** |
|
109 */ |