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