GNU Octave  4.0.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-2015 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 "str-vec.h"
34 #include "MatrixType.h"
35 
36 #include "ov-base.h"
37 #include "ov-typeinfo.h"
38 
39 // Real scalar values.
40 
41 template <class ST>
42 class
44 {
45 public:
46 
48  : octave_base_value (), scalar () { }
49 
50  octave_base_scalar (const ST& s)
51  : octave_base_value (), scalar (s) { }
52 
54  : octave_base_value (), scalar (s.scalar) { }
55 
57 
58  octave_value squeeze (void) const { return scalar; }
59 
60  octave_value full_value (void) const { return scalar; }
61 
62  octave_value subsref (const std::string& type,
63  const std::list<octave_value_list>& idx);
64 
65  octave_value_list subsref (const std::string& type,
66  const std::list<octave_value_list>& idx, int)
67  { return subsref (type, idx); }
68 
69  octave_value subsasgn (const std::string& type,
70  const std::list<octave_value_list>& idx,
71  const octave_value& rhs);
72 
74  { return do_index_op (idx); }
75 
76  bool is_constant (void) const { return true; }
77 
78  bool is_defined (void) const { return true; }
79 
80  dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
81 
82  octave_idx_type numel (void) const { return 1; }
83 
84  int ndims (void) const { return 2; }
85 
86  octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; }
87 
88  octave_value permute (const Array<int>&, bool = false) const;
89 
90  octave_value reshape (const dim_vector& new_dims) const;
91 
92  size_t byte_size (void) const { return sizeof (ST); }
93 
94  octave_value all (int = 0) const { return (scalar != ST ()); }
95 
96  octave_value any (int = 0) const { return (scalar != ST ()); }
97 
98  octave_value diag (octave_idx_type k = 0) const;
99 
100  octave_value diag (octave_idx_type m, octave_idx_type n) const;
101 
103  { return octave_value (scalar); }
105  sortmode) const
106  {
107  sidx.resize (dim_vector (1, 1));
108  sidx(0) = 0;
109  return octave_value (scalar);
110  }
111 
113  { return mode ? mode : ASCENDING; }
114 
116  {
117  return Array<octave_idx_type> (dim_vector (1, 1),
118  static_cast<octave_idx_type> (0));
119  }
120 
122  { return mode ? mode : ASCENDING; }
123 
124  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
126  { return matrix_type (); }
127 
128  bool is_scalar_type (void) const { return true; }
129 
130  bool is_numeric_type (void) const { return true; }
131 
132  bool is_true (void) const;
133 
134  void print (std::ostream& os, bool pr_as_read_syntax = false);
135 
136  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
137 
138  bool print_name_tag (std::ostream& os, const std::string& name) const;
139 
140  void short_disp (std::ostream& os) const;
141 
142  // Unsafe. This function exists to support the MEX interface.
143  // You should not use it anywhere else.
144  void *mex_get_data (void) const { return const_cast<ST *> (&scalar); }
145 
146  const ST& scalar_ref (void) const { return scalar; }
147 
148  ST& scalar_ref (void) { return scalar; }
149 
150  octave_value fast_elem_extract (octave_idx_type n) const;
151 
152  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
153 
154 protected:
155 
156  // The value of this scalar.
157  ST scalar;
158 };
159 
160 #endif
sortmode is_sorted(sortmode mode=UNSORTED) const
bool is_true(const std::string &s)
Definition: mkoctfile.cc:373
size_t byte_size(void) const
const ST & scalar_ref(void) const
MatrixType matrix_type(void) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
sortmode
Definition: oct-sort.h:103
octave_value_list do_multi_index_op(int, const octave_value_list &idx)
octave_value any(int=0) const
bool is_scalar_type(void) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
octave_idx_type nnz(void) const
builtin_type_t
Definition: ov-base.h:59
bool is_defined(void) const
octave_value sort(octave_idx_type, sortmode) const
octave_base_scalar(const octave_base_scalar &s)
bool is_numeric_type(void) const
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1033
bool is_constant(void) const
octave_value squeeze(void) const
MatrixType matrix_type(const MatrixType &) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
Handles the reference counting for all the derived classes.
Definition: Array.h:45
octave_base_scalar(const ST &s)
octave_value full_value(void) const
octave_idx_type numel(void) const
void * mex_get_data(void) const
dim_vector dims(void) const
Array< octave_idx_type > sort_rows_idx(sortmode) const
int ndims(void) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:736
octave_value all(int=0) const