Mercurial > octave
changeset 28642:0237b10e3943
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 19 Aug 2020 23:45:18 -0400 |
parents | 2c15231c3154 |
children | a2cb3dec4bc5 |
files | libinterp/octave-value/ov-base.h |
diffstat | 1 files changed, 28 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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<type>::register_type (void); \ + template <> void cls<type>::register_type (octave::type_info&); \ + template <> int cls<type>::t_id; \ + template <> const std::string cls<type>::t_name; \ + template <> const std::string cls<type>::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