GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
defun-int.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_defun_int_h)
27 #define octave_defun_int_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include "ov-builtin.h"
34 #include "ov-dld-fcn.h"
35 #include "version.h"
36 
37 class octave_value;
38 
40 
41 class interpreter;
42 
43 extern OCTINTERP_API void print_usage (void);
44 
45 extern OCTINTERP_API void print_usage (const std::string&);
46 
47 extern OCTINTERP_API void check_version (const std::string& version,
48  const std::string& fcn);
49 
50 extern OCTINTERP_API void
51 install_dld_function (octave_dld_function::fcn f, const std::string& name,
52  const dynamic_library& shl, const std::string& doc,
53  bool relative = false);
54 
55 extern OCTINTERP_API void
56 install_dld_function (octave_dld_function::meth m, const std::string& name,
57  const dynamic_library& shl, const std::string& doc,
58  bool relative = false);
59 
60 extern OCTINTERP_API void
61 install_mex_function (void *fptr, bool fmex, const std::string& name,
62  const dynamic_library& shl, bool relative = false);
63 
64 // Gets the shlib of the currently executing DLD function, if any.
65 extern OCTINTERP_API dynamic_library get_current_shlib (void);
66 
67 OCTAVE_END_NAMESPACE(octave)
68 
69 // Some of these functions are widely used, so maybe we should avoid
70 // deprecating them for now?
71 
72 inline void print_usage (void)
73 {
75 }
76 
77 inline void print_usage (const std::string& name)
78 {
79  octave::print_usage (name);
80 }
81 
82 inline void
83 check_version (const std::string& version, const std::string& fcn)
84 {
85  octave::check_version (version, fcn);
86 }
87 
88 inline void
90  const octave::dynamic_library& shl,
91  const std::string& doc, bool relative = false)
92 {
93  octave::install_dld_function (f, name, shl, doc, relative);
94 }
95 
96 inline void
98  const octave::dynamic_library& shl,
99  const std::string& doc, bool relative = false)
100 {
101  octave::install_dld_function (m, name, shl, doc, relative);
102 }
103 
104 inline void
105 install_mex_function (void *fptr, bool fmex, const std::string& name,
106  const octave::dynamic_library& shl,
107  bool relative = false)
108 {
109  octave::install_mex_function (fptr, fmex, name, shl, relative);
110 }
111 
112 // Gets the shlib of the currently executing DLD function, if any.
113 inline octave::dynamic_library get_current_shlib (void)
114 {
115  return octave::get_current_shlib ();
116 }
117 
118 #define FORWARD_DECLARE_FUNX(name) \
119  extern OCTAVE_EXPORT octave_value_list \
120  name (const octave_value_list&, int)
121 
122 #define FORWARD_DECLARE_METHODX(name) \
123  extern OCTAVE_EXPORT octave_value_list \
124  name (octave::interpreter&, const octave_value_list&, int)
125 
126 #define FORWARD_DECLARE_FUN(name) \
127  FORWARD_DECLARE_FUNX (F ## name)
128 
129 #define FORWARD_DECLARE_METHOD(name) \
130  FORWARD_DECLARE_METHODX (F ## name)
131 
132 #define DECLARE_FUNX(name, args_name, nargout_name) \
133  OCTAVE_EXPORT octave_value_list \
134  name (const octave_value_list& args_name, int nargout_name)
135 
136 #define DECLARE_METHODX(name, interp_name, args_name, nargout_name) \
137  OCTAVE_EXPORT octave_value_list \
138  name (octave::interpreter& interp_name, \
139  const octave_value_list& args_name, int nargout_name)
140 
141 #define DECLARE_FUN(name, args_name, nargout_name) \
142  DECLARE_FUNX (F ## name, args_name, nargout_name)
143 
144 #define DECLARE_METHOD(name, interp_name, args_name, nargout_name) \
145  DECLARE_METHODX (F ## name, interp_name, args_name, nargout_name)
146 
147 #define FORWARD_DECLARE_STATIC_FUNX(name) \
148  static octave_value_list \
149  name (const octave_value_list&, int)
150 
151 #define FORWARD_DECLARE_STATIC_METHODX(name) \
152  static octave_value_list \
153  name (octave::interpreter&, const octave_value_list&, int)
154 
155 #define FORWARD_DECLARE_STATIC_FUN(name) \
156  FORWARD_DECLARE_STATIC_FUNX (F ## name)
157 
158 #define FORWARD_DECLARE_STATIC_METHOD(name) \
159  FORWARD_DECLARE_STATIC_METHODX (F ## name)
160 
161 #define DECLARE_STATIC_FUNX(name, args_name, nargout_name) \
162  static octave_value_list \
163  name (const octave_value_list& args_name, int nargout_name)
164 
165 #define DECLARE_STATIC_METHODX(name, interp_name, args_name, nargout_name) \
166  static octave_value_list \
167  name (octave::interpreter& interp_name, \
168  const octave_value_list& args_name, int nargout_name)
169 
170 #define DECLARE_STATIC_FUN(name, args_name, nargout_name) \
171  DECLARE_STATIC_FUNX (F ## name, args_name, nargout_name)
172 
173 #define DECLARE_STATIC_METHOD(name, interp_name, args_name, nargout_name) \
174  DECLARE_STATIC_METHODX (F ## name, interp_name, args_name, nargout_name)
175 
176 // Define the code that will be used to insert the new function into
177 // the symbol table. We look for this name instead of the actual
178 // function so that we can easily install the doc std::string too.
179 
180 typedef bool (*octave_dld_fcn_installer) (const octave::dynamic_library&, bool relative);
181 
183  (*octave_dld_fcn_getter) (const octave::dynamic_library&, bool relative);
184 
185 #if defined (OCTAVE_SOURCE)
186 # define DEFINE_FUN_INSTALLER_FUN(name, doc) \
187  DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, "external-doc")
188 #else
189 # define DEFINE_FUN_INSTALLER_FUN(name, doc) \
190  DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc)
191 #endif
192 
193 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \
194  extern "C" \
195  OCTAVE_EXPORT \
196  octave_function * \
197  gname (const octave::dynamic_library& shl, bool relative) \
198  { \
199  check_version (OCTAVE_API_VERSION, name); \
200  \
201  octave_dld_function *fcn \
202  = octave_dld_function::create (fname, shl, name, doc); \
203  \
204  if (relative) \
205  fcn->mark_relative (); \
206  \
207  return fcn; \
208  }
209 
210 #endif
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:63
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:60
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void install_dld_function(octave_dld_function::fcn f, const std::string &name, const dynamic_library &shl, const std::string &doc, bool relative=false)
Definition: defun.cc:90
bool(* octave_dld_fcn_installer)(const octave::dynamic_library &, bool relative)
Definition: defun-int.h:180
void print_usage(void)
Definition: defun-int.h:72
void install_mex_function(void *fptr, bool fmex, const std::string &name, const dynamic_library &shl, bool relative=false)
Definition: defun.cc:124
void check_version(const std::string &version, const std::string &fcn)
Definition: defun-int.h:83
dynamic_library get_current_shlib(void)
Definition: defun-int.h:113
F77_RET_T const F77_DBLE const F77_DBLE * f
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1102
T octave_idx_type m
Definition: mx-inlines.cc:781