Panda3D
extension.h
1 // Filename: extension.h
2 // Created by: rdb (11Sep13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EXTENSION_H
16 #define EXTENSION_H
17 
18 #include "dtoolbase.h"
19 
20 ///////////////////////////////////////////////////////////////////
21 // Class : ExtensionBase
22 // Description : This is where all extensions should derive from.
23 // It defines the _self and _this members that can
24 // be used from the extension method.
25 ////////////////////////////////////////////////////////////////////
26 template<class T>
27 class EXPCL_DTOOLCONFIG ExtensionBase {
28 public:
29  T * _this;
30 };
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : Extension
34 // Description : The default class template does not define any
35 // methods. Classes that are extended should create
36 // a specialization of this class template.
37 ////////////////////////////////////////////////////////////////////
38 template<class T>
39 class EXPCL_DTOOLCONFIG Extension : public ExtensionBase<T> {
40 };
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function : invoke_extension
44 // Description : Creates a new extension object for the given
45 // pointer that can then be used to call extension
46 // methods, as follows:
47 // invoke_extension((MyClass) *ptr).method()
48 ////////////////////////////////////////////////////////////////////
49 template<class T>
50 inline Extension<T>
51 invoke_extension(T *ptr) {
52  Extension<T> ext;
53  ext._this = ptr;
54  return ext;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function : invoke_extension
59 // Description : The const version of the above function.
60 ////////////////////////////////////////////////////////////////////
61 template<class T>
62 inline const Extension<T>
63 invoke_extension(const T *ptr) {
64  Extension<T> ext;
65  ext._this = (T *) ptr;
66  return ext;
67 }
68 
69 #endif
This is where all extensions should derive from.
Definition: extension.h:27
The default class template does not define any methods.
Definition: extension.h:39