3665
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 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 |
|
31 #include <iostream> |
|
32 |
|
33 #include "oct-obj.h" |
|
34 #include "ov-base.h" |
|
35 #include "ov-base-nd-array.h" |
|
36 #include "pr-output.h" |
|
37 |
|
38 static Array<idx_vector> |
|
39 idx_list_to_idx_array (const octave_value_list& idx) |
|
40 { |
|
41 int n = idx.length (); |
|
42 |
|
43 Array<idx_vector> retval (n); |
|
44 |
|
45 for (int i = 0; i < n; i++) |
|
46 retval(i) = idx(i).index_vector (); |
|
47 |
|
48 return retval; |
|
49 } |
|
50 |
|
51 template <class AT> |
|
52 octave_value |
|
53 octave_base_nd_array<AT>::do_index_op (const octave_value_list& idx) |
|
54 { |
|
55 octave_value retval; |
|
56 |
|
57 int len = idx.length (); |
|
58 |
|
59 if (len > 1) |
|
60 { |
|
61 Array<idx_vector> i = idx_list_to_idx_array (idx); |
|
62 |
|
63 retval |
|
64 = octave_value (new octave_base_nd_array<AT> (AT (array.index (i)))); |
|
65 } |
|
66 else if (len == 1) |
|
67 { |
|
68 idx_vector i = idx(0).index_vector (); |
|
69 |
|
70 retval |
|
71 = octave_value (new octave_base_nd_array<AT> (AT (array.index (i)))); |
|
72 } |
|
73 else |
|
74 { |
|
75 std::string n = type_name (); |
|
76 |
|
77 error ("invalid number of indices (%d) for %s value", |
|
78 len, n.c_str ()); |
|
79 } |
|
80 |
|
81 return retval; |
|
82 } |
|
83 |
|
84 template <class AT> |
|
85 bool |
|
86 octave_base_nd_array<AT>::is_true (void) const |
|
87 { |
|
88 // XXX FIXME XXX |
|
89 return false; |
|
90 } |
|
91 |
|
92 template <class AT> |
|
93 bool |
|
94 octave_base_nd_array<AT>::print_as_scalar (void) const |
|
95 { |
|
96 // XXX FIXME XXX |
|
97 return false; |
|
98 } |
|
99 |
|
100 template <class AT> |
|
101 void |
|
102 octave_base_nd_array<AT>::print (std::ostream& os, |
|
103 bool pr_as_read_syntax) const |
|
104 { |
|
105 print_raw (os, pr_as_read_syntax); |
|
106 newline (os); |
|
107 } |
|
108 |
|
109 template <class AT> |
|
110 void |
|
111 octave_base_nd_array<AT>::print_raw (std::ostream& os, |
|
112 bool pr_as_read_syntax) const |
|
113 { |
|
114 // XXX FIXME XX |
|
115 os << array; |
|
116 #if 0 |
|
117 octave_print_internal (os, array, pr_as_read_syntax, |
|
118 current_print_indent_level ()); |
|
119 #endif |
|
120 } |
|
121 |
|
122 template <class AT> |
|
123 bool |
|
124 octave_base_nd_array<AT>::print_name_tag (std::ostream& os, |
|
125 const std::string& name) const |
|
126 { |
|
127 bool retval = false; |
|
128 |
|
129 indent (os); |
|
130 |
|
131 if (print_as_scalar ()) |
|
132 os << name << " = "; |
|
133 else |
|
134 { |
|
135 os << name << " ="; |
|
136 newline (os); |
|
137 newline (os); |
|
138 retval = true; |
|
139 } |
|
140 |
|
141 return retval; |
|
142 } |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |