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