Mercurial > octave-nkf
annotate src/ov-base-scalar.h @ 7961:a5d1e27ee1f4 ss-3-1-51
3.1.51 snapshot
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 22 Jul 2008 11:40:48 -0400 |
parents | 443a8f5a50fd |
children | ec969f3b8955 |
rev | line source |
---|---|
3278 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
3278 | 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. | |
3278 | 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/>. | |
3278 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_base_scalar_h) | |
25 #define octave_base_scalar_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
3503 | 29 #include <iostream> |
3278 | 30 #include <string> |
31 | |
32 #include "lo-mappers.h" | |
33 #include "lo-utils.h" | |
34 #include "oct-alloc.h" | |
35 #include "str-vec.h" | |
6376 | 36 #include "MatrixType.h" |
3278 | 37 |
38 #include "ov-base.h" | |
39 #include "ov-typeinfo.h" | |
40 | |
41 // Real scalar values. | |
42 | |
43 template <class ST> | |
44 class | |
45 octave_base_scalar : public octave_base_value | |
46 { | |
47 public: | |
48 | |
49 octave_base_scalar (void) | |
6376 | 50 : octave_base_value (), typ (MatrixType ()) { } |
3278 | 51 |
6376 | 52 octave_base_scalar (const ST& s, const MatrixType& t = MatrixType ()) |
53 : octave_base_value (), scalar (s), typ (t) { } | |
3278 | 54 |
55 octave_base_scalar (const octave_base_scalar& s) | |
6376 | 56 : octave_base_value (), scalar (s.scalar), typ (s.typ) { } |
3278 | 57 |
58 ~octave_base_scalar (void) { } | |
59 | |
5759 | 60 octave_base_value *clone (void) const { return new octave_base_scalar (*this); } |
61 octave_base_value *empty_clone (void) const { return new octave_base_scalar (); } | |
4981 | 62 |
4759 | 63 octave_value squeeze (void) const { return scalar; } |
64 | |
4247 | 65 octave_value subsref (const std::string& type, |
4219 | 66 const std::list<octave_value_list>& idx); |
3933 | 67 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
68 octave_value_list subsref (const std::string& type, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
69 const std::list<octave_value_list>& idx, int) |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
70 { return subsref (type, idx); } |
4271 | 71 |
4247 | 72 octave_value subsasgn (const std::string& type, |
4219 | 73 const std::list<octave_value_list>& idx, |
3933 | 74 const octave_value& rhs); |
75 | |
3278 | 76 bool is_constant (void) const { return true; } |
77 | |
78 bool is_defined (void) const { return true; } | |
79 | |
4563 | 80 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
81 | |
5602 | 82 octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; } |
83 | |
4901 | 84 octave_value permute (const Array<int>&, bool = false) const |
4875 | 85 { return scalar; } |
86 | |
4791 | 87 size_t byte_size (void) const { return sizeof (ST); } |
88 | |
4901 | 89 octave_value all (int = 0) const { return (scalar != ST ()); } |
3278 | 90 |
4901 | 91 octave_value any (int = 0) const { return (scalar != ST ()); } |
3278 | 92 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
93 octave_value diag (octave_idx_type k = 0) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
94 { return octave_value (matrix_value (). diag (k)); } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
95 |
7433 | 96 octave_value sort (octave_idx_type, sortmode) const |
97 { return octave_value (scalar); } | |
98 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type, | |
99 sortmode) const | |
100 { | |
101 sidx.resize (dim_vector (1, 1)); | |
102 sidx(0) = 0; | |
103 return octave_value (scalar); | |
104 } | |
105 | |
6376 | 106 MatrixType matrix_type (void) const { return typ; } |
107 MatrixType matrix_type (const MatrixType& _typ) const | |
108 { MatrixType ret = typ; typ = _typ; return ret; } | |
109 | |
3278 | 110 bool is_scalar_type (void) const { return true; } |
111 | |
112 bool is_numeric_type (void) const { return true; } | |
113 | |
4901 | 114 bool is_true (void) const { return (scalar != ST ()); } |
3278 | 115 |
3523 | 116 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278 | 117 |
3523 | 118 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278 | 119 |
3523 | 120 bool print_name_tag (std::ostream& os, const std::string& name) const; |
3278 | 121 |
5900 | 122 // Unsafe. This function exists to support the MEX interface. |
123 // You should not use it anywhere else. | |
124 void *mex_get_data (void) const { return const_cast<ST *> (&scalar); } | |
125 | |
3278 | 126 protected: |
127 | |
128 // The value of this scalar. | |
129 ST scalar; | |
6376 | 130 |
131 mutable MatrixType typ; | |
3278 | 132 }; |
133 | |
134 #endif | |
135 | |
136 /* | |
137 ;;; Local Variables: *** | |
138 ;;; mode: C++ *** | |
139 ;;; End: *** | |
140 */ |