3277
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3277
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
3277
|
32 |
4055
|
33 #include "oct-obj.h" |
3277
|
34 #include "ov-base.h" |
3933
|
35 #include "ov-cx-mat.h" |
|
36 #include "ov-re-mat.h" |
3277
|
37 #include "ov-base-scalar.h" |
|
38 #include "pr-output.h" |
|
39 |
|
40 template <class ST> |
3933
|
41 octave_value |
|
42 octave_base_scalar<ST>::subsref (const std::string type, |
|
43 const SLList<octave_value_list>& idx) |
|
44 { |
|
45 octave_value retval; |
|
46 |
|
47 switch (type[0]) |
|
48 { |
|
49 case '(': |
|
50 retval = do_index_op (idx.front ()); |
|
51 break; |
|
52 |
|
53 case '{': |
|
54 case '.': |
|
55 { |
|
56 std::string nm = type_name (); |
|
57 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
58 } |
|
59 break; |
|
60 |
|
61 default: |
|
62 panic_impossible (); |
|
63 } |
|
64 |
|
65 return retval.next_subsref (type, idx); |
|
66 } |
|
67 |
|
68 template <class ST> |
|
69 octave_value |
|
70 octave_base_scalar<ST>::subsasgn (const std::string type, |
|
71 const SLList<octave_value_list>& idx, |
|
72 const octave_value& rhs) |
|
73 { |
|
74 octave_value retval; |
|
75 |
|
76 switch (type[0]) |
|
77 { |
|
78 case '(': |
|
79 { |
|
80 if (type.length () == 1) |
|
81 { |
|
82 if (idx.front().valid_scalar_indices () |
|
83 && rhs.is_scalar_type () |
|
84 && rhs.is_numeric_type ()) |
|
85 retval = rhs; |
|
86 else |
|
87 retval = numeric_assign (type, idx, rhs); |
|
88 } |
|
89 else |
|
90 { |
|
91 std::string nm = type_name (); |
|
92 error ("in indexed assignment of %s, last rhs index must be ()", |
|
93 nm.c_str ()); |
|
94 } |
|
95 } |
|
96 break; |
|
97 |
|
98 case '{': |
|
99 case '.': |
|
100 { |
|
101 std::string nm = type_name (); |
|
102 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
103 } |
|
104 break; |
|
105 |
|
106 default: |
|
107 panic_impossible (); |
|
108 } |
|
109 |
|
110 return retval; |
|
111 } |
|
112 |
|
113 template <class ST> |
3277
|
114 void |
3523
|
115 octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) const |
3277
|
116 { |
|
117 print_raw (os, pr_as_read_syntax); |
|
118 newline (os); |
|
119 } |
|
120 |
|
121 template <class ST> |
|
122 void |
3933
|
123 octave_base_scalar<ST>::print_raw (std::ostream& os, |
|
124 bool pr_as_read_syntax) const |
3277
|
125 { |
|
126 indent (os); |
|
127 octave_print_internal (os, scalar, pr_as_read_syntax); |
|
128 } |
|
129 |
|
130 template <class ST> |
|
131 bool |
3933
|
132 octave_base_scalar<ST>::print_name_tag (std::ostream& os, |
|
133 const std::string& name) const |
3277
|
134 { |
|
135 indent (os); |
|
136 os << name << " = "; |
|
137 return false; |
|
138 } |
|
139 |
|
140 /* |
|
141 ;;; Local Variables: *** |
|
142 ;;; mode: C++ *** |
|
143 ;;; End: *** |
|
144 */ |