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_fcn_handle_h)
00024 #define octave_fcn_handle_h 1
00025
00026 #include <iosfwd>
00027 #include <string>
00028 #include <memory>
00029
00030 #include "oct-alloc.h"
00031
00032 #include "ov-base.h"
00033 #include "ov-base-mat.h"
00034 #include "ov-fcn.h"
00035 #include "ov-typeinfo.h"
00036
00037
00038
00039 class
00040 OCTINTERP_API
00041 octave_fcn_handle : public octave_base_value
00042 {
00043 private:
00044
00045 typedef std::map<std::string, octave_value> str_ov_map;
00046
00047 octave_fcn_handle (const octave_value& f, const std::string& n,
00048 str_ov_map *sdisp)
00049 : fcn (f), nm (n), disp (sdisp) { }
00050
00051 public:
00052 octave_fcn_handle (void)
00053 : fcn (), nm () { }
00054
00055 octave_fcn_handle (const std::string& n)
00056 : fcn (), nm (n) { }
00057
00058 octave_fcn_handle (const octave_value& f, const std::string& n);
00059
00060 octave_fcn_handle (const octave_fcn_handle& fh)
00061 : octave_base_value (fh), fcn (fh.fcn), nm (fh.nm)
00062 {
00063 if (fh.disp.get ())
00064 disp.reset (new str_ov_map (*fh.disp));
00065 }
00066
00067 ~octave_fcn_handle (void) { }
00068
00069 octave_base_value *clone (void) const { return new octave_fcn_handle (*this); }
00070 octave_base_value *empty_clone (void) const { return new octave_fcn_handle (); }
00071
00072 octave_value subsref (const std::string& type,
00073 const std::list<octave_value_list>& idx)
00074 {
00075 octave_value_list tmp = subsref (type, idx, 1);
00076 return tmp.length () > 0 ? tmp(0) : octave_value ();
00077 }
00078
00079 octave_value_list subsref (const std::string& type,
00080 const std::list<octave_value_list>& idx,
00081 int nargout);
00082
00083 octave_value_list
00084 do_multi_index_op (int nargout, const octave_value_list& args);
00085
00086 bool is_defined (void) const { return true; }
00087
00088 bool is_function_handle (void) const { return true; }
00089
00090 bool is_overloaded (void) const { return disp.get () && ! disp->empty (); }
00091
00092 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
00093
00094 octave_function *function_value (bool = false)
00095 { return fcn.function_value (); }
00096
00097 const octave_function *function_value (bool = false) const
00098 { return fcn.function_value (); }
00099
00100 octave_user_function *user_function_value (bool = false)
00101 { return fcn.user_function_value (); }
00102
00103 octave_fcn_handle *fcn_handle_value (bool = false) { return this; }
00104
00105 octave_value fcn_val (void) const { return fcn; }
00106
00107 std::string fcn_name (void) const { return nm; }
00108
00109 bool save_ascii (std::ostream& os);
00110
00111 bool load_ascii (std::istream& is);
00112
00113 bool save_binary (std::ostream& os, bool& save_as_floats);
00114
00115 bool load_binary (std::istream& is, bool swap,
00116 oct_mach_info::float_format fmt);
00117
00118 #if defined (HAVE_HDF5)
00119 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00120
00121 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00122 #endif
00123
00124 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
00125
00126 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
00127
00128 private:
00129
00130 bool set_fcn (const std::string &octaveroot, const std::string& fpath);
00131
00132 DECLARE_OCTAVE_ALLOCATOR
00133
00134 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00135
00136 protected:
00137
00138
00139 octave_value fcn;
00140
00141
00142 std::string nm;
00143
00144
00145
00146 std::auto_ptr<str_ov_map> disp;
00147
00148 friend octave_value make_fcn_handle (const std::string &, bool);
00149 };
00150
00151 extern octave_value make_fcn_handle (const std::string& nm,
00152 bool local_funcs = true);
00153
00154 #endif
00155
00156
00157
00158
00159
00160