GNU Octave  3.8.0
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-2013 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 #ifdef 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  "Undocumented internal function")
44 {
45  octave_value retval;
46 
47  int nargin = args.length ();
48 
49  std::string f, r, t;
50 
51  if (nargin > 0 && nargin < 4)
52  {
53  if (nargin > 0)
54  {
55  f = args(0).string_value ();
56 
57  if (error_state)
58  {
59  error ("__dispatch__: first argument must be a function name");
60  return retval;
61  }
62  }
63 
64  if (nargin > 1)
65  {
66  r = args(1).string_value ();
67 
68  if (error_state)
69  {
70  error ("__dispatch__: second argument must be a function name");
71  return retval;
72  }
73  }
74 
75  if (nargin > 2)
76  {
77  t = args(2).string_value ();
78 
79  if (error_state)
80  {
81  error ("__dispatch__: third argument must be a type name");
82  return retval;
83  }
84  }
85 
86  if (nargin == 1)
87  {
88  if (nargout > 0)
89  {
92 
93  size_t len = dm.size ();
94 
95  Cell type_field (len, 1);
96  Cell name_field (len, 1);
97 
98  symbol_table::fcn_info::dispatch_map_type::const_iterator p
99  = dm.begin ();
100 
101  for (size_t i = 0; i < len; i++)
102  {
103  type_field(i) = p->first;
104  name_field(i) = p->second;
105 
106  p++;
107  }
108 
110 
111  m.assign ("type", type_field);
112  m.assign ("name", name_field);
113 
114  retval = m;
115  }
116  else
118  }
119  else if (nargin == 2)
120  {
121  t = r;
123  }
124  else
125  symbol_table::add_dispatch (f, t, r);
126  }
127  else
128  print_usage ();
129 
130  return retval;
131 }
132 
133 /*
134 ## No test needed for internal helper function.
135 %!assert (1)
136 */