GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-base-scalar.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_ov_base_scalar_h)
24 #define octave_ov_base_scalar_h 1
25 
26 #include <cstdlib>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "lo-mappers.h"
32 #include "lo-utils.h"
33 #include "oct-alloc.h"
34 #include "str-vec.h"
35 #include "MatrixType.h"
36 
37 #include "ov-base.h"
38 #include "ov-typeinfo.h"
39 
40 // Real scalar values.
41 
42 template <class ST>
43 class
45 {
46 public:
47 
49  : octave_base_value (), scalar () { }
50 
51  octave_base_scalar (const ST& s)
52  : octave_base_value (), scalar (s) { }
53 
55  : octave_base_value (), scalar (s.scalar) { }
56 
58 
59  octave_value squeeze (void) const { return scalar; }
60 
61  octave_value full_value (void) const { return scalar; }
62 
63  octave_value subsref (const std::string& type,
64  const std::list<octave_value_list>& idx);
65 
66  octave_value_list subsref (const std::string& type,
67  const std::list<octave_value_list>& idx, int)
68  { return subsref (type, idx); }
69 
70  octave_value subsasgn (const std::string& type,
71  const std::list<octave_value_list>& idx,
72  const octave_value& rhs);
73 
74  octave_value_list do_multi_index_op (int, const octave_value_list& idx)
75  { return do_index_op (idx); }
76 
77  bool is_constant (void) const { return true; }
78 
79  bool is_defined (void) const { return true; }
80 
81  dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
82 
83  octave_idx_type numel (void) const { return 1; }
84 
85  int ndims (void) const { return 2; }
86 
87  octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; }
88 
89  octave_value permute (const Array<int>&, bool = false) const;
90 
91  octave_value reshape (const dim_vector& new_dims) const;
92 
93  size_t byte_size (void) const { return sizeof (ST); }
94 
95  octave_value all (int = 0) const { return (scalar != ST ()); }
96 
97  octave_value any (int = 0) const { return (scalar != ST ()); }
98 
99  octave_value diag (octave_idx_type k = 0) const;
100 
101  octave_value diag (octave_idx_type m, octave_idx_type n) const;
102 
104  { return octave_value (scalar); }
106  sortmode) const
107  {
108  sidx.resize (dim_vector (1, 1));
109  sidx(0) = 0;
110  return octave_value (scalar);
111  }
112 
113  sortmode is_sorted (sortmode mode = UNSORTED) const
114  { return mode ? mode : ASCENDING; }
115 
116  Array<octave_idx_type> sort_rows_idx (sortmode) const
117  {
118  return Array<octave_idx_type> (dim_vector (1, 1),
119  static_cast<octave_idx_type> (0));
120  }
121 
122  sortmode is_sorted_rows (sortmode mode = UNSORTED) const
123  { return mode ? mode : ASCENDING; }
124 
125  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
126  MatrixType matrix_type (const MatrixType&) const
127  { return matrix_type (); }
128 
129  bool is_scalar_type (void) const { return true; }
130 
131  bool is_numeric_type (void) const { return true; }
132 
133  bool is_true (void) const;
134 
135  void print (std::ostream& os, bool pr_as_read_syntax = false) const;
136 
137  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
138 
139  bool print_name_tag (std::ostream& os, const std::string& name) const;
140 
141  void short_disp (std::ostream& os) const;
142 
143  // Unsafe. This function exists to support the MEX interface.
144  // You should not use it anywhere else.
145  void *mex_get_data (void) const { return const_cast<ST *> (&scalar); }
146 
147  const ST& scalar_ref (void) const { return scalar; }
148 
149  ST& scalar_ref (void) { return scalar; }
150 
151  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
152 
153 protected:
154 
155  // The value of this scalar.
156  ST scalar;
157 };
158 
159 #endif