# HG changeset patch # User Eugenio Gianniti # Date 1403359662 -7200 # Node ID 94895618701f581eb41ff8ce0e79f892ef3610fe # Parent b07ec30369ab4faebec0ed9c11fd7b3365d2d13a Add function evaluation with coordinates inside brackets diff -r b07ec30369ab -r 94895618701f src/function.h --- a/src/function.h Sat Jun 21 15:28:07 2014 +0200 +++ b/src/function.h Sat Jun 21 16:07:42 2014 +0200 @@ -22,6 +22,7 @@ #include #include #include +#include class function : public octave_base_value { @@ -35,6 +36,13 @@ boost::shared_ptr _fun) : octave_base_value (), str(_str), fun (_fun) {} + function (function const& _func) + : octave_base_value () + { + str = _func.get_str (); + fun = _func.get_pfun (); + } + void print (std::ostream& os, bool pr_as_read_syntax = false) const @@ -65,6 +73,48 @@ get_str (void) const { return str; } + octave_value + subsref (const std::string& type, + const std::list& idx) + { + octave_value retval; + + switch (type[0]) + { + case '(': + { + std::list args; + args.push_back (octave_value (new function (*this))); + args.push_back (idx.front ()); + retval = feval ("feval", args); + } + break; + + case '{': + case '.': + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } + break; + + default: + panic_impossible (); + } + + return retval; + } + + octave_value_list + subsref (const std::string& type, + const std::list& idx, + int) + { + octave_value_list retval; + retval = subsref (type, idx); + return retval; + } + private: std::string str;