X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finclude%2Fgrob-interface.hh;h=9c3eadb4b06b7deccf252f2cabfbe65f4cc91fa1;hb=8211950f0931c4d8a0e18ee9e436e489bd583dbd;hp=210226094503bf70fa2386e73540ff9d56496f61;hpb=4a401ca1c60f428daa242dbdd102fdb3f327ebfb;p=lilypond.git diff --git a/lily/include/grob-interface.hh b/lily/include/grob-interface.hh index 2102260945..9c3eadb4b0 100644 --- a/lily/include/grob-interface.hh +++ b/lily/include/grob-interface.hh @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2002--2011 Han-Wen Nienhuys + Copyright (C) 2002--2015 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,21 +22,13 @@ #include "lily-guile.hh" -#define DECLARE_GROB_INTERFACE() \ - static SCM interface_symbol_; \ - static bool has_interface (Grob*) - -#define ADD_INTERFACE(cl, b, c) \ - SCM cl::interface_symbol_; \ - bool cl::has_interface (Grob *me) \ - { \ - return me->internal_has_interface (interface_symbol_); \ - } \ - void cl ## _init_ifaces () \ - { \ - cl::interface_symbol_ = add_interface (#cl, b, c); \ - } \ - ADD_SCM_INIT_FUNC (cl ## ifaces, cl ## _init_ifaces); +class Grob; + +#define ADD_INTERFACE(cl, b, c) \ + Grob_interface cl ## _interface_initializer; \ + template <> char const *Grob_interface::cxx_name_ (#cl); \ + template <> char const *Grob_interface::description_ (b); \ + template <> char const *Grob_interface::variables_ (c); SCM add_interface (char const *cxx_name, char const *descr, @@ -46,5 +38,33 @@ SCM ly_add_interface (SCM, SCM, SCM); void internal_add_interface (SCM, SCM, SCM); SCM ly_all_grob_interfaces (); +template +class Grob_interface +{ +public: + Grob_interface () + { + add_scm_init_func (Grob_interface::init); + } + +private: + static void init () + { + interface_symbol_ = ::add_interface (cxx_name_, description_, variables_); + } + + template + friend bool has_interface(Grob *); + +private: + static SCM interface_symbol_; + static char const *cxx_name_; + static char const *description_; + static char const *variables_; +}; + +template +SCM Grob_interface::interface_symbol_; + #endif /* INTERFACE_HH */