GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-builtin.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-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_ov_builtin_h)
27 #define octave_ov_builtin_h 1
28 
29 #include "octave-config.h"
30 
31 #include <list>
32 #include <set>
33 #include <string>
34 
35 #include "ov-fcn.h"
36 #include "ov-typeinfo.h"
37 
38 class octave_value;
39 class octave_value_list;
40 
42 
43 class tree_evaluator;
44 class interpreter;
45 
46 OCTAVE_END_NAMESPACE(octave)
47 
48 // Builtin functions.
49 
50 class
51 OCTINTERP_API
53 {
54 public:
55 
57  : octave_function (), m_fcn (nullptr), m_meth (nullptr), m_file ()
58  { }
59 
60  typedef octave_value_list (*meth) (octave::interpreter&,
61  const octave_value_list&, int);
62 
63  typedef octave_value_list (*fcn) (const octave_value_list&, int);
64 
65  octave_builtin (fcn ff, const std::string& nm = "",
66  const std::string& ds = "")
67  : octave_function (nm, ds), m_fcn (ff), m_meth (nullptr), m_file ()
68  { }
69 
70  octave_builtin (meth mm, const std::string& nm = "",
71  const std::string& ds = "")
72  : octave_function (nm, ds), m_fcn (nullptr), m_meth (mm), m_file ()
73  { }
74 
75  octave_builtin (fcn ff, const std::string& nm, const std::string& fnm,
76  const std::string& ds)
77  : octave_function (nm, ds), m_fcn (ff), m_meth (nullptr), m_file (fnm)
78  { }
79 
80  octave_builtin (meth mm, const std::string& nm, const std::string& fnm,
81  const std::string& ds)
82  : octave_function (nm, ds), m_fcn (nullptr), m_meth (mm), m_file (fnm)
83  { }
84 
85  OCTAVE_DISABLE_COPY_MOVE (octave_builtin)
86 
87  ~octave_builtin () = default;
88 
89  std::string src_file_name () const { return m_file; }
90 
91  octave_function * function_value (bool = false) { return this; }
92 
93  bool is_builtin_function () const { return true; }
94 
96  execute (octave::tree_evaluator& tw, int nargout = 0,
97  const octave_value_list& args = octave_value_list ());
98 
99  fcn function () const;
100 
101  meth method () const;
102 
103  void push_dispatch_class (const std::string& dispatch_type);
104 
105  bool handles_dispatch_class (const std::string& dispatch_type) const;
106 
107 protected:
108 
109  // A pointer to the actual function.
110  fcn m_fcn;
111  meth m_meth;
112 
113  // The name of the file where this function was defined.
114  std::string m_file;
115 
116  // The types this function has been declared to handle (if any).
117  std::set<std::string> m_dispatch_classes;
118 
119 private:
120 
122 };
123 
124 #endif
octave_builtin(fcn ff, const std::string &nm="", const std::string &ds="")
Definition: ov-builtin.h:65
~octave_builtin()=default
std::set< std::string > m_dispatch_classes
Definition: ov-builtin.h:117
octave_function * function_value(bool=false)
Definition: ov-builtin.h:91
bool is_builtin_function() const
Definition: ov-builtin.h:93
octave_builtin(fcn ff, const std::string &nm, const std::string &fnm, const std::string &ds)
Definition: ov-builtin.h:75
std::string src_file_name() const
Definition: ov-builtin.h:89
octave_builtin(meth mm, const std::string &nm="", const std::string &ds="")
Definition: ov-builtin.h:70
octave_builtin(meth mm, const std::string &nm, const std::string &fnm, const std::string &ds)
Definition: ov-builtin.h:80
std::string m_file
Definition: ov-builtin.h:114
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181