GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
__dispatch__.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2001-2017 John W. Eaton and Paul Kienzle
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <list>
28 #include <map>
29 #include <string>
30 
31 #include "Cell.h"
32 #include "oct-map.h"
33 #include "defun.h"
34 #include "ov.h"
35 #include "ov-fcn.h"
36 #include "ov-typeinfo.h"
37 #include "pager.h"
38 #include "parse.h"
39 #include "symtab.h"
40 #include "variables.h"
41 
42 DEFUN (__dispatch__, args, nargout,
43  doc: /* -*- texinfo -*-
44 @deftypefn {} {} __dispatch__ ()
45 Undocumented internal function.
46 @end deftypefn */)
47 {
48  int nargin = args.length ();
49 
50  if (nargin < 1 || nargin > 3)
51  print_usage ();
52 
53  std::string f, r, t;
54 
55  f = args(0).xstring_value ("__dispatch__: first argument must be a function name");
56 
57  if (nargin > 1)
58  r = args(1).xstring_value ("__dispatch__: second argument must be a function name");
59 
60  if (nargin > 2)
61  t = args(2).xstring_value ("__dispatch__: third argument must be a type name");
62 
64 
65  if (nargin == 1)
66  {
67  if (nargout > 0)
68  {
71 
72  size_t len = dm.size ();
73 
74  Cell type_field (len, 1);
75  Cell name_field (len, 1);
76 
77  symbol_table::fcn_info::dispatch_map_type::const_iterator p
78  = dm.begin ();
79 
80  for (size_t i = 0; i < len; i++)
81  {
82  type_field(i) = p->first;
83  name_field(i) = p->second;
84 
85  p++;
86  }
87 
89 
90  m.assign ("type", type_field);
91  m.assign ("name", name_field);
92 
93  retval = m;
94  }
95  else
97  }
98  else if (nargin == 2)
99  {
100  t = r;
102  }
103  else
104  symbol_table::add_dispatch (f, t, r);
105 
106  return retval;
107 }
108 
109 /*
110 ## No test needed for internal helper function.
111 %!assert (1)
112 */
Definition: Cell.h:37
static void clear_dispatch(const std::string &name, const std::string &type)
Definition: symtab.h:1869
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
JNIEnv void * args
Definition: ov-java.cc:67
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
int nargin
Definition: graphics.cc:10115
static void add_dispatch(const std::string &name, const std::string &type, const std::string &fname)
Definition: symtab.h:1848
octave_value retval
Definition: data.cc:6294
static fcn_info::dispatch_map_type get_dispatch(const std::string &name)
Definition: symtab.h:1893
std::map< std::string, std::string > dispatch_map_type
Definition: symtab.h:736
#define octave_stdout
Definition: pager.h:146
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
p
Definition: lu.cc:138
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:223
static void print_dispatch(std::ostream &os, const std::string &name)
Definition: symtab.h:1881
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854