4343
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4343
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
4343
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
4343
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_fcn_handle_h) |
|
24 #define octave_fcn_handle_h 1 |
|
25 |
|
26 #include <iostream> |
|
27 #include <string> |
|
28 |
|
29 #include "oct-alloc.h" |
|
30 |
|
31 #include "ov-base.h" |
4654
|
32 #include "ov-base-mat.h" |
4343
|
33 #include "ov-fcn.h" |
4654
|
34 #include "ov-typeinfo.h" |
4343
|
35 |
|
36 // Function handles. |
|
37 |
4925
|
38 class |
|
39 octave_fcn_handle : public octave_base_value |
4654
|
40 { |
|
41 public: |
4930
|
42 octave_fcn_handle (void) |
5663
|
43 : warn_reload (true), fcn (), nm () { } |
4654
|
44 |
5007
|
45 octave_fcn_handle (const std::string& n) |
5663
|
46 : warn_reload (true), fcn (), nm (n) { } |
5007
|
47 |
4930
|
48 octave_fcn_handle (const octave_value& f, const std::string& n) |
5663
|
49 : warn_reload (true), fcn (f), nm (n) { } |
4654
|
50 |
4967
|
51 octave_fcn_handle (const octave_fcn_handle& fh) |
5663
|
52 : octave_base_value (fh), warn_reload (fh.warn_reload), |
|
53 fcn (fh.fcn), nm (fh.nm) { } |
4967
|
54 |
4654
|
55 ~octave_fcn_handle (void) { } |
|
56 |
5759
|
57 octave_base_value *clone (void) const { return new octave_fcn_handle (*this); } |
|
58 octave_base_value *empty_clone (void) const { return new octave_fcn_handle (); } |
4967
|
59 |
4924
|
60 octave_value subsref (const std::string&, |
|
61 const std::list<octave_value_list>&) |
|
62 { |
|
63 panic_impossible (); |
|
64 return octave_value (); |
|
65 } |
|
66 |
|
67 octave_value_list subsref (const std::string& type, |
|
68 const std::list<octave_value_list>& idx, |
|
69 int nargout); |
|
70 |
4925
|
71 bool is_defined (void) const { return true; } |
4654
|
72 |
|
73 bool is_function_handle (void) const { return true; } |
|
74 |
5654
|
75 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
|
76 |
4930
|
77 octave_function *function_value (bool = false) |
|
78 { return fcn.function_value (); } |
|
79 |
6625
|
80 octave_user_function *user_function_value (bool = false) |
|
81 { return fcn.user_function_value (); } |
|
82 |
4654
|
83 octave_fcn_handle *fcn_handle_value (bool = false) { return this; } |
|
84 |
5007
|
85 octave_value fcn_val (void) const { return fcn; } |
|
86 |
4933
|
87 std::string fcn_name (void) const { return nm; } |
4930
|
88 |
6974
|
89 bool save_ascii (std::ostream& os); |
4988
|
90 |
|
91 bool load_ascii (std::istream& is); |
|
92 |
|
93 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
94 |
|
95 bool load_binary (std::istream& is, bool swap, |
|
96 oct_mach_info::float_format fmt); |
|
97 |
|
98 #if defined (HAVE_HDF5) |
|
99 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
100 |
|
101 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
102 #endif |
|
103 |
4654
|
104 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
105 |
|
106 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
107 |
|
108 private: |
4343
|
109 |
6625
|
110 bool set_fcn (const std::string &octaveroot, const std::string& fpath); |
|
111 |
4612
|
112 DECLARE_OCTAVE_ALLOCATOR |
4343
|
113 |
4612
|
114 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
4925
|
115 |
5663
|
116 // If TRUE, print a warning if the pointed-to fucntion is out of |
|
117 // date. This variable may be removed when updating is properly |
|
118 // implemented. |
|
119 mutable bool warn_reload; |
|
120 |
|
121 void reload_warning (const std::string& fcn_type) const; |
|
122 |
4933
|
123 protected: |
4930
|
124 |
4925
|
125 // The function we are handling. |
4930
|
126 octave_value fcn; |
4925
|
127 |
|
128 // The name of the handle, including the "@". |
|
129 std::string nm; |
4343
|
130 }; |
|
131 |
|
132 extern octave_value make_fcn_handle (const std::string& nm); |
|
133 |
|
134 #endif |
|
135 |
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |