OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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  /**
75  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
76  */
77  typedef osg::NodeCallback CallbackType;
78 
79  /**
80  * The type of the element used as parameter in the () operator.
81  */
82  typedef osg::Node HandledType;
83 
84  /**
85  * Call traversal method if existing for the specific callback type. This calls osg::NodeCallback::traverse.
86  *
87  * \param inst the instance to use
88  * \param handled the instance of the handled object
89  * \param nv the node visitor
90  */
91  static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv )
92  {
93  inst->traverse( handled, nv );
94  }
95 };
96 
97 /**
98  * StateAttributes have their own callback type and do NOT provide a traverse method.
99  */
100 template <>
101 class WGECallbackTraits< osg::StateAttribute >
102 {
103 public:
104 
105  /**
106  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
107  */
108  typedef osg::StateAttribute::Callback CallbackType;
109 
110  /**
111  * The type of the element used as parameter in the () operator.
112  */
113  typedef osg::StateAttribute HandledType;
114 
115  /**
116  * Call traversal method if existing for the specific callback type.
117  */
118  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
119  {
120  // no traverse allowed
121  }
122 };
123 
124 /**
125  * StateSets have their own callback type and do NOT provide a traverse method.
126  */
127 template <>
128 class WGECallbackTraits< osg::StateSet >
129 {
130 public:
131 
132  /**
133  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
134  */
135  typedef osg::StateSet::Callback CallbackType;
136 
137  /**
138  * The type of the element used as parameter in the () operator.
139  */
140  typedef osg::StateSet HandledType;
141 
142  /**
143  * Call traversal method if existing for the specific callback type.
144  */
145  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
146  {
147  // no traverse allowed
148  }
149 };
150 
151 /**
152  * Drawables have their own callback type and do NOT provide a traverse method.
153  */
154 template <>
156 {
157 public:
158 
159  /**
160  * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
161  */
162  typedef osg::Drawable::UpdateCallback CallbackType;
163 
164  /**
165  * The type of the element used as parameter in the () operator.
166  */
167  typedef osg::Drawable HandledType;
168 
169  /**
170  * Call traversal method if existing for the specific callback type.
171  */
172  static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
173  {
174  // no traverse allowed
175  }
176 };
177 
178 
179 #endif // WGECALLBACKTRAITS_H
180