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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_fcn_handle_h) |
|
24 #define octave_fcn_handle_h 1 |
|
25 |
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <iostream> |
|
31 #include <string> |
|
32 |
|
33 #include "oct-alloc.h" |
|
34 |
|
35 #include "ov-base.h" |
4654
|
36 #include "ov-base-mat.h" |
4343
|
37 #include "ov-fcn.h" |
4654
|
38 #include "ov-typeinfo.h" |
4343
|
39 #include "symtab.h" |
|
40 |
|
41 // Function handles. |
|
42 |
4925
|
43 class |
|
44 octave_fcn_handle : public octave_base_value |
4654
|
45 { |
|
46 public: |
4930
|
47 enum fcn_type { fcn_handle = 1, fcn_inline = 2 }; |
4654
|
48 |
4930
|
49 octave_fcn_handle (void) |
|
50 : typ (fcn_handle), fcn (), nm (), iftext (), ifargs () { } |
4654
|
51 |
4930
|
52 octave_fcn_handle (const octave_value& f, const std::string& n) |
|
53 : typ (fcn_handle), fcn (f), nm (n), iftext (), ifargs () { } |
|
54 |
|
55 octave_fcn_handle (const std::string& f, const string_vector& a, |
|
56 const std::string& n = std::string ()); |
4654
|
57 |
|
58 ~octave_fcn_handle (void) { } |
|
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 |
4930
|
75 octave_function *function_value (bool = false) |
|
76 { return fcn.function_value (); } |
|
77 |
|
78 std::string inline_fcn_name (void) const { return nm; } |
4654
|
79 |
4930
|
80 std::string inline_fcn_text (void) const { return iftext; } |
|
81 |
|
82 string_vector inline_fcn_arg_names (void) const { return ifargs; } |
|
83 |
|
84 bool is_inline (void) const { return (typ == fcn_inline); } |
4654
|
85 |
|
86 octave_fcn_handle *fcn_handle_value (bool = false) { return this; } |
|
87 |
4930
|
88 octave_value convert_to_str_internal (bool, bool) const; |
|
89 |
4654
|
90 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
91 |
|
92 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
|
93 |
|
94 private: |
4343
|
95 |
4925
|
96 // No copying! |
|
97 |
|
98 octave_fcn_handle (const octave_fcn_handle& fh); |
|
99 |
|
100 octave_fcn_handle& operator = (const octave_fcn_handle& fh); |
|
101 |
4612
|
102 DECLARE_OCTAVE_ALLOCATOR |
4343
|
103 |
4612
|
104 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
4925
|
105 |
4930
|
106 // The type of function handle |
|
107 fcn_type typ; |
|
108 |
4925
|
109 // The function we are handling. |
4930
|
110 octave_value fcn; |
4925
|
111 |
|
112 // The name of the handle, including the "@". |
|
113 std::string nm; |
4930
|
114 |
|
115 // The expression of an inline function |
|
116 std::string iftext; |
|
117 |
|
118 // The args of an inline function |
|
119 string_vector ifargs; |
4343
|
120 }; |
|
121 |
|
122 extern octave_value make_fcn_handle (const std::string& nm); |
|
123 |
|
124 #endif |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |