octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: restructuring load-save


From: David Bateman
Subject: Re: restructuring load-save
Date: Sat, 22 Nov 2003 09:57:44 +0100
User-agent: Mutt/1.3.28i

I'd thought there might already be a way to do it. I presume this change isn't
in the CVS as it would require lots of changes else. I'll deal with the other
chnages at the same type, though this also mean some changes in octave-forge..

D.

Daprès John W. Eaton <address@hidden> (le 22/11/2003):
> On 22-Nov-2003, David Bateman <address@hidden> wrote:
> 
> | However, for the load functions I've run into a problem of what is the best
> | way to convert from a string of the type name to an octave_value. I thought
> | I could use octave_value_typeinfo class, something like
> | 
> | octave_value
> | octave_value_typeinfo::lookup_type (const std::string &nm)
> | {
> |   for (int i = 0;i < num_types; i++)
> |     if (nm == types(i))
> |       {
> |     // FIXME: How do I initialize an octave_value of the right type?
> |     return octave_value();
> |       }
> | 
> |   return octave_value();
> | }
> | 
> | I can use this to get the static_type_id of the type, but don't see an 
> | obvious way of converting that to an octave_value. Does anyone have a
> | clue?
> 
> I think we have to invent something.  It looks like a reasonable thing
> to do would be to make the static function register_type that is
> defined for each octave_value type also pass an object of the type it
> is registering.  Then octave_value_typeinfo can cache that value and
> return it in a function like you have above.  I think the following
> change should do it (I haven't tested it completely, but I think it
> should do what you want).
> 
> jwe
> 
> 
> Index: ov.h
> ===================================================================
> RCS file: /usr/local/cvsroot/octave/src/ov.h,v
> retrieving revision 1.90
> diff -u -r1.90 ov.h
> --- ov.h      14 Nov 2003 19:49:56 -0000      1.90
> +++ ov.h      22 Nov 2003 03:59:41 -0000
> @@ -767,7 +774,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
>  //
> Index: ov-typeinfo.h
> ===================================================================
> RCS file: /usr/local/cvsroot/octave/src/ov-typeinfo.h,v
> retrieving revision 1.14
> diff -u -r1.14 ov-typeinfo.h
> --- ov-typeinfo.h     14 Nov 2003 19:49:56 -0000      1.14
> +++ ov-typeinfo.h     22 Nov 2003 03:59:41 -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
> Index: ov-typeinfo.cc
> ===================================================================
> RCS file: /usr/local/cvsroot/octave/src/ov-typeinfo.cc,v
> retrieving revision 1.26
> diff -u -r1.26 ov-typeinfo.cc
> --- ov-typeinfo.cc    15 Nov 2003 12:51:20 -0000      1.26
> +++ ov-typeinfo.cc    22 Nov 2003 03:59:41 -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)
>  {
> 
> 
> 

-- 
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]