__dispatch__.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2001-2012 John W. Eaton and Paul Kienzle
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <list>
00028 #include <map>
00029 #include <string>
00030 
00031 #include "Cell.h"
00032 #include "oct-map.h"
00033 #include "defun-dld.h"
00034 #include "ov.h"
00035 #include "ov-fcn.h"
00036 #include "ov-typeinfo.h"
00037 #include "pager.h"
00038 #include "parse.h"
00039 #include "symtab.h"
00040 #include "variables.h"
00041 
00042 DEFUN_DLD (__dispatch__, args, nargout,
00043   "Undocumented internal function")
00044 {
00045   octave_value retval;
00046 
00047   int nargin = args.length ();
00048 
00049   std::string f, r, t;
00050 
00051   if (nargin > 0 && nargin < 4)
00052     {
00053       if (nargin > 0)
00054         {
00055           f = args(0).string_value ();
00056 
00057           if (error_state)
00058             {
00059               error ("__dispatch__: first argument must be a function name");
00060               return retval;
00061             }
00062         }
00063 
00064       if (nargin > 1)
00065         {
00066           r = args(1).string_value ();
00067 
00068           if (error_state)
00069             {
00070               error ("__dispatch__: second argument must be a function name");
00071               return retval;
00072             }
00073         }
00074 
00075       if (nargin > 2)
00076         {
00077           t = args(2).string_value ();
00078 
00079           if (error_state)
00080             {
00081               error ("__dispatch__: third argument must be a type name");
00082               return retval;
00083             }
00084         }
00085 
00086       if (nargin == 1)
00087         {
00088           if (nargout > 0)
00089             {
00090               symbol_table::fcn_info::dispatch_map_type dm
00091                 = symbol_table::get_dispatch (f);
00092 
00093               size_t len = dm.size ();
00094 
00095               Cell type_field (len, 1);
00096               Cell name_field (len, 1);
00097 
00098               symbol_table::fcn_info::dispatch_map_type::const_iterator p
00099                 = dm.begin ();
00100 
00101               for (size_t i = 0; i < len; i++)
00102                 {
00103                   type_field(i) = p->first;
00104                   name_field(i) = p->second;
00105 
00106                   p++;
00107                 }
00108 
00109               octave_scalar_map m;
00110 
00111               m.assign ("type", type_field);
00112               m.assign ("name", name_field);
00113 
00114               retval = m;
00115             }
00116           else
00117             symbol_table::print_dispatch (octave_stdout, f);
00118         }
00119       else if (nargin == 2)
00120         {
00121           t = r;
00122           symbol_table::clear_dispatch (f, t);
00123         }
00124       else
00125         symbol_table::add_dispatch (f, t, r);
00126     }
00127   else
00128     print_usage ();
00129 
00130   return retval;
00131 }
00132 
00133 /*
00134 
00135 ## No test needed for internal helper function.
00136 %!assert (1)
00137 
00138 */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines