Mercurial > hg > octave-nkf
annotate src/ov-base-scalar.h @ 10824:1e6664326d32
rsf2csf: Change first documentation line to active voice.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 27 Jul 2010 10:46:11 -0700 |
parents | 7fa044155982 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
3278 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
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) | |
9686
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
50 : octave_base_value () { } |
3278 | 51 |
9686
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
52 octave_base_scalar (const ST& s) |
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
53 : octave_base_value (), scalar (s) { } |
3278 | 54 |
55 octave_base_scalar (const octave_base_scalar& s) | |
9686
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
56 : octave_base_value (), scalar (s.scalar) { } |
3278 | 57 |
58 ~octave_base_scalar (void) { } | |
59 | |
4759 | 60 octave_value squeeze (void) const { return scalar; } |
61 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8307
diff
changeset
|
62 octave_value full_value (void) const { return scalar; } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8307
diff
changeset
|
63 |
4247 | 64 octave_value subsref (const std::string& type, |
10313 | 65 const std::list<octave_value_list>& idx); |
3933 | 66 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
67 octave_value_list subsref (const std::string& type, |
10313 | 68 const std::list<octave_value_list>& idx, int) |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
69 { return subsref (type, idx); } |
4271 | 70 |
4247 | 71 octave_value subsasgn (const std::string& type, |
10313 | 72 const std::list<octave_value_list>& idx, |
73 const octave_value& rhs); | |
3933 | 74 |
3278 | 75 bool is_constant (void) const { return true; } |
76 | |
77 bool is_defined (void) const { return true; } | |
78 | |
4563 | 79 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
80 | |
10653
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10545
diff
changeset
|
81 octave_idx_type numel (void) const { return 1; } |
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10545
diff
changeset
|
82 |
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10545
diff
changeset
|
83 int ndims (void) const { return 2; } |
ec5fa46e0e45
override ndims and numel for scalars and matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10545
diff
changeset
|
84 |
5602 | 85 octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; } |
86 | |
10545
ffe28cdc6fe2
fix reshape() and permute() for scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
87 octave_value permute (const Array<int>&, bool = false) const; |
4875 | 88 |
10545
ffe28cdc6fe2
fix reshape() and permute() for scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
89 octave_value reshape (const dim_vector& new_dims) const; |
8307
ec969f3b8955
Add scalar reshape method
David Bateman <dbateman@free.fr>
parents:
7651
diff
changeset
|
90 |
4791 | 91 size_t byte_size (void) const { return sizeof (ST); } |
92 | |
4901 | 93 octave_value all (int = 0) const { return (scalar != ST ()); } |
3278 | 94 |
4901 | 95 octave_value any (int = 0) const { return (scalar != ST ()); } |
3278 | 96 |
10816
7fa044155982
fix diag() with complex scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
10670
diff
changeset
|
97 octave_value diag (octave_idx_type k = 0) const; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
98 |
7433 | 99 octave_value sort (octave_idx_type, sortmode) const |
100 { return octave_value (scalar); } | |
101 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type, | |
10313 | 102 sortmode) const |
7433 | 103 { |
104 sidx.resize (dim_vector (1, 1)); | |
105 sidx(0) = 0; | |
106 return octave_value (scalar); | |
107 } | |
108 | |
8734
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8733
diff
changeset
|
109 sortmode is_sorted (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
110 { return mode ? mode : ASCENDING; } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
111 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
112 Array<octave_idx_type> sort_rows_idx (sortmode) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
113 { return Array<octave_idx_type> (1, 0); } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
114 |
8734
767ed8cc6634
rename internal issorted and issorted_rows functions to is_sorted and is_sorted_rows
John W. Eaton <jwe@octave.org>
parents:
8733
diff
changeset
|
115 sortmode is_sorted_rows (sortmode mode = UNSORTED) const |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
116 { return mode ? mode : ASCENDING; } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
117 |
9686
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
118 MatrixType matrix_type (void) const { return MatrixType::Diagonal; } |
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
119 MatrixType matrix_type (const MatrixType&) const |
5e433877634f
don't store MatrixType with scalars
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
120 { return matrix_type (); } |
6376 | 121 |
3278 | 122 bool is_scalar_type (void) const { return true; } |
123 | |
124 bool is_numeric_type (void) const { return true; } | |
125 | |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8458
diff
changeset
|
126 bool is_true (void) const; |
3278 | 127 |
3523 | 128 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278 | 129 |
3523 | 130 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
3278 | 131 |
3523 | 132 bool print_name_tag (std::ostream& os, const std::string& name) const; |
3278 | 133 |
5900 | 134 // Unsafe. This function exists to support the MEX interface. |
135 // You should not use it anywhere else. | |
136 void *mex_get_data (void) const { return const_cast<ST *> (&scalar); } | |
137 | |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
138 const ST& scalar_ref (void) const { return scalar; } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
139 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
140 ST& scalar_ref (void) { return scalar; } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
141 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
142 bool fast_elem_insert_self (void *where, builtin_type_t btyp) const; |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10653
diff
changeset
|
143 |
3278 | 144 protected: |
145 | |
146 // The value of this scalar. | |
147 ST scalar; | |
148 }; | |
149 | |
150 #endif |