Mercurial > hg > octave-jordi
annotate src/oct-obj.cc @ 8437:f00578b495e9
remove valid_as_scalar_index
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 27 Dec 2008 17:01:52 +0100 |
parents | 283989f2da9b |
children | fd11a08a9b31 |
rev | line source |
---|---|
517 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, |
4 2004, 2005, 2006, 2007 John W. Eaton | |
517 | 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. | |
517 | 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/>. | |
517 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
1192 | 25 #include <config.h> |
517 | 26 #endif |
27 | |
1968 | 28 #include "error.h" |
1742 | 29 #include "oct-obj.h" |
517 | 30 |
2970 | 31 octave_allocator |
32 octave_value_list::allocator (sizeof (octave_value_list)); | |
33 | |
4591 | 34 void |
5275 | 35 octave_value_list::resize (octave_idx_type n, const octave_value& val) |
4591 | 36 { |
5275 | 37 octave_idx_type len = length (); |
4591 | 38 |
39 if (n > len) | |
40 { | |
41 data.resize (n); | |
42 | |
5275 | 43 for (octave_idx_type i = len; i < n; i++) |
4591 | 44 data[i] = val; |
45 } | |
46 else if (n < len) | |
47 data.resize (n); | |
48 } | |
49 | |
2872 | 50 octave_value_list& |
51 octave_value_list::prepend (const octave_value& val) | |
52 { | |
5275 | 53 octave_idx_type n = length (); |
2872 | 54 |
55 resize (n + 1); | |
56 | |
57 while (n > 0) | |
58 { | |
59 elem (n) = elem (n - 1); | |
60 n--; | |
61 } | |
62 | |
63 elem (0) = val; | |
64 | |
65 return *this; | |
66 } | |
67 | |
68 octave_value_list& | |
69 octave_value_list::append (const octave_value& val) | |
70 { | |
5275 | 71 octave_idx_type n = length (); |
2872 | 72 |
73 resize (n + 1); | |
74 | |
75 elem (n) = val; | |
76 | |
77 return *this; | |
78 } | |
79 | |
80 octave_value_list& | |
81 octave_value_list::append (const octave_value_list& lst) | |
82 { | |
5275 | 83 octave_idx_type len = length (); |
84 octave_idx_type lst_len = lst.length (); | |
2872 | 85 |
86 resize (len + lst_len); | |
87 | |
5275 | 88 for (octave_idx_type i = 0; i < lst_len; i++) |
2872 | 89 elem (len + i) = lst (i); |
90 | |
91 return *this; | |
92 } | |
93 | |
94 octave_value_list& | |
95 octave_value_list::reverse (void) | |
96 { | |
5275 | 97 octave_idx_type n = length (); |
2872 | 98 |
5275 | 99 for (octave_idx_type i = 0; i < n / 2; i++) |
2872 | 100 { |
101 octave_value tmp = elem (i); | |
102 elem (i) = elem (n - i - 1); | |
103 elem (n - i - 1) = tmp; | |
104 } | |
105 | |
106 return *this; | |
107 } | |
108 | |
3195 | 109 octave_value_list |
5275 | 110 octave_value_list::splice (octave_idx_type offset, octave_idx_type rep_length, |
3195 | 111 const octave_value_list& lst) const |
112 { | |
113 octave_value_list retval; | |
114 | |
5275 | 115 octave_idx_type len = length (); |
3195 | 116 |
117 if (offset < 0 || offset >= len) | |
118 { | |
3219 | 119 if (! (rep_length == 0 && offset == len)) |
120 { | |
121 error ("octave_value_list::splice: invalid OFFSET"); | |
122 return retval; | |
123 } | |
3195 | 124 } |
125 | |
126 if (rep_length < 0 || rep_length + offset > len) | |
127 { | |
128 error ("octave_value_list::splice: invalid LENGTH"); | |
129 return retval; | |
130 } | |
131 | |
5275 | 132 octave_idx_type lst_len = lst.length (); |
3195 | 133 |
5275 | 134 octave_idx_type new_len = len - rep_length + lst_len; |
3195 | 135 |
136 retval.resize (new_len); | |
137 | |
5275 | 138 octave_idx_type k = 0; |
3195 | 139 |
5275 | 140 for (octave_idx_type i = 0; i < offset; i++) |
3195 | 141 retval(k++) = elem (i); |
142 | |
5275 | 143 for (octave_idx_type i = 0; i < lst_len; i++) |
3195 | 144 retval(k++) = lst(i); |
145 | |
5275 | 146 for (octave_idx_type i = offset + rep_length; i < len; i++) |
3195 | 147 retval(k++) = elem (i); |
148 | |
149 return retval; | |
150 } | |
151 | |
2872 | 152 bool |
153 octave_value_list::all_strings_p (void) const | |
1968 | 154 { |
5275 | 155 octave_idx_type n = length (); |
517 | 156 |
5275 | 157 for (octave_idx_type i = 0; i < n; i++) |
1968 | 158 if (! elem(i).is_string ()) |
5846 | 159 return false; |
160 | |
161 return true; | |
162 } | |
1746 | 163 |
5846 | 164 bool |
165 octave_value_list::has_magic_colon (void) const | |
166 { | |
167 octave_idx_type n = length (); | |
168 | |
169 for (octave_idx_type i = 0; i < n; i++) | |
170 if (elem(i).is_magic_colon ()) | |
171 return true; | |
172 | |
173 return false; | |
517 | 174 } |
175 | |
1968 | 176 string_vector |
3523 | 177 octave_value_list::make_argv (const std::string& fcn_name) const |
517 | 178 { |
1968 | 179 string_vector argv; |
180 | |
2872 | 181 if (all_strings_p ()) |
1968 | 182 { |
5275 | 183 octave_idx_type len = length (); |
3180 | 184 |
5275 | 185 octave_idx_type total_nr = 0; |
3180 | 186 |
5275 | 187 for (octave_idx_type i = 0; i < len; i++) |
3264 | 188 { |
3523 | 189 // An empty std::string ("") has zero columns and zero rows (a |
3264 | 190 // change that was made for Matlab contemptibility. |
191 | |
5275 | 192 octave_idx_type n = elem(i).rows (); |
3264 | 193 |
194 total_nr += n ? n : 1; | |
195 } | |
3180 | 196 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
197 octave_idx_type k = 0; |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
198 if (! fcn_name.empty ()) |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
199 { |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
200 argv.resize (total_nr+1); |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
201 argv[0] = fcn_name; |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
202 k = 1; |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
203 } |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
204 else |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
205 argv.resize (total_nr); |
3180 | 206 |
5275 | 207 for (octave_idx_type i = 0; i < len; i++) |
3180 | 208 { |
5275 | 209 octave_idx_type nr = elem(i).rows (); |
3180 | 210 |
3264 | 211 if (nr < 2) |
3180 | 212 argv[k++] = elem(i).string_value (); |
213 else | |
214 { | |
215 string_vector tmp = elem(i).all_strings (); | |
216 | |
5275 | 217 for (octave_idx_type j = 0; j < nr; j++) |
3180 | 218 argv[k++] = tmp[j]; |
219 } | |
220 } | |
1968 | 221 } |
222 else | |
223 error ("%s: expecting all arguments to be strings", fcn_name.c_str ()); | |
517 | 224 |
1968 | 225 return argv; |
517 | 226 } |
227 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
228 void |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
229 octave_value_list::normalize_null_values (void) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
230 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
231 octave_idx_type len = length (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
232 for (octave_idx_type i = 0; i < len; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
233 data[i].make_non_null_value (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
234 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8034
diff
changeset
|
235 |
517 | 236 /* |
237 ;;; Local Variables: *** | |
238 ;;; mode: C++ *** | |
239 ;;; End: *** | |
240 */ |