changeset 4640:2d237a76dbdd

[project @ 2003-11-22 11:24:44 by jwe]
author jwe
date Sat, 22 Nov 2003 11:24:44 +0000
parents f70c9e90ac2d
children 7604168d3e2a
files src/ov-typeinfo.cc src/ov-typeinfo.h src/ov.h
diffstat 3 files changed, 48 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ov-typeinfo.cc	Sat Nov 22 04:25:29 2003 +0000
+++ b/src/ov-typeinfo.cc	Sat Nov 22 11:24:44 2003 +0000
@@ -82,10 +82,11 @@
 
 int
 octave_value_typeinfo::register_type (const std::string& t_name,
-				      const std::string& c_name)
+				      const std::string& c_name,
+				      const octave_value& val)
 {
   return (instance_ok ())
-    ? instance->do_register_type (t_name, c_name) : -1;
+    ? instance->do_register_type (t_name, c_name, val) : -1;
 }
 
 bool
@@ -149,7 +150,8 @@
 
 int
 octave_value_typeinfo::do_register_type (const std::string& t_name,
-					 const std::string& c_name)
+					 const std::string& c_name,
+					 const octave_value& val)
 {
   int i = 0;
 
@@ -165,6 +167,8 @@
 
       types.resize (len, std::string ());
 
+      vals.resize (len, octave_value ());
+
       unary_ops.resize (static_cast<int> (octave_value::num_unary_ops),
 			len, static_cast<unary_op_fcn> (0));
 
@@ -188,6 +192,8 @@
 
   types (i) = t_name;
 
+  vals (i) = val;
+
   num_types++;
 
   return i;
@@ -323,6 +329,23 @@
   return false;
 }
 
+octave_value
+octave_value_typeinfo::do_lookup_type (const std::string& nm)
+{
+  octave_value retval;
+
+  for (int i = 0; i < num_types; i++)
+    {
+      if (nm == types(i))
+	{
+	  retval = vals(i);
+	  break;
+	}
+    }
+
+  return retval;
+}
+
 unary_op_fcn
 octave_value_typeinfo::do_lookup_unary_op (octave_value::unary_op op, int t)
 {
--- a/src/ov-typeinfo.h	Sat Nov 22 04:25:29 2003 +0000
+++ b/src/ov-typeinfo.h	Sat Nov 22 11:24:44 2003 +0000
@@ -44,7 +44,8 @@
 
   static bool instance_ok (void);
 
-  static int register_type (const std::string&, const std::string&);
+  static int register_type (const std::string&, const std::string&,
+			    const octave_value&);
 
   static bool register_unary_op (octave_value::unary_op, int, unary_op_fcn);
 
@@ -64,6 +65,12 @@
 
   static bool register_widening_op (int, int, type_conv_fcn);
 
+  static octave_value
+  lookup_type (const std::string& nm)
+  {
+    return instance->do_lookup_type (nm);
+  }
+
   static unary_op_fcn
   lookup_unary_op (octave_value::unary_op op, int t)
   {
@@ -138,6 +145,8 @@
 
   Array<std::string> types;
 
+  Array<octave_value> vals;
+
   Array2<unary_op_fcn> unary_ops;
 
   Array2<non_const_unary_op_fcn> non_const_unary_ops;
@@ -152,7 +161,8 @@
 
   Array2<type_conv_fcn> widening_ops;
 
-  int do_register_type (const std::string&, const std::string&);
+  int do_register_type (const std::string&, const std::string&,
+			const octave_value&);
 
   bool do_register_unary_op (octave_value::unary_op, int, unary_op_fcn);
 
@@ -172,6 +182,8 @@
 
   bool do_register_widening_op (int, int, type_conv_fcn);
 
+  octave_value do_lookup_type (const std::string& nm);
+
   unary_op_fcn do_lookup_unary_op (octave_value::unary_op, int);
 
   non_const_unary_op_fcn do_lookup_non_const_unary_op
--- a/src/ov.h	Sat Nov 22 04:25:29 2003 +0000
+++ b/src/ov.h	Sat Nov 22 11:24:44 2003 +0000
@@ -756,8 +756,7 @@
     std::string type_name (void) const { return t_name; } \
     std::string class_name (void) const { return c_name; } \
     static int static_type_id (void) { return t_id; } \
-    static void register_type (void) \
-      { t_id = octave_value_typeinfo::register_type (t_name, c_name); } \
+    static void register_type (void); \
  \
   private: \
     static int t_id; \
@@ -767,7 +766,13 @@
 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \
   int t::t_id (-1); \
   const std::string t::t_name (n); \
-  const std::string t::c_name (c)
+  const std::string t::c_name (c); \
+  void t::register_type (void) \
+    { \
+      t_id = octave_value_typeinfo::register_type (t::t_name, \
+						   t::c_name, \
+						   octave_value (new t)); \
+    }
 
 // If TRUE, print a warning for assignments like
 //