changeset 10071:e42b1bbd1052

variables.cc (get_top_level_value, set_top_level_value): new functions
author John W. Eaton <jwe@octave.org>
date Thu, 07 Jan 2010 15:07:19 -0500
parents 897e62651c0a
children 0b0bf1fd1ed7
files src/ChangeLog src/symtab.h src/variables.cc src/variables.h
diffstat 4 files changed, 48 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Jan 07 08:31:41 2010 +0100
+++ b/src/ChangeLog	Thu Jan 07 15:07:19 2010 -0500
@@ -1,3 +1,13 @@
+2010-01-07  John W. Eaton  <jwe@octave.org>
+
+	* variables.cc (get_global_value): Fix function name in error message.
+	(get_top_level_value, set_top_level_value): New functions.
+	* variables.h (get_top_level_value, set_top_level_value):
+	Provide decls.
+
+	* symtab.h (symbol_table::top_level_varref,
+	symbol_table::top_level_varval): New static functions.
+
 2010-01-07  Jaroslav Hajek  <highegg@gmail.com>
 
 	* utils.cc (octave_sleep (double)): Add OCTAVE_QUIT.
--- a/src/symtab.h	Thu Jan 07 08:31:41 2010 +0100
+++ b/src/symtab.h	Thu Jan 07 15:07:19 2010 -0500
@@ -1084,6 +1084,18 @@
     return (p != global_table.end ()) ? p->second : octave_value ();
   }
 
+  static octave_value&
+  top_level_varref (const std::string& name)
+  {
+    return varref (name, top_scope (), 0);
+  }
+
+  static octave_value
+  top_level_varval (const std::string& name)
+  {
+    return varval (name, top_scope (), 0);
+  }
+
   static octave_value& persistent_varref (const std::string& name)
   {
     static octave_value foobar;
--- a/src/variables.cc	Thu Jan 07 08:31:41 2010 +0100
+++ b/src/variables.cc	Thu Jan 07 15:07:19 2010 -0500
@@ -607,7 +607,7 @@
   octave_value val = symbol_table::global_varval (nm);
 
   if (val.is_undefined () && ! silent)
-    error ("get_global_by_name: undefined symbol `%s'", nm.c_str ());
+    error ("get_global_value: undefined symbol `%s'", nm.c_str ());
 
   return val;
 }
@@ -618,6 +618,23 @@
   symbol_table::global_varref (nm) = val;
 }
 
+octave_value
+get_top_level_value (const std::string& nm, bool silent)
+{
+  octave_value val = symbol_table::top_level_varval (nm);
+
+  if (val.is_undefined () && ! silent)
+    error ("get_top_level_value: undefined symbol `%s'", nm.c_str ());
+
+  return val;
+}
+
+void
+set_top_level_value (const std::string& nm, const octave_value& val)
+{
+  symbol_table::top_level_varref (nm) = val;
+}
+
 // Variable values.
 
 octave_value
--- a/src/variables.h	Thu Jan 07 08:31:41 2010 +0100
+++ b/src/variables.h	Thu Jan 07 15:07:19 2010 -0500
@@ -78,7 +78,14 @@
 extern OCTINTERP_API octave_value
 get_global_value (const std::string& nm, bool silent = false);
 
-extern OCTINTERP_API void set_global_value (const std::string& nm, const octave_value& val);
+extern OCTINTERP_API void
+set_global_value (const std::string& nm, const octave_value& val);
+
+extern OCTINTERP_API octave_value
+get_top_level_value (const std::string& nm, bool silent = false);
+
+extern OCTINTERP_API void
+set_top_level_value (const std::string& nm, const octave_value& val);
 
 extern OCTINTERP_API octave_value
 set_internal_variable (bool& var, const octave_value_list& args,