Mercurial > octave-nkf
comparison src/ov-fcn-handle.cc @ 4654:a9b22513b7a6
[project @ 2003-11-24 18:56:35 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 18:56:35 +0000 |
parents | f7ce581b27fb |
children | c8829691db47 |
comparison
equal
deleted
inserted
replaced
4653:14ab7b05a572 | 4654:a9b22513b7a6 |
---|---|
29 #endif | 29 #endif |
30 | 30 |
31 #include <iostream> | 31 #include <iostream> |
32 | 32 |
33 #include "defun.h" | 33 #include "defun.h" |
34 #include "error.h" | |
35 #include "gripes.h" | |
34 #include "oct-map.h" | 36 #include "oct-map.h" |
35 #include "ov-base.h" | 37 #include "ov-base.h" |
38 #include "ov-base-mat.h" | |
39 #include "ov-base-mat.cc" | |
36 #include "ov-fcn-handle.h" | 40 #include "ov-fcn-handle.h" |
37 #include "pr-output.h" | 41 #include "pr-output.h" |
38 #include "variables.h" | 42 #include "variables.h" |
39 | 43 |
44 // Instantiate Arrays of fcn_handle_elt values. | |
45 | |
46 #include "Array.h" | |
47 #include "Array.cc" | |
48 | |
49 INSTANTIATE_ARRAY_AND_ASSIGN (fcn_handle_elt); | |
50 | |
51 #include "Array2.h" | |
52 | |
53 template class Array2<fcn_handle_elt>; | |
54 | |
55 #include "ArrayN.h" | |
56 #include "ArrayN.cc" | |
57 | |
58 template class ArrayN<fcn_handle_elt>; | |
59 | |
60 template class octave_base_matrix<fcn_handle_array>; | |
61 | |
62 boolNDArray | |
63 fcn_handle_array::all (int) const | |
64 { | |
65 error ("all: invalid call for function handle object"); | |
66 return boolNDArray (); | |
67 } | |
68 | |
69 boolNDArray | |
70 fcn_handle_array::any (int) const | |
71 { | |
72 error ("any: invalid call for function handle object"); | |
73 return boolNDArray (); | |
74 } | |
75 | |
40 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); | 76 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); |
41 | 77 |
42 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, | 78 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, |
43 "function handle", | 79 "function handle", |
44 "function handle"); | 80 "function handle"); |
45 | 81 |
82 octave_function * | |
83 octave_fcn_handle::function_value (bool) | |
84 { | |
85 octave_function *retval = 0; | |
86 | |
87 if (numel () > 0) | |
88 { | |
89 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? | |
90 if (Vwarn_fortran_indexing) | |
91 gripe_implicit_conversion ("function handle array", | |
92 "scalar function handle"); | |
93 | |
94 fcn_handle_elt elt = matrix(0); | |
95 | |
96 retval = elt.function_value (); | |
97 } | |
98 else | |
99 gripe_invalid_conversion ("function handle array", | |
100 "scalar function handle"); | |
101 | |
102 return retval; | |
103 } | |
104 | |
105 std::string | |
106 octave_fcn_handle::name (void) const | |
107 { | |
108 std::string retval; | |
109 | |
110 if (numel () > 0) | |
111 { | |
112 // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? | |
113 if (Vwarn_fortran_indexing) | |
114 gripe_implicit_conversion ("function handle array", | |
115 "scalar function handle"); | |
116 | |
117 fcn_handle_elt elt = matrix(0); | |
118 | |
119 retval = elt.name (); | |
120 } | |
121 else | |
122 gripe_invalid_conversion ("function handle array", | |
123 "scalar function handle"); | |
124 | |
125 return retval; | |
126 } | |
127 | |
128 ArrayN<std::string> | |
129 fcn_handle_array::names (void) const | |
130 { | |
131 ArrayN<std::string> retval (dims ()); | |
132 | |
133 int nel = length (); | |
134 | |
135 for (int i = 0; i < nel; i++) | |
136 { | |
137 fcn_handle_elt elt = elem (i); | |
138 | |
139 retval(i) = elt.name (); | |
140 } | |
141 | |
142 return retval; | |
143 } | |
144 | |
46 void | 145 void |
47 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const | 146 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const |
48 { | 147 { |
49 print_raw (os, pr_as_read_syntax); | 148 print_raw (os, pr_as_read_syntax); |
50 newline (os); | 149 newline (os); |
51 } | 150 } |
52 | 151 |
53 void | 152 void |
54 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | 153 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
55 { | 154 { |
155 dim_vector dv = matrix.dims (); | |
156 os << "<" << dv.str () << " function handle object>"; | |
157 | |
158 #if 0 | |
56 indent (os); | 159 indent (os); |
57 os << name (); | 160 octave_print_internal (os, name_array (), pr_as_read_syntax, |
161 current_print_indent_level (), true); | |
162 #endif | |
58 } | 163 } |
59 | 164 |
60 octave_value | 165 octave_value |
61 make_fcn_handle (const std::string& nm) | 166 make_fcn_handle (const std::string& nm) |
62 { | 167 { |
63 octave_value retval; | 168 octave_value retval; |
64 | 169 |
65 octave_function *f = lookup_function (nm); | 170 octave_function *f = lookup_function (nm); |
66 | 171 |
67 if (f) | 172 if (f) |
68 { | 173 return fcn_handle_array (f, nm); |
69 octave_fcn_handle fh (f, nm); | |
70 | |
71 retval = octave_value (fh); | |
72 } | |
73 else | 174 else |
74 error ("error creating function handle \"@%s\"", nm.c_str ()); | 175 error ("error creating function handle \"@%s\"", nm.c_str ()); |
75 | 176 |
76 return retval; | 177 return retval; |
77 } | 178 } |