2974
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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_mapper_h) |
|
24 #define octave_mapper_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2974
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <string> |
|
31 |
4055
|
32 #include "oct-obj.h" |
2974
|
33 #include "ov-fcn.h" |
|
34 #include "ov-typeinfo.h" |
|
35 |
|
36 class octave_value; |
|
37 class octave_value_list; |
|
38 |
|
39 // Builtin mapper functions. |
|
40 |
|
41 class |
|
42 octave_mapper : public octave_function |
|
43 { |
|
44 public: |
|
45 |
4645
|
46 octave_mapper (void) { } |
4644
|
47 |
2974
|
48 typedef int (*ch_mapper) (int); |
3249
|
49 typedef bool (*d_b_mapper) (double); |
|
50 typedef bool (*c_b_mapper) (const Complex&); |
2974
|
51 typedef double (*d_d_mapper) (double); |
|
52 typedef double (*d_c_mapper) (const Complex&); |
|
53 typedef Complex (*c_c_mapper) (const Complex&); |
|
54 |
3249
|
55 octave_mapper (ch_mapper ch, d_b_mapper db, c_b_mapper cb, |
|
56 d_d_mapper dd, d_c_mapper dc, |
4100
|
57 c_c_mapper cc, double ll, double ul, |
|
58 int cmf, bool crcfr, |
3523
|
59 const std::string& nm = std::string (), |
|
60 const std::string& ds = std::string ()) |
3249
|
61 : octave_function (nm, ds), ch_map_fcn (ch), |
|
62 d_b_map_fcn (db), c_b_map_fcn (cb), |
|
63 d_d_map_fcn (dd), d_c_map_fcn (dc), c_c_map_fcn (cc), |
4100
|
64 lower_limit (ll), upper_limit (ul), ch_map_flag (cmf), |
|
65 can_ret_cmplx_for_real (crcfr) { } |
2974
|
66 |
|
67 ~octave_mapper (void) { } |
|
68 |
|
69 octave_function *function_value (bool) { return this; } |
|
70 |
4271
|
71 octave_value subsref (const std::string& type, |
|
72 const std::list<octave_value_list>& idx) |
|
73 { |
|
74 panic_impossible (); |
|
75 return octave_value (); |
|
76 } |
|
77 |
4247
|
78 octave_value_list subsref (const std::string& type, |
4219
|
79 const std::list<octave_value_list>& idx, |
3933
|
80 int nargout); |
|
81 |
3544
|
82 octave_value_list |
|
83 do_multi_index_op (int nargout, const octave_value_list& args); |
2974
|
84 |
|
85 private: |
|
86 |
|
87 octave_value apply (const octave_value& arg) const; |
|
88 |
|
89 // ch_map_fcn is a kluge. |
|
90 |
|
91 ch_mapper ch_map_fcn; |
3249
|
92 d_b_mapper d_b_map_fcn; |
|
93 c_b_mapper c_b_map_fcn; |
2974
|
94 d_d_mapper d_d_map_fcn; |
|
95 d_c_mapper d_c_map_fcn; |
|
96 c_c_mapper c_c_map_fcn; |
|
97 |
|
98 // If flag is nonzero and we are not calling ch_map_fcn, lower_limit |
|
99 // and upper_limit specify the range of values for which a real arg |
|
100 // returns a real value. Outside that range, we have to convert args |
|
101 // to complex, and call the complex valued function. |
|
102 |
|
103 double lower_limit; |
|
104 double upper_limit; |
|
105 |
4100
|
106 // ch_map_flag has the following meanings: |
2974
|
107 // |
|
108 // 0 => this function returns a matrix of ones and zeros |
|
109 // 1 => this function returns a numeric matrix (any values) |
3523
|
110 // 2 => this function returns a std::string array |
4100
|
111 |
|
112 int ch_map_flag; |
2974
|
113 |
4100
|
114 // can_ret_cmplx_for_real is a flag that says whether this function |
|
115 // can create a complex number given a real-valued argument |
|
116 // (e.g., sqrt (-1)). |
|
117 |
|
118 bool can_ret_cmplx_for_real; |
2974
|
119 |
4645
|
120 // No copying! |
|
121 |
|
122 octave_mapper (const octave_mapper& om); |
|
123 |
|
124 octave_mapper& operator = (const octave_mapper& om); |
|
125 |
4612
|
126 DECLARE_OCTAVE_ALLOCATOR |
2974
|
127 |
4612
|
128 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2974
|
129 }; |
|
130 |
|
131 #endif |
|
132 |
|
133 /* |
|
134 ;;; Local Variables: *** |
|
135 ;;; mode: C++ *** |
|
136 ;;; End: *** |
|
137 */ |