changeset 5156:7c3b22bafedc

[project @ 2005-02-22 17:42:15 by jwe]
author jwe
date Tue, 22 Feb 2005 17:42:16 +0000
parents ee50a5f1e541
children 8ca032643f55
files src/ChangeLog src/DLD-FUNCTIONS/time.cc src/oct-map.cc src/oct-map.h src/ov-mapper.cc
diffstat 5 files changed, 65 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Feb 21 21:39:24 2005 +0000
+++ b/src/ChangeLog	Tue Feb 22 17:42:16 2005 +0000
@@ -1,3 +1,18 @@
+2005-02-22  John W. Eaton  <jwe@octave.org>
+
+	* ov-mapper.cc (octave_mapper::subsref): Return retval after
+	calling next_subsref.
+
+	* ov-mapper.cc (octave_builtin::subsref): If nargout is 0 and we
+	have additional indexing to perform, set it to 1 before calling
+	do_multi_index_op.
+
+	* oct-map.cc (Octave_map::intfield, Octave_map::stringfield):
+	New functions.
+	* oct-map.h: Provide decls.
+	* DLD-FUNCTIONS/time.cc (extract_tm): Use intfield and stringfield
+	to access map elements.
+
 2005-02-21  John W. Eaton  <jwe@octave.org>
 
 	* ov-builtin.cc (octave_builtin::subsref): If nargout is 0 and we
--- a/src/DLD-FUNCTIONS/time.cc	Mon Feb 21 21:39:24 2005 +0000
+++ b/src/DLD-FUNCTIONS/time.cc	Tue Feb 22 17:42:16 2005 +0000
@@ -60,17 +60,17 @@
 {
   octave_base_tm tm;
 
-  tm.usec (m.contents ("usec")(0) . int_value ());
-  tm.sec (m.contents ("sec")(0) . int_value ());
-  tm.min (m.contents ("min")(0) . int_value ());
-  tm.hour (m.contents ("hour")(0) . int_value ());
-  tm.mday (m.contents ("mday")(0) . int_value ());
-  tm.mon (m.contents ("mon")(0) . int_value ());
-  tm.year (m.contents ("year")(0) . int_value ());
-  tm.wday (m.contents ("wday")(0) . int_value ());
-  tm.yday (m.contents ("yday")(0) . int_value ());
-  tm.isdst (m.contents ("isdst")(0) . int_value ());
-  tm.zone (m.contents ("zone")(0) . string_value ());
+  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"));
 
   return tm;
 }
--- a/src/oct-map.cc	Mon Feb 21 21:39:24 2005 +0000
+++ b/src/oct-map.cc	Tue Feb 22 17:42:16 2005 +0000
@@ -38,6 +38,33 @@
   return p != end () ? p->second : Cell ();
 }
 
+int
+Octave_map::intfield (const std::string& k, int def_val) const
+{
+  int retval = def_val;
+
+  Cell c = contents (k);
+
+  if (! c.is_empty ())
+    retval = c(0).int_value ();
+
+  return retval;
+}
+
+std::string
+Octave_map::stringfield (const std::string& k,
+			 const std::string& def_val) const
+{
+  std::string retval = def_val;
+
+  Cell c = contents (k);
+
+  if (! c.is_empty ())
+    retval = c(0).string_value ();
+
+  return retval;
+}
+
 string_vector
 Octave_map::keys (void) const
 {
--- a/src/oct-map.h	Mon Feb 21 21:39:24 2005 +0000
+++ b/src/oct-map.h	Tue Feb 22 17:42:16 2005 +0000
@@ -95,6 +95,11 @@
   Cell contents (const_iterator p) const
     { return contents (key(p)); }
 
+  int intfield (const std::string& k, int def_val = 0) const;
+
+  std::string stringfield (const std::string& k,
+			   const std::string& def_val = std::string ()) const;
+
   const_iterator seek (const std::string& k) const { return map.find (k); }
 
   bool contains (const std::string& k) const
--- a/src/ov-mapper.cc	Mon Feb 21 21:39:24 2005 +0000
+++ b/src/ov-mapper.cc	Tue Feb 22 17:42:16 2005 +0000
@@ -246,7 +246,11 @@
   switch (type[0])
     {
     case '(':
-      retval = do_multi_index_op (nargout, idx.front ());
+      {
+	int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
+
+	retval = do_multi_index_op (tmp_nargout, idx.front ());
+      }
       break;
 
     case '{':
@@ -261,14 +265,14 @@
       panic_impossible ();
     }
 
-  return retval;
-
   // XXX FIXME XXX -- perhaps there should be an
   // octave_value_list::next_subsref member function?  See also
   // and octave_builtin::subsref.
 
   if (idx.size () > 1)
     retval = retval(0).next_subsref (nargout, type, idx);
+
+  return retval;
 }
 
 octave_value_list