3277
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1999, 2000, 2002, 2004, 2005, 2007 |
|
4 John W. Eaton |
3277
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3277
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
3277
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
3277
|
29 |
4055
|
30 #include "oct-obj.h" |
3277
|
31 #include "ov-base.h" |
3933
|
32 #include "ov-cx-mat.h" |
|
33 #include "ov-re-mat.h" |
3277
|
34 #include "ov-base-scalar.h" |
|
35 #include "pr-output.h" |
|
36 |
|
37 template <class ST> |
3933
|
38 octave_value |
4247
|
39 octave_base_scalar<ST>::subsref (const std::string& type, |
4219
|
40 const std::list<octave_value_list>& idx) |
3933
|
41 { |
|
42 octave_value retval; |
|
43 |
|
44 switch (type[0]) |
|
45 { |
|
46 case '(': |
|
47 retval = do_index_op (idx.front ()); |
|
48 break; |
|
49 |
|
50 case '{': |
|
51 case '.': |
|
52 { |
|
53 std::string nm = type_name (); |
|
54 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
55 } |
|
56 break; |
|
57 |
|
58 default: |
|
59 panic_impossible (); |
|
60 } |
|
61 |
|
62 return retval.next_subsref (type, idx); |
|
63 } |
|
64 |
|
65 template <class ST> |
|
66 octave_value |
4247
|
67 octave_base_scalar<ST>::subsasgn (const std::string& type, |
4219
|
68 const std::list<octave_value_list>& idx, |
3933
|
69 const octave_value& rhs) |
|
70 { |
|
71 octave_value retval; |
|
72 |
|
73 switch (type[0]) |
|
74 { |
|
75 case '(': |
|
76 { |
|
77 if (type.length () == 1) |
|
78 { |
|
79 if (idx.front().valid_scalar_indices () |
|
80 && rhs.is_scalar_type () |
|
81 && rhs.is_numeric_type ()) |
|
82 retval = rhs; |
|
83 else |
|
84 retval = numeric_assign (type, idx, rhs); |
|
85 } |
|
86 else |
|
87 { |
|
88 std::string nm = type_name (); |
|
89 error ("in indexed assignment of %s, last rhs index must be ()", |
|
90 nm.c_str ()); |
|
91 } |
|
92 } |
|
93 break; |
|
94 |
|
95 case '{': |
|
96 case '.': |
|
97 { |
|
98 std::string nm = type_name (); |
|
99 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
100 } |
|
101 break; |
|
102 |
|
103 default: |
|
104 panic_impossible (); |
|
105 } |
|
106 |
|
107 return retval; |
|
108 } |
|
109 |
|
110 template <class ST> |
3277
|
111 void |
3523
|
112 octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax) const |
3277
|
113 { |
|
114 print_raw (os, pr_as_read_syntax); |
|
115 newline (os); |
|
116 } |
|
117 |
|
118 template <class ST> |
|
119 void |
3933
|
120 octave_base_scalar<ST>::print_raw (std::ostream& os, |
|
121 bool pr_as_read_syntax) const |
3277
|
122 { |
|
123 indent (os); |
|
124 octave_print_internal (os, scalar, pr_as_read_syntax); |
|
125 } |
|
126 |
|
127 template <class ST> |
|
128 bool |
3933
|
129 octave_base_scalar<ST>::print_name_tag (std::ostream& os, |
|
130 const std::string& name) const |
3277
|
131 { |
|
132 indent (os); |
|
133 os << name << " = "; |
|
134 return false; |
|
135 } |
|
136 |
|
137 /* |
|
138 ;;; Local Variables: *** |
|
139 ;;; mode: C++ *** |
|
140 ;;; End: *** |
|
141 */ |