2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 (octave_value_h) |
|
24 #define octave_value_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2376
|
33 #include <string> |
4219
|
34 #include <list> |
2376
|
35 |
4507
|
36 |
2376
|
37 #include "Range.h" |
|
38 #include "idx-vector.h" |
|
39 #include "mx-base.h" |
2477
|
40 #include "oct-alloc.h" |
4254
|
41 #include "oct-time.h" |
2942
|
42 #include "str-vec.h" |
|
43 |
3351
|
44 class Cell; |
2376
|
45 class Octave_map; |
2903
|
46 class octave_stream; |
2974
|
47 class octave_function; |
4342
|
48 class octave_fcn_handle; |
2376
|
49 class octave_value_list; |
2979
|
50 class octave_lvalue; |
2376
|
51 |
|
52 // Constants. |
|
53 |
|
54 // This just provides a way to avoid infinite recursion when building |
|
55 // octave_value objects. |
|
56 |
|
57 class |
|
58 octave_xvalue |
|
59 { |
|
60 public: |
|
61 |
|
62 octave_xvalue (void) { } |
|
63 }; |
|
64 |
2427
|
65 class octave_value; |
|
66 |
|
67 // XXX FIXME XXX -- these should probably really be inside the scope |
|
68 // of the octave_value class, but the cygwin32 beta16 version of g++ |
3203
|
69 // can't handle that. |
|
70 |
|
71 typedef octave_value (*unary_op_fcn) |
|
72 (const octave_value&); |
|
73 |
|
74 typedef void (*non_const_unary_op_fcn) |
|
75 (octave_value&); |
2427
|
76 |
|
77 typedef octave_value (*binary_op_fcn) |
|
78 (const octave_value&, const octave_value&); |
|
79 |
|
80 typedef octave_value (*assign_op_fcn) |
|
81 (octave_value&, const octave_value_list&, const octave_value&); |
|
82 |
|
83 typedef octave_value * (*type_conv_fcn) (const octave_value&); |
|
84 |
2376
|
85 class |
2974
|
86 octave_value |
2376
|
87 { |
|
88 public: |
|
89 |
3203
|
90 enum unary_op |
|
91 { |
3525
|
92 op_not, |
|
93 op_uminus, |
|
94 op_transpose, |
|
95 op_hermitian, |
|
96 op_incr, |
|
97 op_decr, |
3203
|
98 num_unary_ops, |
|
99 unknown_unary_op |
|
100 }; |
|
101 |
2376
|
102 enum binary_op |
|
103 { |
3525
|
104 op_add, |
|
105 op_sub, |
|
106 op_mul, |
|
107 op_div, |
|
108 op_pow, |
|
109 op_ldiv, |
|
110 op_lshift, |
|
111 op_rshift, |
|
112 op_lt, |
|
113 op_le, |
|
114 op_eq, |
|
115 op_ge, |
|
116 op_gt, |
|
117 op_ne, |
|
118 op_el_mul, |
|
119 op_el_div, |
|
120 op_el_pow, |
|
121 op_el_ldiv, |
|
122 op_el_and, |
|
123 op_el_or, |
|
124 op_struct_ref, |
2376
|
125 num_binary_ops, |
|
126 unknown_binary_op |
|
127 }; |
|
128 |
2880
|
129 enum assign_op |
|
130 { |
3525
|
131 op_asn_eq, |
|
132 op_add_eq, |
|
133 op_sub_eq, |
|
134 op_mul_eq, |
|
135 op_div_eq, |
|
136 op_ldiv_eq, |
4018
|
137 op_pow_eq, |
3525
|
138 op_lshift_eq, |
|
139 op_rshift_eq, |
|
140 op_el_mul_eq, |
|
141 op_el_div_eq, |
|
142 op_el_ldiv_eq, |
4018
|
143 op_el_pow_eq, |
3525
|
144 op_el_and_eq, |
|
145 op_el_or_eq, |
2880
|
146 num_assign_ops, |
|
147 unknown_assign_op |
|
148 }; |
|
149 |
3523
|
150 static std::string unary_op_as_string (unary_op); |
3203
|
151 |
3523
|
152 static std::string binary_op_as_string (binary_op); |
2376
|
153 |
3523
|
154 static std::string assign_op_as_string (assign_op); |
2880
|
155 |
3933
|
156 static octave_value empty_conv (const std::string& type, |
|
157 const octave_value& rhs = octave_value ()); |
|
158 |
2376
|
159 enum magic_colon { magic_colon_t }; |
|
160 enum all_va_args { all_va_args_t }; |
|
161 |
|
162 octave_value (void); |
4254
|
163 octave_value (short int i); |
|
164 octave_value (unsigned short int i); |
4233
|
165 octave_value (int i); |
4254
|
166 octave_value (unsigned int i); |
|
167 octave_value (long int i); |
|
168 octave_value (unsigned long int i); |
4353
|
169 |
|
170 // XXX FIXME XXX -- these are kluges. They turn into doubles |
|
171 // internally, which will break for very large values. We just use |
|
172 // them to store things like 64-bit ino_t, etc, and hope that those |
|
173 // values are never actually larger than can be represented exactly |
|
174 // in a double. |
|
175 |
|
176 #if defined (HAVE_LONG_LONG_INT) |
|
177 octave_value (long long int i); |
|
178 #endif |
4356
|
179 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
180 octave_value (unsigned long long int i); |
|
181 #endif |
|
182 |
4254
|
183 octave_value (octave_time t); |
2376
|
184 octave_value (double d); |
3351
|
185 octave_value (const Cell& m); |
2376
|
186 octave_value (const Matrix& m); |
4507
|
187 octave_value (const NDArray& m); |
2376
|
188 octave_value (const DiagMatrix& d); |
3418
|
189 octave_value (const RowVector& v); |
|
190 octave_value (const ColumnVector& v); |
2376
|
191 octave_value (const Complex& C); |
|
192 octave_value (const ComplexMatrix& m); |
4478
|
193 octave_value (const ArrayN<Complex>& m); |
2376
|
194 octave_value (const ComplexDiagMatrix& d); |
3418
|
195 octave_value (const ComplexRowVector& v); |
|
196 octave_value (const ComplexColumnVector& v); |
2825
|
197 octave_value (bool b); |
|
198 octave_value (const boolMatrix& bm); |
3189
|
199 octave_value (char c); |
2376
|
200 octave_value (const char *s); |
3523
|
201 octave_value (const std::string& s); |
2376
|
202 octave_value (const string_vector& s); |
|
203 octave_value (const charMatrix& chm, bool is_string = false); |
|
204 octave_value (double base, double limit, double inc); |
|
205 octave_value (const Range& r); |
|
206 octave_value (const Octave_map& m); |
3340
|
207 octave_value (const octave_stream& s, int n); |
2974
|
208 octave_value (octave_function *f); |
4342
|
209 octave_value (const octave_fcn_handle& fh); |
3977
|
210 octave_value (const octave_value_list& m, bool is_cs_list = false); |
2376
|
211 octave_value (octave_value::magic_colon); |
|
212 octave_value (octave_value::all_va_args); |
|
213 |
3933
|
214 octave_value (octave_value *new_rep, int count = 1); |
2376
|
215 |
|
216 // Copy constructor. |
|
217 |
|
218 octave_value (const octave_value& a) |
|
219 { |
|
220 rep = a.rep; |
|
221 rep->count++; |
|
222 } |
|
223 |
3933
|
224 // This should only be called for derived types. |
|
225 |
|
226 virtual octave_value *clone (void) const; |
|
227 |
|
228 virtual octave_value *empty_clone (void) const |
|
229 { return rep->empty_clone (); } |
|
230 |
2376
|
231 // Delete the representation of this constant if the count drops to |
|
232 // zero. |
|
233 |
|
234 virtual ~octave_value (void); |
|
235 |
|
236 void make_unique (void) |
|
237 { |
|
238 if (rep->count > 1) |
|
239 { |
|
240 --rep->count; |
|
241 rep = rep->clone (); |
|
242 rep->count = 1; |
|
243 } |
|
244 } |
|
245 |
|
246 // Simple assignment. |
|
247 |
|
248 octave_value& operator = (const octave_value& a) |
|
249 { |
|
250 if (rep != a.rep) |
|
251 { |
|
252 if (--rep->count == 0) |
|
253 delete rep; |
|
254 |
|
255 rep = a.rep; |
|
256 rep->count++; |
|
257 } |
|
258 |
|
259 return *this; |
|
260 } |
|
261 |
3933
|
262 int get_count (void) const { return rep->count; } |
3239
|
263 |
2409
|
264 virtual type_conv_fcn numeric_conversion_function (void) const |
2376
|
265 { return rep->numeric_conversion_function (); } |
|
266 |
2409
|
267 void maybe_mutate (void); |
|
268 |
2410
|
269 virtual octave_value *try_narrowing_conversion (void) |
|
270 { return rep->try_narrowing_conversion (); } |
2409
|
271 |
4271
|
272 octave_value single_subsref (const std::string& type, |
|
273 const octave_value_list& idx); |
|
274 |
4247
|
275 virtual octave_value subsref (const std::string& type, |
4219
|
276 const std::list<octave_value_list>& idx) |
3933
|
277 { return rep->subsref (type, idx); } |
|
278 |
4247
|
279 virtual octave_value_list subsref (const std::string& type, |
4219
|
280 const std::list<octave_value_list>& idx, |
3933
|
281 int nargout); |
|
282 |
4247
|
283 octave_value next_subsref (const std::string& type, const |
4219
|
284 std::list<octave_value_list>& idx, |
4233
|
285 size_t skip = 1); |
3933
|
286 |
|
287 virtual octave_value do_index_op (const octave_value_list& idx, |
|
288 int resize_ok) |
|
289 { return rep->do_index_op (idx, resize_ok); } |
|
290 |
|
291 octave_value do_index_op (const octave_value_list& idx) |
|
292 { return do_index_op (idx, 0); } |
2376
|
293 |
2974
|
294 virtual octave_value_list |
3544
|
295 do_multi_index_op (int nargout, const octave_value_list& idx); |
2974
|
296 |
4247
|
297 virtual octave_value subsasgn (const std::string& type, |
4219
|
298 const std::list<octave_value_list>& idx, |
3933
|
299 const octave_value& rhs); |
2376
|
300 |
4247
|
301 octave_value assign (assign_op op, const std::string& type, |
4219
|
302 const std::list<octave_value_list>& idx, |
3933
|
303 const octave_value& rhs); |
2948
|
304 |
3933
|
305 const octave_value& assign (assign_op, const octave_value& rhs); |
2948
|
306 |
2376
|
307 virtual idx_vector index_vector (void) const |
|
308 { return rep->index_vector (); } |
|
309 |
|
310 // Size. |
|
311 |
|
312 virtual int rows (void) const |
|
313 { return rep->rows (); } |
|
314 |
|
315 virtual int columns (void) const |
|
316 { return rep->columns (); } |
|
317 |
3195
|
318 virtual int length (void) const |
|
319 { return rep->length (); } |
|
320 |
2376
|
321 // Does this constant have a type? Both of these are provided since |
|
322 // it is sometimes more natural to write is_undefined() instead of |
|
323 // ! is_defined(). |
|
324 |
|
325 virtual bool is_defined (void) const |
|
326 { return rep->is_defined (); } |
|
327 |
|
328 bool is_undefined (void) const |
|
329 { return ! is_defined (); } |
|
330 |
3351
|
331 virtual bool is_cell (void) const |
|
332 { return rep->is_cell (); } |
|
333 |
2376
|
334 virtual bool is_real_scalar (void) const |
|
335 { return rep->is_real_scalar (); } |
|
336 |
|
337 virtual bool is_real_matrix (void) const |
|
338 { return rep->is_real_matrix (); } |
|
339 |
4505
|
340 virtual bool is_real_nd_array (void) const |
|
341 { return rep->is_real_nd_array (); } |
|
342 |
2376
|
343 virtual bool is_complex_scalar (void) const |
|
344 { return rep->is_complex_scalar (); } |
|
345 |
|
346 virtual bool is_complex_matrix (void) const |
|
347 { return rep->is_complex_matrix (); } |
|
348 |
|
349 virtual bool is_char_matrix (void) const |
|
350 { return rep->is_char_matrix (); } |
|
351 |
|
352 virtual bool is_string (void) const |
|
353 { return rep->is_string (); } |
|
354 |
|
355 virtual bool is_range (void) const |
|
356 { return rep->is_range (); } |
|
357 |
|
358 virtual bool is_map (void) const |
|
359 { return rep->is_map (); } |
|
360 |
3340
|
361 virtual bool is_stream (void) const |
|
362 { return rep->is_stream (); } |
|
363 |
3977
|
364 virtual bool is_cs_list (void) const |
|
365 { return rep->is_cs_list (); } |
|
366 |
2880
|
367 virtual bool is_list (void) const |
|
368 { return rep->is_list (); } |
|
369 |
2376
|
370 virtual bool is_magic_colon (void) const |
|
371 { return rep->is_magic_colon (); } |
|
372 |
|
373 virtual bool is_all_va_args (void) const |
|
374 { return rep->is_all_va_args (); } |
|
375 |
|
376 // Are any or all of the elements in this constant nonzero? |
|
377 |
4015
|
378 virtual octave_value all (int dim = 0) const |
|
379 { return rep->all (dim); } |
2376
|
380 |
4015
|
381 virtual octave_value any (int dim = 0) const |
|
382 { return rep->any (dim); } |
2376
|
383 |
|
384 // Other type stuff. |
|
385 |
3209
|
386 virtual bool is_bool_type (void) const |
|
387 { return rep->is_bool_type (); } |
|
388 |
2376
|
389 virtual bool is_real_type (void) const |
|
390 { return rep->is_real_type (); } |
|
391 |
|
392 virtual bool is_complex_type (void) const |
|
393 { return rep->is_complex_type (); } |
|
394 |
|
395 virtual bool is_scalar_type (void) const |
|
396 { return rep->is_scalar_type (); } |
|
397 |
|
398 virtual bool is_matrix_type (void) const |
|
399 { return rep->is_matrix_type (); } |
|
400 |
|
401 virtual bool is_numeric_type (void) const |
|
402 { return rep->is_numeric_type (); } |
|
403 |
|
404 virtual bool valid_as_scalar_index (void) const |
|
405 { return rep->valid_as_scalar_index (); } |
|
406 |
|
407 virtual bool valid_as_zero_index (void) const |
|
408 { return rep->valid_as_zero_index (); } |
|
409 |
|
410 // Does this constant correspond to a truth value? |
|
411 |
|
412 virtual bool is_true (void) const |
|
413 { return rep->is_true (); } |
|
414 |
|
415 // Is at least one of the dimensions of this constant zero? |
|
416 |
|
417 virtual bool is_empty (void) const |
|
418 { return rep->is_empty (); } |
|
419 |
|
420 // Are the dimensions of this constant zero by zero? |
|
421 |
|
422 virtual bool is_zero_by_zero (void) const |
|
423 { return rep->is_zero_by_zero (); } |
|
424 |
2974
|
425 virtual bool is_constant (void) const |
|
426 { return rep->is_constant (); } |
|
427 |
|
428 virtual bool is_function (void) const |
|
429 { return rep->is_function (); } |
2891
|
430 |
3325
|
431 virtual bool is_builtin_function (void) const |
|
432 { return rep->is_builtin_function (); } |
|
433 |
|
434 virtual bool is_dld_function (void) const |
|
435 { return rep->is_dld_function (); } |
|
436 |
2376
|
437 // Values. |
|
438 |
2891
|
439 octave_value eval (void) { return *this; } |
|
440 |
4254
|
441 virtual short int |
|
442 short_value (bool req_int = false, bool frc_str_conv = false) const |
|
443 { return rep->short_value (req_int, frc_str_conv); } |
|
444 |
|
445 virtual unsigned short int |
|
446 ushort_value (bool req_int = false, bool frc_str_conv = false) const |
|
447 { return rep->ushort_value (req_int, frc_str_conv); } |
|
448 |
3202
|
449 virtual int int_value (bool req_int = false, bool frc_str_conv = false) const |
|
450 { return rep->int_value (req_int, frc_str_conv); } |
|
451 |
4254
|
452 virtual unsigned int |
|
453 uint_value (bool req_int = false, bool frc_str_conv = false) const |
|
454 { return rep->uint_value (req_int, frc_str_conv); } |
|
455 |
3202
|
456 virtual int nint_value (bool frc_str_conv = false) const |
|
457 { return rep->nint_value (frc_str_conv); } |
|
458 |
4254
|
459 virtual long int |
|
460 long_value (bool req_int = false, bool frc_str_conv = false) const |
|
461 { return rep->long_value (req_int, frc_str_conv); } |
|
462 |
|
463 virtual unsigned long int |
|
464 ulong_value (bool req_int = false, bool frc_str_conv = false) const |
|
465 { return rep->ulong_value (req_int, frc_str_conv); } |
|
466 |
2376
|
467 virtual double double_value (bool frc_str_conv = false) const |
|
468 { return rep->double_value (frc_str_conv); } |
|
469 |
2916
|
470 virtual double scalar_value (bool frc_str_conv = false) const |
|
471 { return rep->scalar_value (frc_str_conv); } |
|
472 |
3351
|
473 virtual Cell cell_value (void) const; |
|
474 |
2376
|
475 virtual Matrix matrix_value (bool frc_str_conv = false) const |
|
476 { return rep->matrix_value (frc_str_conv); } |
|
477 |
4507
|
478 virtual NDArray double_nd_array_value (bool frc_str_conv = false) const |
4505
|
479 { return rep->double_nd_array_value (frc_str_conv); } |
|
480 |
2376
|
481 virtual Complex complex_value (bool frc_str_conv = false) const |
|
482 { return rep->complex_value (frc_str_conv); } |
|
483 |
|
484 virtual ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const |
|
485 { return rep->complex_matrix_value (frc_str_conv); } |
|
486 |
|
487 virtual charMatrix char_matrix_value (bool frc_str_conv = false) const |
|
488 { return rep->char_matrix_value (frc_str_conv); } |
|
489 |
4457
|
490 virtual string_vector all_strings (bool pad = false, |
|
491 bool force = false) const |
4358
|
492 { return rep->all_strings (pad); } |
2376
|
493 |
4457
|
494 virtual std::string string_value (bool force = false) const |
2376
|
495 { return rep->string_value (); } |
|
496 |
|
497 virtual Range range_value (void) const |
|
498 { return rep->range_value (); } |
|
499 |
|
500 virtual Octave_map map_value (void) const; |
|
501 |
3933
|
502 virtual string_vector map_keys (void) const |
|
503 { return rep->map_keys (); } |
|
504 |
3340
|
505 virtual octave_stream stream_value (void) const; |
2903
|
506 |
|
507 virtual int stream_number (void) const; |
|
508 |
2974
|
509 virtual octave_function *function_value (bool silent = false); |
|
510 |
4346
|
511 virtual octave_fcn_handle *fcn_handle_value (bool silent = false); |
4343
|
512 |
2880
|
513 virtual octave_value_list list_value (void) const; |
|
514 |
2825
|
515 virtual bool bool_value (void) const |
|
516 { return rep->bool_value (); } |
|
517 |
|
518 virtual boolMatrix bool_matrix_value (void) const |
|
519 { return rep->bool_matrix_value (); } |
|
520 |
3419
|
521 ColumnVector column_vector_value (bool frc_str_conv = false, |
2376
|
522 bool frc_vec_conv = false) const; |
|
523 |
|
524 ComplexColumnVector |
3419
|
525 complex_column_vector_value (bool frc_str_conv = false, |
2376
|
526 bool frc_vec_conv = false) const; |
|
527 |
3419
|
528 RowVector row_vector_value (bool frc_str_conv = false, |
|
529 bool frc_vec_conv = false) const; |
|
530 |
|
531 ComplexRowVector |
|
532 complex_row_vector_value (bool frc_str_conv = false, |
|
533 bool frc_vec_conv = false) const; |
|
534 |
4044
|
535 Array<int> int_vector_value (bool req_int = false, |
|
536 bool frc_str_conv = false, |
|
537 bool frc_vec_conv = false) const; |
|
538 |
3419
|
539 Array<double> vector_value (bool frc_str_conv = false, |
|
540 bool frc_vec_conv = false) const; |
|
541 |
|
542 Array<Complex> complex_vector_value (bool frc_str_conv = false, |
|
543 bool frc_vec_conv = false) const; |
|
544 |
2376
|
545 // Conversions. These should probably be private. If a user of this |
|
546 // class wants a certain kind of constant, he should simply ask for |
|
547 // it, and we should convert it if possible. |
|
548 |
4457
|
549 octave_value convert_to_str (bool pad = false, bool force = false) const; |
4452
|
550 |
4457
|
551 virtual octave_value convert_to_str_internal (bool pad, bool force) const |
|
552 { return rep->convert_to_str_internal (pad, force); } |
2376
|
553 |
|
554 virtual void convert_to_row_or_column_vector (void) |
|
555 { rep->convert_to_row_or_column_vector (); } |
|
556 |
3523
|
557 virtual void print (std::ostream& os, bool pr_as_read_syntax = false) const |
2466
|
558 { rep->print (os, pr_as_read_syntax); } |
2376
|
559 |
4457
|
560 virtual void print_raw (std::ostream& os, |
|
561 bool pr_as_read_syntax = false) const |
2903
|
562 { rep->print_raw (os, pr_as_read_syntax); } |
|
563 |
3523
|
564 virtual bool print_name_tag (std::ostream& os, const std::string& name) const |
2903
|
565 { return rep->print_name_tag (os, name); } |
2376
|
566 |
3523
|
567 void print_with_name (std::ostream& os, const std::string& name, |
2903
|
568 bool print_padding = true) const; |
2376
|
569 |
|
570 virtual int type_id (void) const { return rep->type_id (); } |
|
571 |
3523
|
572 virtual std::string type_name (void) const { return rep->type_name (); } |
2376
|
573 |
3203
|
574 // Unary and binary operations. |
|
575 |
3933
|
576 friend octave_value do_unary_op (unary_op op, |
|
577 const octave_value& a); |
3203
|
578 |
3933
|
579 const octave_value& do_non_const_unary_op (unary_op op); |
|
580 |
|
581 void do_non_const_unary_op (unary_op op, const octave_value_list& idx); |
2376
|
582 |
4247
|
583 octave_value do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
584 const std::list<octave_value_list>& idx); |
3205
|
585 |
3933
|
586 friend octave_value do_binary_op (binary_op op, |
|
587 const octave_value& a, |
|
588 const octave_value& b); |
2376
|
589 |
3301
|
590 const octave_value& get_rep (void) const { return *rep; } |
|
591 |
3933
|
592 virtual void print_info (std::ostream& os, |
|
593 const std::string& prefix = std::string ()) const; |
|
594 |
2376
|
595 protected: |
|
596 |
|
597 octave_value (const octave_xvalue&) : rep (0) { } |
|
598 |
3933
|
599 // This should only be called for derived types. |
|
600 |
4247
|
601 octave_value numeric_assign (const std::string& type, |
4219
|
602 const std::list<octave_value_list>& idx, |
3933
|
603 const octave_value& rhs); |
|
604 |
2903
|
605 void reset_indent_level (void) const |
|
606 { curr_print_indent_level = 0; } |
|
607 |
|
608 void increment_indent_level (void) const |
|
609 { curr_print_indent_level += 2; } |
|
610 |
|
611 void decrement_indent_level (void) const |
|
612 { curr_print_indent_level -= 2; } |
|
613 |
|
614 int current_print_indent_level (void) const |
|
615 { return curr_print_indent_level; } |
|
616 |
3523
|
617 void newline (std::ostream& os) const; |
2903
|
618 |
3523
|
619 void indent (std::ostream& os) const; |
2903
|
620 |
|
621 void reset (void) const; |
|
622 |
2376
|
623 union |
|
624 { |
|
625 octave_value *rep; // The real representation. |
|
626 int count; // A reference count. |
|
627 }; |
2413
|
628 |
3933
|
629 private: |
2903
|
630 |
|
631 static int curr_print_indent_level; |
|
632 static bool beginning_of_line; |
3204
|
633 |
3205
|
634 assign_op unary_op_to_assign_op (unary_op op); |
|
635 |
3204
|
636 binary_op op_eq_to_binary_op (assign_op op); |
|
637 |
3219
|
638 DECLARE_OCTAVE_ALLOCATOR |
2376
|
639 }; |
|
640 |
3203
|
641 #define OV_UNOP_FN(name) \ |
|
642 inline octave_value \ |
|
643 name (const octave_value& a) \ |
|
644 { \ |
|
645 return do_unary_op (octave_value::name, a); \ |
|
646 } |
|
647 |
|
648 #define OV_UNOP_OP(name, op) \ |
|
649 inline octave_value \ |
|
650 operator op (const octave_value& a) \ |
|
651 { \ |
|
652 return name (a); \ |
|
653 } |
|
654 |
|
655 #define OV_UNOP_FN_OP(name, op) \ |
|
656 OV_UNOP_FN (name) \ |
|
657 OV_UNOP_OP (name, op) |
|
658 |
3525
|
659 OV_UNOP_FN_OP (op_not, !) |
|
660 OV_UNOP_FN_OP (op_uminus, -) |
3203
|
661 |
3525
|
662 OV_UNOP_FN (op_transpose) |
|
663 OV_UNOP_FN (op_hermitian) |
3203
|
664 |
|
665 // No simple way to define these for prefix and suffix ops? |
|
666 // |
|
667 // incr |
|
668 // decr |
|
669 |
|
670 #define OV_BINOP_FN(name) \ |
|
671 inline octave_value \ |
|
672 name (const octave_value& a1, const octave_value& a2) \ |
|
673 { \ |
|
674 return do_binary_op (octave_value::name, a1, a2); \ |
|
675 } |
|
676 |
|
677 #define OV_BINOP_OP(name, op) \ |
|
678 inline octave_value \ |
|
679 operator op (const octave_value& a1, const octave_value& a2) \ |
|
680 { \ |
|
681 return name (a1, a2); \ |
|
682 } |
|
683 |
|
684 #define OV_BINOP_FN_OP(name, op) \ |
|
685 OV_BINOP_FN (name) \ |
|
686 OV_BINOP_OP (name, op) |
|
687 |
3525
|
688 OV_BINOP_FN_OP (op_add, +) |
|
689 OV_BINOP_FN_OP (op_sub, -) |
|
690 OV_BINOP_FN_OP (op_mul, *) |
|
691 OV_BINOP_FN_OP (op_div, /) |
3203
|
692 |
3525
|
693 OV_BINOP_FN (op_pow) |
|
694 OV_BINOP_FN (op_ldiv) |
|
695 OV_BINOP_FN (op_lshift) |
|
696 OV_BINOP_FN (op_rshift) |
3203
|
697 |
3525
|
698 OV_BINOP_FN_OP (op_lt, <) |
|
699 OV_BINOP_FN_OP (op_le, <=) |
|
700 OV_BINOP_FN_OP (op_eq, ==) |
|
701 OV_BINOP_FN_OP (op_ge, >=) |
|
702 OV_BINOP_FN_OP (op_gt, >) |
|
703 OV_BINOP_FN_OP (op_ne, !=) |
3203
|
704 |
3525
|
705 OV_BINOP_FN (op_el_mul) |
|
706 OV_BINOP_FN (op_el_div) |
|
707 OV_BINOP_FN (op_el_pow) |
|
708 OV_BINOP_FN (op_el_ldiv) |
|
709 OV_BINOP_FN (op_el_and) |
|
710 OV_BINOP_FN (op_el_or) |
3203
|
711 |
3525
|
712 OV_BINOP_FN (op_struct_ref) |
3203
|
713 |
3219
|
714 // T_ID is the type id of struct objects, set by register_type(). |
|
715 // T_NAME is the type name of struct objects. |
|
716 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \ |
|
717 public: \ |
|
718 int type_id (void) const { return t_id; } \ |
3523
|
719 std::string type_name (void) const { return t_name; } \ |
4252
|
720 static int static_type_id (void) { return t_id; } \ |
3219
|
721 static void register_type (void) \ |
|
722 { t_id = octave_value_typeinfo::register_type (t_name); } \ |
|
723 \ |
|
724 private: \ |
4252
|
725 static int t_id; \ |
3523
|
726 static const std::string t_name; |
3219
|
727 |
|
728 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n) \ |
4252
|
729 int t::t_id (-1); \ |
3523
|
730 const std::string t::t_name (n) |
3219
|
731 |
4455
|
732 // If TRUE, print a warning for assignments like |
2376
|
733 // |
|
734 // octave> A(1) = 3; A(2) = 5 |
|
735 // |
|
736 // for A already defined and a matrix type. |
4455
|
737 extern bool Vwarn_fortran_indexing; |
2376
|
738 |
4452
|
739 // Should we print a warning when converting `[97, 98, 99, "123"]' |
|
740 // to a character string? |
|
741 extern bool Vwarn_num_to_str; |
4257
|
742 |
4452
|
743 // If TRUE, warn for operations like |
2376
|
744 // |
|
745 // octave> 'abc' + 0 |
|
746 // 97 98 99 |
|
747 // |
4452
|
748 extern int Vwarn_str_to_num; |
2376
|
749 |
4451
|
750 // Should we warn about conversions from complex to real? |
|
751 extern int Vwarn_imag_to_real; |
2376
|
752 |
|
753 // If TRUE, print the name along with the value. |
|
754 extern bool Vprint_answer_id_name; |
|
755 |
|
756 // How many levels of structure elements should we print? |
|
757 extern int Vstruct_levels_to_print; |
|
758 |
|
759 // Allow divide by zero errors to be suppressed. |
|
760 extern bool Vwarn_divide_by_zero; |
|
761 |
4461
|
762 // If TRUE, print a warning when a matrix is resized by an indexed |
|
763 // assignment with indices outside the current bounds. |
|
764 extern bool Vwarn_resize_on_range_error; |
3195
|
765 |
2376
|
766 // Indentation level for structures. |
|
767 extern int struct_indent; |
|
768 |
|
769 extern void increment_struct_indent (void); |
|
770 extern void decrement_struct_indent (void); |
|
771 |
2880
|
772 // Indentation level for lists. |
|
773 extern int list_indent; |
|
774 |
|
775 extern void increment_list_indent (void); |
|
776 extern void decrement_list_indent (void); |
|
777 |
2376
|
778 extern void install_types (void); |
|
779 |
|
780 #endif |
|
781 |
|
782 /* |
|
783 ;; Local Variables: *** |
|
784 ;; mode: C++ *** |
|
785 ;; End: *** |
|
786 */ |