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 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <string> |
|
31 |
|
32 #include "ov-fcn.h" |
|
33 #include "ov-typeinfo.h" |
|
34 |
|
35 class octave_value; |
|
36 class octave_value_list; |
|
37 |
|
38 // Builtin mapper functions. |
|
39 |
|
40 class |
|
41 octave_mapper : public octave_function |
|
42 { |
|
43 public: |
|
44 |
|
45 typedef int (*ch_mapper) (int); |
|
46 typedef double (*d_d_mapper) (double); |
|
47 typedef double (*d_c_mapper) (const Complex&); |
|
48 typedef Complex (*c_c_mapper) (const Complex&); |
|
49 |
|
50 octave_mapper (ch_mapper ch, d_d_mapper dd, d_c_mapper dc, |
|
51 c_c_mapper cc, double ll, double ul, int f, |
|
52 const string& nm = string (), |
|
53 const string& ds = string ()) |
|
54 : octave_function (nm, ds), ch_map_fcn (ch), d_d_map_fcn (dd), |
|
55 d_c_map_fcn (dc), c_c_map_fcn (cc), |
|
56 lower_limit (ll), upper_limit (ul), flag (f) { } |
|
57 |
|
58 ~octave_mapper (void) { } |
|
59 |
|
60 void *operator new (size_t size) |
|
61 { return allocator.alloc (size); } |
|
62 |
|
63 void operator delete (void *p, size_t size) |
|
64 { allocator.free (p, size); } |
|
65 |
|
66 octave_function *function_value (bool) { return this; } |
|
67 |
|
68 octave_value_list do_index_op (int nargout, const octave_value_list& args); |
|
69 |
|
70 int type_id (void) const { return t_id; } |
|
71 |
|
72 string type_name (void) const { return t_name; } |
|
73 |
|
74 static int static_type_id (void) { return t_id; } |
|
75 |
|
76 static void register_type (void) |
|
77 { t_id = octave_value_typeinfo::register_type (t_name); } |
|
78 |
|
79 private: |
|
80 |
|
81 octave_mapper (void); |
|
82 |
|
83 octave_mapper (const octave_mapper& m); |
|
84 |
|
85 octave_value apply (const octave_value& arg) const; |
|
86 |
|
87 // ch_map_fcn is a kluge. |
|
88 |
|
89 ch_mapper ch_map_fcn; |
|
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 |
|
102 // For ch_map_fcn, flag has the following meanings: |
|
103 // |
|
104 // 0 => this function returns a matrix of ones and zeros |
|
105 // 1 => this function returns a numeric matrix (any values) |
|
106 // 2 => this function returns a string array |
|
107 // |
|
108 // For other mappers, nonzero means that this function can return a |
|
109 // complex value for some real arguments. |
|
110 |
|
111 int flag; |
|
112 |
|
113 // For custom memory management. |
|
114 static octave_allocator allocator; |
|
115 |
|
116 // Type id of list objects, set by register_type(). |
|
117 static int t_id; |
|
118 |
|
119 // Type name of list objects, defined in ov-list.cc. |
|
120 static const string t_name; |
|
121 }; |
|
122 |
|
123 #endif |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |