GNU Octave  4.2.1
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
pt-cell.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1999-2017 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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <iostream>
28 
29 #include "Cell.h"
30 #include "ovl.h"
31 #include "pt-arg-list.h"
32 #include "pt-exp.h"
33 #include "pt-cell.h"
34 #include "pt-walk.h"
35 #include "ov.h"
36 
39 {
41 
42  octave_idx_type nr = length ();
43  octave_idx_type nc = -1;
44 
45  Cell val;
46 
47  octave_idx_type i = 0;
48 
49  for (iterator p = begin (); p != end (); p++)
50  {
51  tree_argument_list *elt = *p;
52 
54 
55  if (nr == 1)
56  // Optimize the single row case.
57  val = row.cell_value ();
58  else if (nc < 0)
59  {
60  nc = row.length ();
61 
62  val = Cell (nr, nc);
63  }
64  else
65  {
66  octave_idx_type this_nc = row.length ();
67 
68  if (this_nc != nc)
69  {
70  if (this_nc == 0)
71  continue; // blank line
72  else
73  error ("number of columns must match");
74  }
75  }
76 
77  for (octave_idx_type j = 0; j < nc; j++)
78  val(i,j) = row(j);
79 
80  i++;
81  }
82 
83  if (i < nr)
84  val.resize (dim_vector (i, nc)); // there were blank rows
85  retval = val;
86 
87  return retval;
88 }
89 
92 {
93  if (nargout > 1)
94  error ("invalid number of output arguments for cell array");
95 
96  return rvalue1 (nargout);
97 }
98 
102 {
103  tree_cell *new_cell = new tree_cell (0, line (), column ());
104 
105  new_cell->copy_base (*this, scope, context);
106 
107  return new_cell;
108 }
109 
110 void
112 {
113  tw.visit_cell (*this);
114 }
Definition: Cell.h:37
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
octave_idx_type length(void) const
Definition: ovl.h:96
octave_value_list convert_to_const_vector(const octave_value *object=0)
octave_value_list rvalue(int)
Definition: pt-cell.cc:91
void error(const char *fmt,...)
Definition: error.cc:570
tree_expression * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-cell.cc:100
Cell cell_value(void) const
Definition: ovl.h:88
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
octave_value retval
Definition: data.cc:6294
void copy_base(const tree_array_list &array_list)
octave::base_list< tree_argument_list * >::iterator iterator
Definition: pt-array-list.h:41
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
p
Definition: lu.cc:138
tree_cell(tree_argument_list *row=0, int l=-1, int c=-1)
Definition: pt-cell.h:46
octave_value rvalue1(int nargout=1)
Definition: pt-cell.cc:38
virtual void visit_cell(tree_cell &)=0
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
virtual int column(void) const
Definition: pt.h:51
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
Definition: str2double.cc:342
void accept(tree_walker &tw)
Definition: pt-cell.cc:111