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