polymorphism.h
1 //------------------------------------------------------------------------------
2 // polymorphism.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef idDB7BACD7_96AF_4A8E_9530F074031E6A19
24 #define idDB7BACD7_96AF_4A8E_9530F074031E6A19
25 
26 #define POLYMORPHIC_SETTER_DECLARE(ret, self, name, args) \
27  template<typename X> void set_##name(ret (X::*x)args) \
28  { \
29  set_##name(static_cast<ret (self::*)args>(x)); \
30  } \
31  void set_##name(ret (self::*f)args); \
32 
33 #define POLYMORPHIC_DEFINE(ret, self, name, args, callargs) \
34  void self::set_##name(ret (self::*f)args) \
35  { \
36  d->name = f; \
37  } \
38  ret self::name args \
39  { \
40  return (this->*d->name)callargs; \
41  }
42 
43 #define POLYMORPHIC_SETTER_DECLARE_CONST(ret, self, name, args) \
44  template<typename X> void set_##name(ret (X::*x)args const) \
45  { \
46  set_##name(static_cast<ret (self::*)args const>(x)); \
47  } \
48  void set_##name(ret (self::*f)args const); \
49 
50 #define POLYMORPHIC_DEFINE_CONST(ret, self, name, args, callargs) \
51  void self::set_##name(ret (self::*f)args const) \
52  { \
53  d->name = f; \
54  } \
55  ret self::name args const \
56  { \
57  return (this->*d->name)callargs; \
58  }
59 
60 #endif