GNU Octave  8.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-2023 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 
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  // No copying!
86 
87  octave_builtin (const octave_builtin& ob) = delete;
88 
90 
91  ~octave_builtin (void) = default;
92 
93  std::string src_file_name (void) const { return m_file; }
94 
95  octave_function * function_value (bool = false) { return this; }
96 
97  bool is_builtin_function (void) const { return true; }
98 
100  execute (octave::tree_evaluator& tw, int nargout = 0,
101  const octave_value_list& args = octave_value_list ());
102 
103  fcn function (void) const;
104 
105  meth method (void) const;
106 
107  void push_dispatch_class (const std::string& dispatch_type);
108 
109  bool handles_dispatch_class (const std::string& dispatch_type) const;
110 
111 protected:
112 
113  // A pointer to the actual function.
114  fcn m_fcn;
115  meth m_meth;
116 
117  // The name of the file where this function was defined.
118  std::string m_file;
119 
120  // The types this function has been declared to handle (if any).
121  std::set<std::string> m_dispatch_classes;
122 
123 private:
124 
126 };
127 
128 #endif
OCTAVE_END_NAMESPACE(octave)
int execute(void)
Definition: interpreter.cc:841
interpreter & operator=(const interpreter &)=delete
octave_builtin(fcn ff, const std::string &nm="", const std::string &ds="")
Definition: ov-builtin.h:65
octave_builtin(const octave_builtin &ob)=delete
std::set< std::string > m_dispatch_classes
Definition: ov-builtin.h:121
octave_function * function_value(bool=false)
Definition: ov-builtin.h:95
std::string src_file_name(void) 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
octave_builtin(meth mm, const std::string &nm="", const std::string &ds="")
Definition: ov-builtin.h:70
~octave_builtin(void)=default
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:118
bool is_builtin_function(void) const
Definition: ov-builtin.h:97
octave_builtin(void)
Definition: ov-builtin.h:56
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:181