2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 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 (octave_scalar_h) |
|
24 #define octave_scalar_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
|
32 #include <string> |
|
33 |
|
34 class ostream; |
|
35 |
|
36 #include "lo-utils.h" |
|
37 #include "mx-base.h" |
|
38 #include "str-vec.h" |
|
39 |
|
40 #include "mappers.h" |
|
41 #include "ov-base.h" |
|
42 #include "ov-typeinfo.h" |
|
43 |
|
44 class Octave_map; |
|
45 class octave_value_list; |
|
46 |
|
47 class tree_walker; |
|
48 |
|
49 // Real scalar values. |
|
50 |
|
51 class |
|
52 octave_scalar : public octave_base_value |
|
53 { |
|
54 public: |
|
55 |
|
56 octave_scalar (void) |
|
57 : octave_base_value (), scalar (0.0) { } |
|
58 |
|
59 octave_scalar (double d) |
|
60 : octave_base_value (), scalar (d) { } |
|
61 |
|
62 octave_scalar (const octave_scalar& s) |
|
63 : octave_base_value (), scalar (s.scalar) { } |
|
64 |
|
65 ~octave_scalar (void) { } |
|
66 |
|
67 octave_value *clone (void) { return new octave_scalar (*this); } |
|
68 |
|
69 #if 0 |
|
70 void *operator new (size_t size); |
|
71 void operator delete (void *p, size_t size); |
|
72 #endif |
|
73 |
|
74 octave_value index (const octave_value_list& idx) const; |
|
75 |
|
76 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
77 |
|
78 int rows (void) const { return 1; } |
|
79 int columns (void) const { return 1; } |
|
80 |
|
81 bool is_defined (void) const { return true; } |
|
82 bool is_real_scalar (void) const { return true; } |
|
83 |
|
84 octave_value all (void) const { return (scalar != 0.0); } |
|
85 octave_value any (void) const { return (scalar != 0.0); } |
|
86 |
|
87 bool is_real_type (void) const { return true; } |
|
88 bool is_scalar_type (void) const { return true; } |
|
89 bool is_numeric_type (void) const { return true; } |
|
90 |
|
91 bool valid_as_scalar_index (void) const |
|
92 { return (! xisnan (scalar) && NINT (scalar) == 1); } |
|
93 |
|
94 bool valid_as_zero_index (void) const |
|
95 { return (! xisnan (scalar) && NINT (scalar) == 0); } |
|
96 |
|
97 bool is_true (void) const { return (scalar != 0.0); } |
|
98 |
|
99 double double_value (bool = false) const { return scalar; } |
|
100 |
|
101 Matrix matrix_value (bool = false) const { return Matrix (1, 1, scalar); } |
|
102 |
|
103 Complex complex_value (bool = false) const { return scalar; } |
|
104 |
|
105 ComplexMatrix complex_matrix_value (bool = false) const |
|
106 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
107 |
|
108 octave_value not (void) const { return octave_value (! scalar); } |
|
109 |
|
110 octave_value uminus (void) const { return octave_value (- scalar); } |
|
111 |
|
112 octave_value transpose (void) const { return octave_value (scalar); } |
|
113 |
|
114 octave_value hermitian (void) const { return octave_value (scalar); } |
|
115 |
|
116 void increment (void) { ++scalar; } |
|
117 |
|
118 void decrement (void) { --scalar; } |
|
119 |
|
120 octave_value convert_to_str (void) const; |
|
121 |
|
122 void print (ostream& os); |
|
123 |
|
124 int type_id (void) const { return t_id; } |
|
125 |
|
126 string type_name (void) const { return t_name; } |
|
127 |
|
128 static int static_type_id (void) { return t_id; } |
|
129 |
|
130 static void register_type (void) |
|
131 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
132 |
|
133 private: |
|
134 |
|
135 double scalar; |
|
136 |
|
137 static int t_id; |
|
138 |
|
139 static const string t_name; |
|
140 }; |
|
141 |
|
142 #endif |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |