Mercurial > hg > octave-avbm
changeset 10261:a4fb4675accb
make printing of handles more Matlab-compatible
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 03 Feb 2010 13:35:41 +0100 |
parents | 14d5fee02b3b |
children | 2b05f4aff27c |
files | src/ChangeLog src/ov-fcn-handle.cc src/ov-fcn-handle.h src/pt-fcn-handle.cc |
diffstat | 4 files changed, 34 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-02-03 Jaroslav Hajek <highegg@gmail.com> + + * ov-fcn-handle.h (octave_fcn_handle::anonymous): New static field. + * ov-fcn-handle.cc (octave_fcn_handle::anonymous): Initialize it. + Use everywhere instead of hardwired string. + (octave_fcn_handle::print_raw): Print named function handle with + starting @. + * pt-fcn-handle.cc: Use octave_fcn_handle::anonymous rather than + hardcoded string. + 2010-02-03 Jaroslav Hajek <highegg@gmail.com> * OPERATORS/op-fcn.cc: New source.
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -68,13 +68,15 @@ "function handle", "function_handle"); +const std::string octave_fcn_handle::anonymous ("@<anonymous>"); + octave_fcn_handle::octave_fcn_handle (const octave_value& f, const std::string& n) : fcn (f), nm (n) { octave_user_function *uf = fcn.user_function_value (true); - if (uf) + if (uf && nm != anonymous) symbol_table::cache_name (uf->scope (), nm); } @@ -284,7 +286,7 @@ bool octave_fcn_handle::save_ascii (std::ostream& os) { - if (nm == "@<anonymous>") + if (nm == anonymous) { os << nm << "\n"; @@ -349,7 +351,7 @@ is >> nm; - if (nm == "@<anonymous>") + if (nm == anonymous) { skip_preceeding_newline (is); @@ -447,7 +449,7 @@ bool octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) { - if (nm == "@<anonymous>") + if (nm == anonymous) { std::ostringstream nmbuf; @@ -526,15 +528,17 @@ if (! is) return false; - if (nm.length() >= 12 && nm.substr (0, 12) == "@<anonymous>") + size_t anl = anonymous.length (); + + if (nm.length() >= anl && nm.substr (0, anl) == anonymous) { octave_idx_type len = 0; - if (nm.length() > 12) + if (nm.length() > anl) { - std::istringstream nm_is (nm.substr(12)); + std::istringstream nm_is (nm.substr (anl)); nm_is >> len; - nm = nm.substr(0,12); + nm = nm.substr (0, anl); } if (! is.read (reinterpret_cast<char *> (&tmp), 4)) @@ -679,7 +683,7 @@ } H5Dclose (data_hid); - if (nm == "@<anonymous>") + if (nm == anonymous) { std::ostringstream buf; print_raw (buf, true); @@ -934,7 +938,7 @@ H5Dclose (data_hid); nm = nm_tmp; - if (nm == "@<anonymous>") + if (nm == anonymous) { #if HAVE_HDF5_18 data_hid = H5Dopen (group_hid, "fcn", H5P_DEFAULT); @@ -1264,7 +1268,7 @@ { bool printed = false; - if (nm == "@<anonymous>") + if (nm == anonymous) { tree_print_code tpc (os); @@ -1319,7 +1323,7 @@ } if (! printed) - octave_print_internal (os, nm, pr_as_read_syntax, + octave_print_internal (os, "@" + nm, pr_as_read_syntax, current_print_indent_level ()); } @@ -1563,7 +1567,7 @@ std::string fh_nm = fh->fcn_name (); - if (fh_nm == "@<anonymous>") + if (fh_nm == octave_fcn_handle::anonymous) { std::ostringstream buf; fh->print_raw (buf); @@ -1593,7 +1597,7 @@ std::string nm = fcn->fcn_file_name (); - if (fh_nm == "@<anonymous>") + if (fh_nm == octave_fcn_handle::anonymous) { m.assign ("file", nm); @@ -1655,7 +1659,7 @@ { std::string fh_nm = fh->fcn_name (); - if (fh_nm == "@<anonymous>") + if (fh_nm == octave_fcn_handle::anonymous) { std::ostringstream buf;
--- a/src/ov-fcn-handle.h +++ b/src/ov-fcn-handle.h @@ -49,13 +49,16 @@ : fcn (f), nm (n), disp (sdisp) { } public: + + static const std::string anonymous; + octave_fcn_handle (void) : fcn (), nm () { } octave_fcn_handle (const std::string& n) : fcn (), nm (n) { } - octave_fcn_handle (const octave_value& f, const std::string& n); + octave_fcn_handle (const octave_value& f, const std::string& n = anonymous); octave_fcn_handle (const octave_fcn_handle& fh) : octave_base_value (fh), fcn (fh.fcn), nm (fh.nm)