4343
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4343
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_fcn_handle_h) |
|
25 #define octave_fcn_handle_h 1 |
|
26 |
|
27 #include <iostream> |
|
28 #include <string> |
|
29 |
|
30 #include "oct-alloc.h" |
|
31 |
|
32 #include "ov-base.h" |
4654
|
33 #include "ov-base-mat.h" |
4343
|
34 #include "ov-fcn.h" |
4654
|
35 #include "ov-typeinfo.h" |
4343
|
36 |
|
37 // Function handles. |
|
38 |
4925
|
39 class |
|
40 octave_fcn_handle : public octave_base_value |
4654
|
41 { |
|
42 public: |
4930
|
43 octave_fcn_handle (void) |
5663
|
44 : warn_reload (true), fcn (), nm () { } |
4654
|
45 |
5007
|
46 octave_fcn_handle (const std::string& n) |
5663
|
47 : warn_reload (true), fcn (), nm (n) { } |
5007
|
48 |
4930
|
49 octave_fcn_handle (const octave_value& f, const std::string& n) |
5663
|
50 : warn_reload (true), fcn (f), nm (n) { } |
4654
|
51 |
4967
|
52 octave_fcn_handle (const octave_fcn_handle& fh) |
5663
|
53 : octave_base_value (fh), warn_reload (fh.warn_reload), |
|
54 fcn (fh.fcn), nm (fh.nm) { } |
4967
|
55 |
4654
|
56 ~octave_fcn_handle (void) { } |
|
57 |
5759
|
58 octave_base_value *clone (void) const { return new octave_fcn_handle (*this); } |
|
59 octave_base_value *empty_clone (void) const { return new octave_fcn_handle (); } |
4967
|
60 |
4924
|
61 octave_value subsref (const std::string&, |
|
62 const std::list<octave_value_list>&) |
|
63 { |
|
64 panic_impossible (); |
|
65 return octave_value (); |
|
66 } |
|
67 |
|
68 octave_value_list subsref (const std::string& type, |
|
69 const std::list<octave_value_list>& idx, |
|
70 int nargout); |
|
71 |
4925
|
72 bool is_defined (void) const { return true; } |
4654
|
73 |
|
74 bool is_function_handle (void) const { return true; } |
|
75 |
5654
|
76 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
|
77 |
4930
|
78 octave_function *function_value (bool = false) |
|
79 { return fcn.function_value (); } |
|
80 |
4654
|
81 octave_fcn_handle *fcn_handle_value (bool = false) { return this; } |
|
82 |
5007
|
83 octave_value fcn_val (void) const { return fcn; } |
|
84 |
4933
|
85 std::string fcn_name (void) const { return nm; } |
4930
|
86 |
5958
|
87 bool save_ascii (std::ostream& os, bool& infnan_warned); |
4988
|
88 |
|
89 bool load_ascii (std::istream& is); |
|
90 |
|
91 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
92 |
|
93 bool load_binary (std::istream& is, bool swap, |
|
94 oct_mach_info::float_format fmt); |
|
95 |
|
96 #if defined (HAVE_HDF5) |
|
97 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
98 |
|
99 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
100 #endif |
|
101 |
4654
|
102 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
103 |
|
104 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
105 |
|
106 private: |
4343
|
107 |
4612
|
108 DECLARE_OCTAVE_ALLOCATOR |
4343
|
109 |
4612
|
110 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
4925
|
111 |
5663
|
112 // If TRUE, print a warning if the pointed-to fucntion is out of |
|
113 // date. This variable may be removed when updating is properly |
|
114 // implemented. |
|
115 mutable bool warn_reload; |
|
116 |
|
117 void reload_warning (const std::string& fcn_type) const; |
|
118 |
4933
|
119 protected: |
4930
|
120 |
4925
|
121 // The function we are handling. |
4930
|
122 octave_value fcn; |
4925
|
123 |
|
124 // The name of the handle, including the "@". |
|
125 std::string nm; |
4343
|
126 }; |
|
127 |
|
128 extern octave_value make_fcn_handle (const std::string& nm); |
|
129 |
|
130 #endif |
|
131 |
|
132 /* |
|
133 ;;; Local Variables: *** |
|
134 ;;; mode: C++ *** |
|
135 ;;; End: *** |
|
136 */ |