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