# HG changeset patch # User jwe # Date 1069500284 0 # Node ID 2d237a76dbdd090368b2652868fc05068fb6c2e5 # Parent f70c9e90ac2df9fd9c64829b64f2bce94bd1e53a [project @ 2003-11-22 11:24:44 by jwe] diff --git a/src/ov-typeinfo.cc b/src/ov-typeinfo.cc --- a/src/ov-typeinfo.cc +++ b/src/ov-typeinfo.cc @@ -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 (octave_value::num_unary_ops), len, static_cast (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) { diff --git a/src/ov-typeinfo.h b/src/ov-typeinfo.h --- a/src/ov-typeinfo.h +++ b/src/ov-typeinfo.h @@ -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 types; + Array vals; + Array2 unary_ops; Array2 non_const_unary_ops; @@ -152,7 +161,8 @@ Array2 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 diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -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 //