Mercurial > hg > octave-lyh
view examples/structdemo.cc @ 17213:334d8edd48bc
lo-regexp.cc: prevent cast of negative floating point value to size_t.
* regexp.cc: simplify two expressions like "static_cast<size_t> (e - 1) + 1"
to "static_cast<size_t> (e), where 'e' is a nonnegative index value of type
double. This prevents a cast of -1.0 to the unsigned integral type "size_t"
whenever 'e' is zero. A test case where this occurs (for the second change) is
regexprep ('World', '^', 'Hello ', 'emptymatch').
author | Philipp Kutin <philipp.kutin@gmail.com> |
---|---|
date | Thu, 08 Aug 2013 10:58:37 +0200 |
parents | be41c30bcb44 |
children |
line wrap: on
line source
#include <octave/oct.h> #include <octave/ov-struct.h> DEFUN_DLD (structdemo, args, , "Struct Demo") { octave_value retval; int nargin = args.length (); if (args.length () == 2) { octave_scalar_map arg0 = args(0).scalar_map_value (); //octave_map arg0 = args(0).map_value (); if (! error_state) { std::string arg1 = args(1).string_value (); if (! error_state) { octave_value tmp = arg0.contents (arg1); //octave_value tmp = arg0.contents (arg1)(0); if (tmp.is_defined ()) { octave_scalar_map st; st.assign ("selected", tmp); retval = octave_value (st); } else error ("structdemo: struct does not have a field named '%s'\n", arg1.c_str ()); } else error ("structdemo: ARG2 must be a character string"); } else error ("structdemo: ARG1 must be a struct"); } else print_usage (); return retval; }