OpenWalnut  1.4.0
WGECallbackTraits.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGECALLBACKTRAITS_H
26 #define WGECALLBACKTRAITS_H
27 
28 #include <osg/Node>
29 #include <osg/StateAttribute>
30 #include <osg/StateSet>
31 #include <osg/Drawable>
32 
33 /**
34  * This class is needed as OSG does not define a uniform callback type.
35  */
36 template < typename Type >
38 {
39 public:
40  /**
41  * The real callback type. Some specific osg classes have specific callbacks. Specialize this template in this case.
42  */
43  typedef typename Type::Callback CallbackType;
44 
45  /**
46  * The type of the element used as parameter in the () operator.
47  */
48  typedef Type HandledType;
49 
50  /**
51  * Call traversal method if existing for the specific callback type.
52  *
53  * \param inst the instance to use
54  * \param handled the instance of the handled object
55  * \param nv the node visitor
56  */
57  static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv );
58 };
59 
60 template < typename Type >
61 void WGECallbackTraits< Type >::traverse( CallbackType* /*inst*/, Type* /*handled*/, osg::NodeVisitor* /*nv*/ )
62 {
63  // the generic case: no nested callbacks -> no traversal
64 }
65 
66 /**
67  * Nodes have their own callback type and provide a traverse method (as they can be nested).
68  */
69 template <>
70 class WGECallbackTraits< osg::Node >
71 {
72 public:
73  /**
74  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
75  */
76  typedef osg::NodeCallback CallbackType;
77 
78  /**
79  * The type of the element used as parameter in the () operator.
80  */
81  typedef osg::Node HandledType;
82 
83  /**
84  * Call traversal method if existing for the specific callback type. This calls osg::NodeCallback::traverse.
85  *
86  * \param inst the instance to use
87  * \param handled the instance of the handled object
88  * \param nv the node visitor
89  */
90  static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv )
91  {
92  inst->traverse( handled, nv );
93  }
94 };
95 
96 /**
97  * StateAttributes have their own callback type and do NOT provide a traverse method.
98  */
99 template <>
100 class WGECallbackTraits< osg::StateAttribute >
101 {
102 public:
103  /**
104  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
105  */
106  typedef osg::StateAttribute::Callback CallbackType;
107 
108  /**
109  * The type of the element used as parameter in the () operator.
110  */
111  typedef osg::StateAttribute HandledType;
112 
113  /**
114  * Call traversal method if existing for the specific callback type.
115  */
116  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
117  {
118  // no traverse allowed
119  }
120 };
121 
122 /**
123  * StateSets have their own callback type and do NOT provide a traverse method.
124  */
125 template <>
126 class WGECallbackTraits< osg::StateSet >
127 {
128 public:
129  /**
130  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
131  */
132  typedef osg::StateSet::Callback CallbackType;
133 
134  /**
135  * The type of the element used as parameter in the () operator.
136  */
137  typedef osg::StateSet HandledType;
138 
139  /**
140  * Call traversal method if existing for the specific callback type.
141  */
142  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
143  {
144  // no traverse allowed
145  }
146 };
147 
148 /**
149  * Drawables have their own callback type and do NOT provide a traverse method.
150  */
151 template <>
152 class WGECallbackTraits< osg::Drawable >
153 {
154 public:
155  /**
156  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
157  */
158  typedef osg::Drawable::UpdateCallback CallbackType;
159 
160  /**
161  * The type of the element used as parameter in the () operator.
162  */
163  typedef osg::Drawable HandledType;
164 
165  /**
166  * Call traversal method if existing for the specific callback type.
167  */
168  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
169  {
170  // no traverse allowed
171  }
172 };
173 
174 
175 #endif // WGECALLBACKTRAITS_H
176 
osg::Drawable::UpdateCallback CallbackType
The real callback type.
static void traverse(CallbackType *, HandledType *, osg::NodeVisitor *)
Call traversal method if existing for the specific callback type.
osg::StateSet HandledType
The type of the element used as parameter in the () operator.
Type::Callback CallbackType
The real callback type.
osg::Node HandledType
The type of the element used as parameter in the () operator.
osg::Drawable HandledType
The type of the element used as parameter in the () operator.
osg::StateAttribute HandledType
The type of the element used as parameter in the () operator.
static void traverse(CallbackType *, HandledType *, osg::NodeVisitor *)
Call traversal method if existing for the specific callback type.
osg::StateSet::Callback CallbackType
The real callback type.
osg::NodeCallback CallbackType
The real callback type.
osg::StateAttribute::Callback CallbackType
The real callback type.
static void traverse(CallbackType *inst, HandledType *handled, osg::NodeVisitor *nv)
Call traversal method if existing for the specific callback type.
static void traverse(CallbackType *inst, HandledType *handled, osg::NodeVisitor *nv)
Call traversal method if existing for the specific callback type.
Type HandledType
The type of the element used as parameter in the () operator.
This class is needed as OSG does not define a uniform callback type.
static void traverse(CallbackType *, HandledType *, osg::NodeVisitor *)
Call traversal method if existing for the specific callback type.