Mercurial > jwe > octave
changeset 24108:1a53f0c855db
move some duplicate code into a separate function
* ov-fcn-handle.h, ov-fcn-handle.cc
(octave_fcn_handle::parse_anon_fcn_hanlde): New function.
(octave_fcn_handle::load_ascii, octave_fcn_handle::load_binary,
octave_fcn_handle::load_hdf5): Use it to eliminate duplicate code.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 27 Sep 2017 15:56:39 -0400 |
parents | e250aeab3c85 |
children | 1d6c940a1b37 |
files | libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-fcn-handle.h |
diffstat | 2 files changed, 44 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.cc Tue Sep 26 15:18:31 2017 -0700 +++ b/libinterp/octave-value/ov-fcn-handle.cc Wed Sep 27 15:56:39 2017 -0400 @@ -385,6 +385,43 @@ } bool +octave_fcn_handle::parse_anon_fcn_handle (const std::string& fcn_text) +{ + bool success = true; + + int parse_status; + + octave_value anon_fcn_handle = + octave::eval_string (fcn_text, true, parse_status); + + if (parse_status == 0) + { + octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); + + if (fh) + { + fcn = fh->fcn; + + octave_user_function *uf = fcn.user_function_value (true); + + if (uf) + { + octave::symbol_table::scope *uf_scope = uf->scope (); + + if (uf_scope) + uf_scope->cache_name (nm); + } + } + else + success = false; + } + else + success = false; + + return success; +} + +bool octave_fcn_handle::load_ascii (std::istream& is) { bool success = true; @@ -469,36 +506,7 @@ } if (is && success) - { - int parse_status; - octave_value anon_fcn_handle = - octave::eval_string (buf, true, parse_status); - - if (parse_status == 0) - { - octave_fcn_handle *fh = - anon_fcn_handle.fcn_handle_value (); - - if (fh) - { - fcn = fh->fcn; - - octave_user_function *uf = fcn.user_function_value (true); - - if (uf) - { - octave::symbol_table::scope *uf_scope = uf->scope (); - - if (uf_scope) - uf_scope->cache_name (nm); - } - } - else - success = false; - } - else - success = false; - } + success = parse_anon_fcn_handle (buf); else success = false; } @@ -656,35 +664,9 @@ } if (is && success) - { - int parse_status; - octave_value anon_fcn_handle - = octave::eval_string (ctmp2, true, parse_status); - - if (parse_status == 0) - { - octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); - - if (fh) - { - fcn = fh->fcn; - - octave_user_function *uf = fcn.user_function_value (true); - - if (uf) - { - octave::symbol_table::scope *uf_scope = uf->scope (); - - if (uf_scope) - uf_scope->cache_name (nm); - } - } - else - success = false; - } - else - success = false; - } + success = parse_anon_fcn_handle (ctmp2); + else + success = false; } else { @@ -1191,35 +1173,7 @@ } if (success) - { - int parse_status; - octave_value anon_fcn_handle - = octave::eval_string (fcn_tmp, true, parse_status); - - if (parse_status == 0) - { - octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); - - if (fh) - { - fcn = fh->fcn; - - octave_user_function *uf = fcn.user_function_value (true); - - if (uf) - { - octave::symbol_table::scope *uf_scope = uf->scope (); - - if (uf_scope) - uf_scope->cache_name (nm); - } - } - else - success = false; - } - else - success = false; - } + success = parse_anon_fcn_handle (fcn_tmp); frame.run (); }
--- a/libinterp/octave-value/ov-fcn-handle.h Tue Sep 26 15:18:31 2017 -0700 +++ b/libinterp/octave-value/ov-fcn-handle.h Wed Sep 27 15:56:39 2017 -0400 @@ -174,6 +174,8 @@ // Overloads for other classes. str_ov_map overloads; + bool parse_anon_fcn_handle (const std::string& fcn_text); + virtual octave_value_list call (int nargout, const octave_value_list& args); friend octave_value make_fcn_handle (const std::string &, bool);