GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-tm-const.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pt_tm_const_h)
27#define octave_pt_tm_const_h 1
28
29#include "octave-config.h"
30
31#include <list>
32#include <memory>
33#include <string>
34
35#include "Array.h"
36#include "Sparse.h"
37
38#include "data.h"
39#include "dim-vector.h"
40#include "oct-map.h"
41#include "ov.h"
42#include "ovl.h"
43#include "pt-arg-list.h"
44#include "pt-mat.h"
45
47
48class tree_evaluator;
49
50// Evaluate tree_matrix objects and convert them to octave_value
51// arrays (full and sparse numeric, char, cell, struct, class and
52// anything else that works like an array). Use a separate class
53// (tm_const) and pass the evaluator object to it instead of doing
54// all this work in tree_evaluator::visit_matrix because the job is
55// fairly large and requires extra data (stored in the tm_info
56// class) for each row and for the overall array.
57
58// Evaluate all elements of the array, recording info about each
59// row, then create summary info for the full array. Compute the
60// result type and dimension first before copying values.
61
62// FIXME: Handle overloading of horzcat and vertcat for for built-in
63// types.
64
65// Summary info about the current row or matrix.
66
68{
69public:
70
71 tm_info (bool obj_is_empty)
72 : m_dv (0, 0), m_all_strings (true), m_all_sq_strings (true),
73 m_all_dq_strings (true), m_some_strings (false),
74 m_all_real (true), m_all_complex (true), m_all_empty (true),
75 m_any_cell (false), m_any_sparse (false),
76 m_any_class (false), m_all_1x1 (! obj_is_empty),
78 { }
79
80 dim_vector dims () const { return m_dv; }
81
82 octave_idx_type rows () const { return m_dv(0); }
83 octave_idx_type cols () const { return m_dv(1); }
84
85 bool all_strings_p () const { return m_all_strings; }
86 bool all_sq_strings_p () const { return m_all_sq_strings; }
87 bool all_dq_strings_p () const { return m_all_dq_strings; }
88 bool some_strings_p () const { return m_some_strings; }
89 bool all_real_p () const { return m_all_real; }
90 bool all_complex_p () const { return m_all_complex; }
91 bool all_empty_p () const { return m_all_empty; }
92 bool any_cell_p () const { return m_any_cell; }
93 bool any_sparse_p () const { return m_any_sparse; }
94 bool any_class_p () const { return m_any_class; }
95 bool all_1x1_p () const { return m_all_1x1; }
97
98 std::string class_name () const { return m_class_name; }
99
100protected:
101
102 // Size of this row or matrix after evaluation.
104
105 // Are all elements character strings?
107
108 // Are all elements double-quoted character strings?
110
111 // Are all elements single-quoted character strings?
113
114 // Are any elements character strings?
116
117 // Are all elements real valued?
119
120 // Are all elements complex valued?
122
123 // Are all elements empty?
125
126 // Are any elements cells?
128
129 // Are any elements sparse arrays?
131
132 // Are any elements sparse class objects?
134
135 // Do all elements have dimensions 1x1?
137
138 // Is the first element a struct?
140
141 // Class name of result.
142 std::string m_class_name;
143};
144
145class tm_row_const : public tm_info
146{
147public:
148
149 typedef std::list<octave_value>::iterator iterator;
150 typedef std::list<octave_value>::const_iterator const_iterator;
151
152 tm_row_const () = delete;
153
155 : tm_info (row.empty ()), m_values ()
156 {
157 init (row, tw);
158 }
159
160 tm_row_const (const tm_row_const&) = default;
161
163
164 ~tm_row_const () = default;
165
166 iterator begin () { return m_values.begin (); }
167 const_iterator begin () const { return m_values.begin (); }
168
169 iterator end () { return m_values.end (); }
170 const_iterator end () const { return m_values.end (); }
171
172 bool empty () const { return m_values.empty (); }
173
174 std::size_t length () const { return m_values.size (); }
175
176 void cellify ();
177
178private:
179
180 std::list<octave_value> m_values;
181
182 void init_element (const octave_value&, bool&);
183
184 void init (const tree_argument_list&, tree_evaluator& tw);
185};
186
187class tm_const : public tm_info
188{
189public:
190
191 typedef std::list<tm_row_const>::iterator iterator;
192 typedef std::list<tm_row_const>::const_iterator const_iterator;
193
194 tm_const () = delete;
195
197 : tm_info (tm.empty ()), m_evaluator (tw), m_tm_rows ()
198 {
199 init (tm);
200 }
201
202 OCTAVE_DISABLE_COPY_MOVE (tm_const)
203
204 ~tm_const () = default;
205
206 octave_value concat (char string_fill_char) const;
207
208private:
209
210 tree_evaluator& m_evaluator;
211
212 // The list of lists of octave_value objects that contain the
213 // values of elements in each row of the tree_matrix object we are
214 // evaluating.
215
216 std::list<tm_row_const> m_tm_rows;
217
218 void init (const tree_matrix& tm);
219
220 octave_value char_array_concat (char string_fill_char) const;
221
222 octave_value class_concat () const;
223
224 octave_value generic_concat () const;
225
226 template <typename TYPE>
227 void array_concat_internal (TYPE& result) const;
228
229 template <typename TYPE>
230 TYPE array_concat () const;
231
232 template <typename TYPE>
233 TYPE sparse_array_concat () const;
234
235 template <typename MAP>
236 octave_map map_concat () const;
237};
238
239OCTAVE_END_NAMESPACE(octave)
240
241#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
~tm_const()=default
std::list< tm_row_const >::const_iterator const_iterator
std::list< tm_row_const >::iterator iterator
octave_value concat(char string_fill_char) const
tm_const()=delete
tm_const(const tree_matrix &tm, tree_evaluator &tw)
bool all_sq_strings_p() const
Definition pt-tm-const.h:86
bool m_any_class
bool m_all_1x1
bool all_empty_p() const
Definition pt-tm-const.h:91
bool all_1x1_p() const
Definition pt-tm-const.h:95
bool m_all_complex
bool some_strings_p() const
Definition pt-tm-const.h:88
bool all_dq_strings_p() const
Definition pt-tm-const.h:87
dim_vector dims() const
Definition pt-tm-const.h:80
bool m_first_elem_is_struct
bool m_all_real
tm_info(bool obj_is_empty)
Definition pt-tm-const.h:71
dim_vector m_dv
bool m_some_strings
bool m_any_sparse
octave_idx_type cols() const
Definition pt-tm-const.h:83
bool m_any_cell
bool all_real_p() const
Definition pt-tm-const.h:89
octave_idx_type rows() const
Definition pt-tm-const.h:82
bool m_all_empty
std::string m_class_name
bool any_cell_p() const
Definition pt-tm-const.h:92
bool any_class_p() const
Definition pt-tm-const.h:94
bool first_elem_struct_p() const
Definition pt-tm-const.h:96
bool m_all_dq_strings
bool m_all_sq_strings
bool any_sparse_p() const
Definition pt-tm-const.h:93
bool all_complex_p() const
Definition pt-tm-const.h:90
bool m_all_strings
bool all_strings_p() const
Definition pt-tm-const.h:85
std::string class_name() const
Definition pt-tm-const.h:98
~tm_row_const()=default
std::size_t length() const
iterator begin()
iterator end()
bool empty() const
std::list< octave_value >::iterator iterator
tm_row_const(const tm_row_const &)=default
tm_row_const & operator=(const tm_row_const &)=delete
const_iterator begin() const
tm_row_const()=delete
const_iterator end() const
std::list< octave_value >::const_iterator const_iterator
tm_row_const(const tree_argument_list &row, tree_evaluator &tw)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn