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_scalar_h) |
|
24 #define octave_scalar_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> |
|
34 |
2889
|
35 #include "lo-mappers.h" |
2376
|
36 #include "lo-utils.h" |
|
37 #include "mx-base.h" |
2477
|
38 #include "oct-alloc.h" |
2376
|
39 #include "str-vec.h" |
|
40 |
|
41 #include "ov-base.h" |
3223
|
42 #include "ov-base-scalar.h" |
2376
|
43 #include "ov-typeinfo.h" |
|
44 |
|
45 class Octave_map; |
|
46 class octave_value_list; |
|
47 |
|
48 class tree_walker; |
|
49 |
|
50 // Real scalar values. |
|
51 |
|
52 class |
3223
|
53 octave_scalar : public octave_base_scalar<double> |
2376
|
54 { |
|
55 public: |
|
56 |
|
57 octave_scalar (void) |
3223
|
58 : octave_base_scalar<double> (0.0) { } |
2376
|
59 |
|
60 octave_scalar (double d) |
3223
|
61 : octave_base_scalar<double> (d) { } |
2376
|
62 |
|
63 octave_scalar (const octave_scalar& s) |
3223
|
64 : octave_base_scalar<double> (s) { } |
2376
|
65 |
|
66 ~octave_scalar (void) { } |
|
67 |
3933
|
68 octave_value *clone (void) const { return new octave_scalar (*this); } |
|
69 octave_value *empty_clone (void) const { return new octave_scalar (); } |
2376
|
70 |
3933
|
71 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2376
|
72 |
|
73 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
74 |
|
75 bool is_real_scalar (void) const { return true; } |
|
76 |
|
77 bool is_real_type (void) const { return true; } |
|
78 |
|
79 bool valid_as_scalar_index (void) const |
|
80 { return (! xisnan (scalar) && NINT (scalar) == 1); } |
|
81 |
|
82 bool valid_as_zero_index (void) const |
|
83 { return (! xisnan (scalar) && NINT (scalar) == 0); } |
|
84 |
|
85 double double_value (bool = false) const { return scalar; } |
|
86 |
2916
|
87 double scalar_value (bool = false) const { return scalar; } |
|
88 |
3145
|
89 Matrix matrix_value (bool = false) const |
|
90 { return Matrix (1, 1, scalar); } |
2376
|
91 |
4569
|
92 NDArray array_value (bool = false) const |
|
93 { return NDArray (dim_vector (1, 1), double_value ()); } |
4505
|
94 |
2376
|
95 Complex complex_value (bool = false) const { return scalar; } |
|
96 |
|
97 ComplexMatrix complex_matrix_value (bool = false) const |
|
98 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
99 |
4569
|
100 ComplexNDArray complex_array_value (bool = false) const |
|
101 { return ComplexNDArray (dim_vector (1, 1), double_value ()); } |
|
102 |
4457
|
103 octave_value convert_to_str_internal (bool pad, bool force) const; |
3223
|
104 |
2376
|
105 void increment (void) { ++scalar; } |
|
106 |
|
107 void decrement (void) { --scalar; } |
|
108 |
|
109 private: |
|
110 |
3219
|
111 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2477
|
112 |
3219
|
113 DECLARE_OCTAVE_ALLOCATOR |
2376
|
114 }; |
|
115 |
|
116 #endif |
|
117 |
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; End: *** |
|
122 */ |