3278
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
3278
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
3278
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_base_scalar_h) |
|
24 #define octave_base_scalar_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
3278
|
29 #include <string> |
|
30 |
|
31 #include "lo-mappers.h" |
|
32 #include "lo-utils.h" |
|
33 #include "oct-alloc.h" |
|
34 #include "str-vec.h" |
6376
|
35 #include "MatrixType.h" |
3278
|
36 |
|
37 #include "ov-base.h" |
|
38 #include "ov-typeinfo.h" |
|
39 |
|
40 // Real scalar values. |
|
41 |
|
42 template <class ST> |
|
43 class |
|
44 octave_base_scalar : public octave_base_value |
|
45 { |
|
46 public: |
|
47 |
|
48 octave_base_scalar (void) |
6376
|
49 : octave_base_value (), typ (MatrixType ()) { } |
3278
|
50 |
6376
|
51 octave_base_scalar (const ST& s, const MatrixType& t = MatrixType ()) |
|
52 : octave_base_value (), scalar (s), typ (t) { } |
3278
|
53 |
|
54 octave_base_scalar (const octave_base_scalar& s) |
6376
|
55 : octave_base_value (), scalar (s.scalar), typ (s.typ) { } |
3278
|
56 |
|
57 ~octave_base_scalar (void) { } |
|
58 |
5759
|
59 octave_base_value *clone (void) const { return new octave_base_scalar (*this); } |
|
60 octave_base_value *empty_clone (void) const { return new octave_base_scalar (); } |
4981
|
61 |
4759
|
62 octave_value squeeze (void) const { return scalar; } |
|
63 |
4247
|
64 octave_value subsref (const std::string& type, |
4219
|
65 const std::list<octave_value_list>& idx); |
3933
|
66 |
4661
|
67 octave_value_list subsref (const std::string&, |
|
68 const std::list<octave_value_list>&, int) |
4271
|
69 { |
|
70 panic_impossible (); |
|
71 return octave_value_list (); |
|
72 } |
|
73 |
4247
|
74 octave_value subsasgn (const std::string& type, |
4219
|
75 const std::list<octave_value_list>& idx, |
3933
|
76 const octave_value& rhs); |
|
77 |
3278
|
78 bool is_constant (void) const { return true; } |
|
79 |
|
80 bool is_defined (void) const { return true; } |
|
81 |
4563
|
82 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
|
83 |
5602
|
84 octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; } |
|
85 |
4901
|
86 octave_value permute (const Array<int>&, bool = false) const |
4875
|
87 { return scalar; } |
|
88 |
4791
|
89 size_t byte_size (void) const { return sizeof (ST); } |
|
90 |
4901
|
91 octave_value all (int = 0) const { return (scalar != ST ()); } |
3278
|
92 |
4901
|
93 octave_value any (int = 0) const { return (scalar != ST ()); } |
3278
|
94 |
6376
|
95 MatrixType matrix_type (void) const { return typ; } |
|
96 MatrixType matrix_type (const MatrixType& _typ) const |
|
97 { MatrixType ret = typ; typ = _typ; return ret; } |
|
98 |
3278
|
99 bool is_scalar_type (void) const { return true; } |
|
100 |
|
101 bool is_numeric_type (void) const { return true; } |
|
102 |
4901
|
103 bool is_true (void) const { return (scalar != ST ()); } |
3278
|
104 |
3523
|
105 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278
|
106 |
3523
|
107 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278
|
108 |
3523
|
109 bool print_name_tag (std::ostream& os, const std::string& name) const; |
3278
|
110 |
5900
|
111 // Unsafe. This function exists to support the MEX interface. |
|
112 // You should not use it anywhere else. |
|
113 void *mex_get_data (void) const { return const_cast<ST *> (&scalar); } |
|
114 |
3278
|
115 protected: |
|
116 |
|
117 // The value of this scalar. |
|
118 ST scalar; |
6376
|
119 |
|
120 mutable MatrixType typ; |
3278
|
121 }; |
|
122 |
|
123 #endif |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |