ov-cell.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1999-2012 John W. Eaton
00004 Copyright (C) 2009-2010 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #if !defined (octave_cell_h)
00025 #define octave_cell_h 1
00026 
00027 #include <cstdlib>
00028 
00029 #include <iosfwd>
00030 #include <string>
00031 #include <memory>
00032 
00033 #include "mx-base.h"
00034 #include "oct-alloc.h"
00035 #include "str-vec.h"
00036 
00037 #include "Cell.h"
00038 #include "error.h"
00039 #include "ov-base-mat.h"
00040 #include "ov-typeinfo.h"
00041 
00042 class octave_value_list;
00043 
00044 class tree_walker;
00045 
00046 // Cells.
00047 
00048 class
00049 octave_cell : public octave_base_matrix<Cell>
00050 {
00051 public:
00052 
00053   octave_cell (void)
00054     : octave_base_matrix<Cell> (), cellstr_cache () { }
00055 
00056   octave_cell (const Cell& c)
00057     : octave_base_matrix<Cell> (c), cellstr_cache () { }
00058 
00059   octave_cell (const Array<std::string>& str)
00060     : octave_base_matrix<Cell> (Cell (str)), cellstr_cache (new Array<std::string> (str)) { }
00061 
00062   octave_cell (const octave_cell& c)
00063     : octave_base_matrix<Cell> (c), cellstr_cache () { }
00064 
00065   ~octave_cell (void) { }
00066 
00067   octave_base_value *clone (void) const { return new octave_cell (*this); }
00068   octave_base_value *empty_clone (void) const { return new octave_cell (); }
00069 
00070 #if 0
00071   octave_base_value *try_narrowing_conversion (void);
00072 #endif
00073 
00074   octave_value subsref (const std::string& type,
00075                         const std::list<octave_value_list>& idx)
00076     {
00077       octave_value_list tmp = subsref (type, idx, 1);
00078       return tmp.length () > 0 ? tmp(0) : octave_value ();
00079     }
00080 
00081   octave_value_list subsref (const std::string& type,
00082                              const std::list<octave_value_list>& idx, int);
00083 
00084   octave_value subsref (const std::string& type,
00085                         const std::list<octave_value_list>& idx,
00086                         bool auto_add);
00087 
00088   octave_value subsasgn (const std::string& type,
00089                          const std::list<octave_value_list>& idx,
00090                          const octave_value& rhs);
00091 
00092   void assign (const octave_value_list& idx, const Cell& rhs);
00093 
00094   void assign (const octave_value_list& idx, const octave_value& rhs);
00095 
00096   void delete_elements (const octave_value_list& idx);
00097 
00098   size_t byte_size (void) const;
00099 
00100   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
00101 
00102   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
00103                      sortmode mode = ASCENDING) const;
00104 
00105   sortmode is_sorted (sortmode mode = UNSORTED) const;
00106 
00107   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
00108 
00109   sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
00110 
00111   bool is_matrix_type (void) const { return false; }
00112 
00113   bool is_numeric_type (void) const { return false; }
00114 
00115   bool is_defined (void) const { return true; }
00116 
00117   bool is_constant (void) const { return true; }
00118 
00119   bool is_cell (void) const { return true; }
00120 
00121   builtin_type_t builtin_type (void) const { return btyp_cell; }
00122 
00123   bool is_cellstr (void) const;
00124 
00125   bool is_true (void) const;
00126 
00127   Cell cell_value (void) const { return matrix; }
00128 
00129   octave_value_list list_value (void) const;
00130 
00131   octave_value convert_to_str_internal (bool pad, bool, char type) const
00132     { return octave_value (all_strings (pad), type); }
00133 
00134   string_vector all_strings (bool pad = false) const;
00135 
00136   Array<std::string> cellstr_value (void) const;
00137 
00138   bool print_as_scalar (void) const;
00139 
00140   void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00141 
00142   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00143 
00144 
00145   bool save_ascii (std::ostream& os);
00146 
00147   bool load_ascii (std::istream& is);
00148 
00149   bool save_binary (std::ostream& os, bool& save_as_floats);
00150 
00151   bool load_binary (std::istream& is, bool swap,
00152                     oct_mach_info::float_format fmt);
00153 
00154 #if defined (HAVE_HDF5)
00155   bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00156 
00157   bool load_hdf5 (hid_t loc_id, const char *name);
00158 #endif
00159 
00160   octave_value map (unary_mapper_t umap) const;
00161 
00162   mxArray *as_mxArray (void) const;
00163 
00164   // Unsafe.  This function exists to support the MEX interface.
00165   // You should not use it anywhere else.
00166   void *mex_get_data (void) const;
00167 
00168 private:
00169 
00170   void clear_cellstr_cache (void) const
00171     { cellstr_cache.reset (); }
00172 
00173   mutable std::auto_ptr<Array<std::string> > cellstr_cache;
00174 
00175   DECLARE_OCTAVE_ALLOCATOR
00176 
00177   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00178 };
00179 
00180 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines