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