GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-cell.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1999-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 (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "Cell.h"
31#include "ovl.h"
32#include "pt-arg-list.h"
33#include "pt-eval.h"
34#include "pt-exp.h"
35#include "pt-cell.h"
36#include "pt-walk.h"
37#include "ov.h"
38
40
43{
44 tree_cell *new_cell = new tree_cell (nullptr);
45
46 new_cell->copy_base (*this, scope);
47
48 return new_cell;
49}
50
53{
54 unwind_action act ([&tw] (const std::list<octave_lvalue> *lvl)
55 {
56 tw.set_lvalue_list (lvl);
57 }, tw.lvalue_list ());
58 tw.set_lvalue_list (nullptr);
59
60 octave_idx_type nr = size ();
61 octave_idx_type nc = -1;
62
63 Cell val;
64
65 octave_idx_type i = 0;
66
67 for (tree_argument_list *elt : *this)
68 {
70
71 if (nr == 1)
72 // Optimize the single row case.
73 val = row.cell_value ();
74 else if (nc < 0)
75 {
76 nc = row.length ();
77
78 val = Cell (nr, nc);
79 }
80 else
81 {
82 octave_idx_type this_nc = row.length ();
83
84 if (this_nc != nc)
85 {
86 if (this_nc == 0)
87 continue; // blank line
88 else
89 error ("number of columns must match");
90 }
91 }
92
93 for (octave_idx_type j = 0; j < nc; j++)
94 val(i, j) = row(j);
95
96 i++;
97 }
98
99 if (i < nr)
100 val.resize (dim_vector (i, nc)); // there were blank rows
101
102 return octave_value (val);
103}
104
105OCTAVE_END_NAMESPACE(octave)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition Cell.h:41
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
Cell cell_value() const
Definition ovl.h:103
octave_idx_type length() const
Definition ovl.h:111
void copy_base(const tree_array_list &array_list)
tree_expression * dup(symbol_scope &scope) const
Definition pt-cell.cc:42
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-cell.cc:52
const std::list< octave_lvalue > * lvalue_list() const
Definition pt-eval.h:762
octave_value_list convert_to_const_vector(tree_argument_list *arg_list)
Definition pt-eval.cc:2358
void set_lvalue_list(const std::list< octave_lvalue > *lst)
Definition pt-eval.h:767
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003