Mercurial > octave
annotate src/ov-fcn-handle.h @ 7761:5adeea5de26c
symbol table reporting functions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 May 2008 05:51:17 -0400 |
parents | 443a8f5a50fd |
children | f6fffa74b9b5 |
rev | line source |
---|---|
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 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
48 octave_fcn_handle (const octave_value& f, const std::string& n); |
4654 | 49 |
4967 | 50 octave_fcn_handle (const octave_fcn_handle& fh) |
5663 | 51 : octave_base_value (fh), warn_reload (fh.warn_reload), |
52 fcn (fh.fcn), nm (fh.nm) { } | |
4967 | 53 |
4654 | 54 ~octave_fcn_handle (void) { } |
55 | |
5759 | 56 octave_base_value *clone (void) const { return new octave_fcn_handle (*this); } |
57 octave_base_value *empty_clone (void) const { return new octave_fcn_handle (); } | |
4967 | 58 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
59 octave_value subsref (const std::string& type, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
60 const std::list<octave_value_list>& idx) |
4924 | 61 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
62 octave_value_list tmp = subsref (type, idx, 1); |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
63 return tmp.length () > 0 ? tmp(0) : octave_value (); |
4924 | 64 } |
65 | |
66 octave_value_list subsref (const std::string& type, | |
67 const std::list<octave_value_list>& idx, | |
68 int nargout); | |
69 | |
4925 | 70 bool is_defined (void) const { return true; } |
4654 | 71 |
72 bool is_function_handle (void) const { return true; } | |
73 | |
5654 | 74 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
75 | |
4930 | 76 octave_function *function_value (bool = false) |
77 { return fcn.function_value (); } | |
78 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
79 const octave_function *function_value (bool = false) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
80 { return fcn.function_value (); } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
81 |
6625 | 82 octave_user_function *user_function_value (bool = false) |
83 { return fcn.user_function_value (); } | |
84 | |
4654 | 85 octave_fcn_handle *fcn_handle_value (bool = false) { return this; } |
86 | |
5007 | 87 octave_value fcn_val (void) const { return fcn; } |
88 | |
4933 | 89 std::string fcn_name (void) const { return nm; } |
4930 | 90 |
6974 | 91 bool save_ascii (std::ostream& os); |
4988 | 92 |
93 bool load_ascii (std::istream& is); | |
94 | |
95 bool save_binary (std::ostream& os, bool& save_as_floats); | |
96 | |
97 bool load_binary (std::istream& is, bool swap, | |
98 oct_mach_info::float_format fmt); | |
99 | |
100 #if defined (HAVE_HDF5) | |
101 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
102 | |
103 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
104 #endif | |
105 | |
4654 | 106 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
107 | |
108 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
109 | |
110 private: | |
4343 | 111 |
6625 | 112 bool set_fcn (const std::string &octaveroot, const std::string& fpath); |
113 | |
4612 | 114 DECLARE_OCTAVE_ALLOCATOR |
4343 | 115 |
4612 | 116 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
4925 | 117 |
5663 | 118 // If TRUE, print a warning if the pointed-to fucntion is out of |
119 // date. This variable may be removed when updating is properly | |
120 // implemented. | |
121 mutable bool warn_reload; | |
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 */ |