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-cell.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1999-2013 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_ov_cell_h)
25 #define octave_ov_cell_h 1
26 
27 #include <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 #include <memory>
32 
33 #include "mx-base.h"
34 #include "oct-alloc.h"
35 #include "str-vec.h"
36 
37 #include "Cell.h"
38 #include "error.h"
39 #include "ov-base-mat.h"
40 #include "ov-typeinfo.h"
41 
42 class octave_value_list;
43 
44 class tree_walker;
45 
46 // Cells.
47 
48 class
50 {
51 public:
52 
53  octave_cell (void)
54  : octave_base_matrix<Cell> (), cellstr_cache () { }
55 
56  octave_cell (const Cell& c)
57  : octave_base_matrix<Cell> (c), cellstr_cache () { }
58 
60  : octave_base_matrix<Cell> (Cell (str)),
61  cellstr_cache (new Array<std::string> (str)) { }
62 
64  : octave_base_matrix<Cell> (c), cellstr_cache () { }
65 
66  ~octave_cell (void) { }
67 
68  octave_base_value *clone (void) const { return new octave_cell (*this); }
69  octave_base_value *empty_clone (void) const { return new octave_cell (); }
70 
71 #if 0
72  octave_base_value *try_narrowing_conversion (void);
73 #endif
74 
75  octave_value subsref (const std::string& type,
76  const std::list<octave_value_list>& idx)
77  {
78  octave_value_list tmp = subsref (type, idx, 1);
79  return tmp.length () > 0 ? tmp(0) : octave_value ();
80  }
81 
82  octave_value_list subsref (const std::string& type,
83  const std::list<octave_value_list>& idx,
84  int nargout)
85  {
86  return subsref (type, idx, nargout, 0);
87  }
88 
89  octave_value_list subsref (const std::string& type,
90  const std::list<octave_value_list>& idx,
91  int nargout,
92  const std::list<octave_lvalue> *lvalue_list);
93 
94  octave_value subsref (const std::string& type,
95  const std::list<octave_value_list>& idx,
96  bool auto_add);
97 
98  octave_value subsasgn (const std::string& type,
99  const std::list<octave_value_list>& idx,
100  const octave_value& rhs);
101 
102  void assign (const octave_value_list& idx, const Cell& rhs);
103 
104  void assign (const octave_value_list& idx, const octave_value& rhs);
105 
106  void delete_elements (const octave_value_list& idx);
107 
108  size_t byte_size (void) const;
109 
110  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
111 
113  sortmode mode = ASCENDING) const;
114 
115  sortmode is_sorted (sortmode mode = UNSORTED) const;
116 
117  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
118 
119  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
120 
121  bool is_matrix_type (void) const { return false; }
122 
123  bool is_numeric_type (void) const { return false; }
124 
125  bool is_defined (void) const { return true; }
126 
127  bool is_constant (void) const { return true; }
128 
129  bool is_cell (void) const { return true; }
130 
131  builtin_type_t builtin_type (void) const { return btyp_cell; }
132 
133  bool is_cellstr (void) const;
134 
135  bool is_true (void) const;
136 
137  Cell cell_value (void) const { return matrix; }
138 
139  octave_value_list list_value (void) const;
140 
141  octave_value convert_to_str_internal (bool pad, bool, char type) const
142  { return octave_value (all_strings (pad), type); }
143 
144  string_vector all_strings (bool pad = false) const;
145 
146  Array<std::string> cellstr_value (void) const;
147 
148  bool print_as_scalar (void) const;
149 
150  void print (std::ostream& os, bool pr_as_read_syntax = false) const;
151 
152  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
153 
154  void short_disp (std::ostream& os) const;
155 
156  bool save_ascii (std::ostream& os);
157 
158  bool load_ascii (std::istream& is);
159 
160  bool save_binary (std::ostream& os, bool& save_as_floats);
161 
162  bool load_binary (std::istream& is, bool swap,
164 
165 #if defined (HAVE_HDF5)
166  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
167 
168  bool load_hdf5 (hid_t loc_id, const char *name);
169 #endif
170 
171  octave_value map (unary_mapper_t umap) const;
172 
173  mxArray *as_mxArray (void) const;
174 
175  // Unsafe. This function exists to support the MEX interface.
176  // You should not use it anywhere else.
177  void *mex_get_data (void) const;
178 
179 private:
180 
181  void clear_cellstr_cache (void) const
182  { cellstr_cache.reset (); }
183 
184  mutable std::auto_ptr<Array<std::string> > cellstr_cache;
185 
187 
189 };
190 
191 #endif