Mercurial > hg > octave-terminal
changeset 11042:f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 29 Sep 2010 03:09:19 -0400 |
parents | 696829b6445b |
children | e9966851619b |
files | src/ChangeLog src/DLD-FUNCTIONS/time.cc |
diffstat | 2 files changed, 50 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2010-09-29 John W. Eaton <jwe@octave.org> + + * DLD-FUNCTIONS/time.cc (intfield, stringfield): New functions. + (mk_tm_map, extract_tm): Arg is now octave_scalar_map instead of + Octave_map. + (extract_tm): Use local intfield and setfield functions. + (Fmktime, Fstrftime): Use octave_scalar_map instead of Octave_map. + 2010-09-28 John W. Eaton <jwe@octave.org> * Cell.h, Cell.cc (Cell::Cell (const std::list<std::string>&)):
--- a/src/DLD-FUNCTIONS/time.cc +++ b/src/DLD-FUNCTIONS/time.cc @@ -36,10 +36,10 @@ // Date and time functions. -static Octave_map +static octave_scalar_map mk_tm_map (const octave_base_tm& t) { - Octave_map m; + octave_scalar_map m; m.assign ("usec", static_cast<double> (t.usec ())); m.assign ("sec", static_cast<double> (t.sec ())); @@ -56,22 +56,48 @@ return m; } +static inline int +intfield (const octave_scalar_map& m, const std::string& k) +{ + int retval = 0; + + octave_value v = m.getfield (k); + + if (! v.is_empty ()) + retval = v.int_value (); + + return retval; +} + +static inline std::string +stringfield (const octave_scalar_map& m, const std::string& k) +{ + std::string retval; + + octave_value v = m.getfield (k); + + if (! v.is_empty ()) + retval = v.string_value (); + + return retval; +} + static octave_base_tm -extract_tm (Octave_map &m) +extract_tm (const octave_scalar_map& m) { octave_base_tm tm; - tm.usec (m.intfield ("usec")); - tm.sec (m.intfield ("sec")); - tm.min (m.intfield ("min")); - tm.hour (m.intfield ("hour")); - tm.mday (m.intfield ("mday")); - tm.mon (m.intfield ("mon")); - tm.year (m.intfield ("year")); - tm.wday (m.intfield ("wday")); - tm.yday (m.intfield ("yday")); - tm.isdst (m.intfield ("isdst")); - tm.zone (m.stringfield ("zone")); + tm.usec (intfield (m, "usec")); + tm.sec (intfield (m, "sec")); + tm.min (intfield (m, "min")); + tm.hour (intfield (m, "hour")); + tm.mday (intfield (m, "mday")); + tm.mon (intfield (m, "mon")); + tm.year (intfield (m, "year")); + tm.wday (intfield (m, "wday")); + tm.yday (intfield (m, "yday")); + tm.isdst (intfield (m, "isdst")); + tm.zone (stringfield (m, "zone")); return tm; } @@ -249,7 +275,7 @@ if (args.length () == 1) { - Octave_map map = args(0).map_value (); + octave_scalar_map map = args(0).scalar_map_value (); if (! error_state) { @@ -448,7 +474,7 @@ if (! error_state) { - Octave_map map = args(1).map_value (); + octave_scalar_map map = args(1).scalar_map_value (); if (! error_state) {