diff libinterp/corefcn/time.cc @ 20704:571508c1ed06

eliminate more uses of error_state * ov.h, ov.cc (octave_value::xall_strings): New extractor. * bitfcns.cc, data.cc, ellipj.cc, fftn.cc, file-io.cc, filter.cc, find.cc, graphics.cc, input.cc, load-path.cc, luinc.cc, matrix_type.cc, oct-stream.cc, ordschur.cc, psi.cc, rand.cc, spparms.cc, strfns.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, utils.cc, variables.cc, __glpk__.cc, __magick_read__.cc, amd.cc, ov-cell.cc, ov-fcn-inline.cc, ov-struct.cc: Eliminate more uses of error_state. * system.tst: Update tests.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Nov 2015 15:18:05 -0500
parents 68e3a747ca02
children d903cccb8de8
line wrap: on
line diff
--- a/libinterp/corefcn/time.cc	Sat Nov 14 12:07:38 2015 -0500
+++ b/libinterp/corefcn/time.cc	Sat Nov 14 15:18:05 2015 -0500
@@ -57,48 +57,48 @@
 }
 
 static inline int
-intfield (const octave_scalar_map& m, const std::string& k)
+intfield (const octave_scalar_map& m, const std::string& k, const char *who)
 {
   int retval = 0;
 
   octave_value v = m.getfield (k);
 
   if (! v.is_empty ())
-    retval = v.int_value ();
+    retval = v.xint_value ("%s: invalid TM_STRUCT argument", who);
 
   return retval;
 }
 
 static inline std::string
-stringfield (const octave_scalar_map& m, const std::string& k)
+stringfield (const octave_scalar_map& m, const std::string& k, const char *who)
 {
   std::string retval;
 
   octave_value v = m.getfield (k);
 
   if (! v.is_empty ())
-    retval = v.string_value ();
+    retval = v.xstring_value ("%s: invalid TM_STRUCT argument", who);
 
   return retval;
 }
 
 static octave_base_tm
-extract_tm (const octave_scalar_map& m)
+extract_tm (const octave_scalar_map& m, const char *who)
 {
   octave_base_tm tm;
 
-  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.gmtoff (intfield (m, "gmtoff"));
-  tm.zone (stringfield (m, "zone"));
+  tm.usec (intfield (m, "usec", who));
+  tm.sec (intfield (m, "sec", who));
+  tm.min (intfield (m, "min", who));
+  tm.hour (intfield (m, "hour", who));
+  tm.mday (intfield (m, "mday", who));
+  tm.mon (intfield (m, "mon", who));
+  tm.year (intfield (m, "year", who));
+  tm.wday (intfield (m, "wday", who));
+  tm.yday (intfield (m, "yday", who));
+  tm.isdst (intfield (m, "isdst", who));
+  tm.gmtoff (intfield (m, "gmtoff", who));
+  tm.zone (stringfield (m, "zone", who));
 
   return tm;
 }
@@ -275,19 +275,11 @@
 
   if (args.length () == 1)
     {
-      octave_scalar_map map = args(0).scalar_map_value ();
-
-      if (! error_state)
-        {
-          octave_base_tm tm = extract_tm (map);
+      octave_scalar_map map = args(0).xscalar_map_value ("mktime: TM_STRUCT argument must be a structure");
 
-          if (! error_state)
-            retval = octave_time (tm);
-          else
-            error ("mktime: invalid TM_STRUCT argument");
-        }
-      else
-        error ("mktime: TM_STRUCT argument must be a structure");
+      octave_base_tm tm = extract_tm (map, "mktime");
+
+      retval = octave_time (tm);
     }
   else
     print_usage ();
@@ -475,19 +467,11 @@
     {
       std::string fmt = args(0).xstring_value ("strftime: FMT must be a string");
 
-      octave_scalar_map map = args(1).scalar_map_value ();
-
-      if (! error_state)
-        {
-          octave_base_tm tm = extract_tm (map);
+      octave_scalar_map map = args(1).xscalar_map_value ("strftime: TM_STRUCT must be a structure");
 
-          if (! error_state)
-            retval = tm.strftime (fmt);
-          else
-            error ("strftime: invalid TM_STRUCT argument");
-        }
-      else
-        error ("strftime: TM_STRUCT must be a structure");
+      octave_base_tm tm = extract_tm (map, "strftime");
+
+      retval = tm.strftime (fmt);
     }
   else
     print_usage ();