changeset 11051:2204120e38d2

structdemo.cc: use octave_scalar_map instead of Octave_map
author John W. Eaton <jwe@octave.org>
date Wed, 29 Sep 2010 04:23:13 -0400
parents b1ee705aef45
children b099acf06b55
files ChangeLog examples/make_int.cc examples/structdemo.cc
diffstat 3 files changed, 33 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-29  John W. Eaton  <jwe@octave.org>
+
+	* examples/structdemo.cc (Fstructdemo): Use octave_scalar_map
+	instead of Octave_map.
+
 2010-09-29  John W. Eaton  <jwe@octave.org>
 
 	* configure.ac: Style fixes.
--- a/examples/make_int.cc
+++ b/examples/make_int.cc
@@ -25,7 +25,6 @@
 #include <octave/symtab.h>
 #include <octave/variables.h>
 
-class Octave_map;
 class octave_value_list;
 
 class tree_walker;
--- a/examples/structdemo.cc
+++ b/examples/structdemo.cc
@@ -6,33 +6,39 @@
   int nargin = args.length ();
   octave_value retval;
 
-  if (nargin != 2)
-    print_usage ();
-  else
+  if (args.length () == 2)
     {
-      Octave_map arg0 = args(0).map_value ();
-      std::string arg1 = args(1).string_value ();
+      octave_scalar_map arg0 = args(0).scalar_map_value ();
 
-      if (! error_state && arg0.contains (arg1))
+      if (! error_state)
         {
-          // The following two lines might be written as
-          //    octave_value tmp;
-          //    for (Octave_map::iterator p0 = 
-          //        arg0.begin(); 
-          //        p0 != arg0.end(); p0++ )
-          //      if (arg0.key (p0) == arg1)
-          //        {
-          //          tmp = arg0.contents (p0) (0);
-          //          break;
-          //        }
-          // though using seek is more concise.
-          Octave_map::const_iterator p1 = arg0.seek (arg1);
-          octave_value tmp =  arg0.contents(p1)(0);
-          Octave_map st;
-          st.assign ("selected", tmp);
-          retval = octave_value (st);
+          std::string arg1 = args(1).string_value ();
+
+          if (! error_state)
+            {
+              octave_value tmp = arg0.contents (arg1);
+
+              if (tmp.is_defined ())
+                {
+                  octave_scalar_map st;
+
+                  st.assign ("selected", tmp);
+
+                  retval = octave_value (st);
+                }
+              else
+                error ("sruct does not contain field named '%s'\n",
+                       arg1.c_str ());
+            }
+          else
+            error ("expecting character string as second argument");
         }
+      else
+        error ("expecting struct as first argument");
     }
+  else
+    print_usage ();
+
   return retval; 
 }