00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_class_h)
00024 #define octave_class_h 1
00025
00026 #include <cstdlib>
00027
00028 #include <iosfwd>
00029 #include <string>
00030
00031 #include "mx-base.h"
00032 #include "str-vec.h"
00033
00034 #include "error.h"
00035 #include "oct-alloc.h"
00036 #include "oct-map.h"
00037 #include "ov-base.h"
00038 #include "ov-typeinfo.h"
00039
00040 class octave_value_list;
00041
00042 class tree_walker;
00043
00044
00045
00046 class
00047 octave_class : public octave_base_value
00048 {
00049 public:
00050
00051 octave_class (void)
00052 : octave_base_value (), obsolete_copies (0) { }
00053
00054 octave_class (const Octave_map& m, const std::string& id)
00055 : octave_base_value (), map (m), c_name (id), obsolete_copies (0) { }
00056
00057 octave_class (const octave_class& s)
00058 : octave_base_value (s), map (s.map), c_name (s.c_name),
00059 parent_list (s.parent_list), obsolete_copies (0) { }
00060
00061 octave_class (const Octave_map& m, const std::string& id,
00062 const octave_value_list& parents);
00063
00064 ~octave_class (void) { }
00065
00066 octave_base_value *clone (void) const { return new octave_class (*this); }
00067
00068 octave_base_value *unique_clone (void);
00069
00070 octave_base_value *empty_clone (void) const
00071 {
00072 return new octave_class (Octave_map (map.keys ()), class_name ());
00073 }
00074
00075 Cell dotref (const octave_value_list& idx);
00076
00077 Matrix size (void);
00078
00079 octave_idx_type numel (const octave_value_list&);
00080
00081 octave_value subsref (const std::string& type,
00082 const std::list<octave_value_list>& idx)
00083 {
00084 octave_value_list tmp = subsref (type, idx, 1);
00085 return tmp.length () > 0 ? tmp(0) : octave_value ();
00086 }
00087
00088 octave_value_list subsref (const std::string& type,
00089 const std::list<octave_value_list>& idx,
00090 int nargout);
00091
00092 static octave_value numeric_conv (const Cell& val,
00093 const std::string& type);
00094
00095 void assign(const std::string& k, const octave_value& rhs)
00096 { map.assign (k, rhs); };
00097
00098 octave_value subsasgn (const std::string& type,
00099 const std::list<octave_value_list>& idx,
00100 const octave_value& rhs);
00101
00102 idx_vector index_vector (void) const;
00103
00104 dim_vector dims (void) const { return map.dims (); }
00105
00106 size_t byte_size (void) const;
00107
00108
00109
00110 octave_idx_type numel (void) const
00111 {
00112 dim_vector dv = dims ();
00113 return dv.numel ();
00114 }
00115
00116 octave_idx_type nfields (void) const { return map.nfields (); }
00117
00118 size_t nparents (void) const { return parent_list.size (); }
00119
00120 octave_value reshape (const dim_vector& new_dims) const
00121 { return map.reshape (new_dims); }
00122
00123 octave_value resize (const dim_vector& dv, bool = false) const
00124 { Octave_map tmap = map; tmap.resize (dv); return tmap; }
00125
00126 bool is_defined (void) const { return true; }
00127
00128 bool is_map (void) const { return false; }
00129
00130 bool is_object (void) const { return true; }
00131
00132 Octave_map map_value (void) const { return map; }
00133
00134 string_vector map_keys (void) const;
00135
00136 std::list<std::string> parent_class_name_list (void) const
00137 { return parent_list; }
00138
00139 string_vector parent_class_names (void) const
00140 { return string_vector (parent_list); }
00141
00142 octave_base_value *find_parent_class (const std::string&);
00143
00144 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00145
00146 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00147
00148 bool print_name_tag (std::ostream& os, const std::string& name) const;
00149
00150 void print_with_name (std::ostream& os, const std::string& name,
00151 bool print_padding = true);
00152
00153 bool reconstruct_exemplar (void);
00154
00155 static void clear_exemplar_map (void);
00156
00157 bool reconstruct_parents (void);
00158
00159 bool save_ascii (std::ostream& os);
00160
00161 bool load_ascii (std::istream& is);
00162
00163 bool save_binary (std::ostream& os, bool& save_as_floats);
00164
00165 bool load_binary (std::istream& is, bool swap,
00166 oct_mach_info::float_format fmt);
00167
00168 #if defined (HAVE_HDF5)
00169 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00170
00171 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00172 #endif
00173
00174 mxArray *as_mxArray (void) const;
00175
00176 private:
00177
00178 Octave_map map;
00179
00180 DECLARE_OCTAVE_ALLOCATOR
00181
00182 public:
00183 int type_id (void) const { return t_id; }
00184 std::string type_name (void) const { return t_name; }
00185 std::string class_name (void) const { return c_name; }
00186
00187 static int static_type_id (void) { return t_id; }
00188 static std::string static_type_name (void) { return t_name; }
00189 static std::string static_class_name (void) { return "<unknown>"; }
00190 static void register_type (void);
00191
00192 private:
00193 static int t_id;
00194
00195 static const std::string t_name;
00196 std::string c_name;
00197 std::list<std::string> parent_list;
00198
00199 bool in_class_method (void);
00200
00201 int obsolete_copies;
00202
00203 public:
00204
00205
00206 class exemplar_info
00207 {
00208 public:
00209
00210 exemplar_info (void) : field_names (), parent_class_names () { }
00211
00212 exemplar_info (const octave_value& obj);
00213
00214 exemplar_info (const exemplar_info& x)
00215 : field_names (x.field_names),
00216 parent_class_names (x.parent_class_names) { }
00217
00218 exemplar_info& operator = (const exemplar_info& x)
00219 {
00220 if (&x != this)
00221 {
00222 field_names = x.field_names;
00223 parent_class_names = x.parent_class_names;
00224 }
00225 return *this;
00226 }
00227
00228 octave_idx_type nfields (void) const { return field_names.length (); }
00229
00230 size_t nparents (void) const { return parent_class_names.size (); }
00231
00232 string_vector fields (void) const { return field_names; }
00233
00234 std::list<std::string> parents (void) const { return parent_class_names; }
00235
00236 bool compare (const octave_value& obj) const;
00237
00238 private:
00239
00240 string_vector field_names;
00241 std::list<std::string> parent_class_names;
00242 };
00243
00244
00245 static std::map<std::string, exemplar_info> exemplar_map;
00246
00247 typedef std::map<std::string, exemplar_info>::iterator exemplar_iterator;
00248 typedef std::map<std::string, exemplar_info>::const_iterator exemplar_const_iterator;
00249 };
00250
00251 #endif
00252
00253
00254
00255
00256
00257