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