# HG changeset patch # User John W. Eaton # Date 1597895118 14400 # Node ID 0237b10e3943350874dcfee508201dba0c28aabc # Parent 2c15231c31547923bde08fc095cad888f3a57f90 allow template types in OV_TYPEID macros * ov-base.h (DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS): New macro. (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL): New macro. (DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA): NEw macros. (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA): Define using internal version of the macro. diff -r 2c15231c3154 -r 0237b10e3943 libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h Wed Aug 19 23:42:05 2020 -0400 +++ b/libinterp/octave-value/ov-base.h Wed Aug 19 23:45:18 2020 -0400 @@ -189,22 +189,35 @@ static const std::string t_name; \ static const std::string c_name; +#define DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS(cls, type) \ + template <> void cls::register_type (void); \ + template <> void cls::register_type (octave::type_info&); \ + template <> int cls::t_id; \ + template <> const std::string cls::t_name; \ + template <> const std::string cls::c_name; + +#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL(tspec, t, n, c) \ + tspec int t::t_id (-1); \ + tspec const std::string t::t_name (n); \ + tspec const std::string t::c_name (c); \ + tspec void t::register_type (void) \ + { \ + octave::type_info& type_info \ + = octave::__get_type_info__ (#t "::register_type"); \ + \ + register_type (type_info); \ + } \ + tspec void t::register_type (octave::type_info& ti) \ + { \ + octave_value v (new t ()); \ + t_id = ti.register_type (t::t_name, t::c_name, v); \ + } + +#define DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ + DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL (template <>, t, n, c) + #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); \ - void t::register_type (void) \ - { \ - octave::type_info& type_info \ - = octave::__get_type_info__ (#t "::register_type"); \ - \ - register_type (type_info); \ - } \ - void t::register_type (octave::type_info& ti) \ - { \ - octave_value v (new t ()); \ - t_id = ti.register_type (t::t_name, t::c_name, v); \ - } + DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL ( , t, n, c) // A base value type, so that derived types only have to redefine what // they need (if they are derived from octave_base_value instead of