OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGECALLBACKTRAITS_H 00026 #define WGECALLBACKTRAITS_H 00027 00028 #include <osg/Node> 00029 #include <osg/StateAttribute> 00030 #include <osg/StateSet> 00031 #include <osg/Drawable> 00032 00033 /** 00034 * This class is needed as OSG does not define a uniform callback type. 00035 */ 00036 template < typename Type > 00037 class WGECallbackTraits 00038 { 00039 public: 00040 /** 00041 * The real callback type. Some specific osg classes have specific callbacks. Specialize this template in this case. 00042 */ 00043 typedef typename Type::Callback CallbackType; 00044 00045 /** 00046 * The type of the element used as parameter in the () operator. 00047 */ 00048 typedef Type HandledType; 00049 00050 /** 00051 * Call traversal method if existing for the specific callback type. 00052 * 00053 * \param inst the instance to use 00054 * \param handled the instance of the handled object 00055 * \param nv the node visitor 00056 */ 00057 static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv ); 00058 }; 00059 00060 template < typename Type > 00061 void WGECallbackTraits< Type >::traverse( CallbackType* /*inst*/, Type* /*handled*/, osg::NodeVisitor* /*nv*/ ) 00062 { 00063 // the generic case: no nested callbacks -> no traversal 00064 } 00065 00066 /** 00067 * Nodes have their own callback type and provide a traverse method (as they can be nested). 00068 */ 00069 template <> 00070 class WGECallbackTraits< osg::Node > 00071 { 00072 public: 00073 00074 /** 00075 * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case. 00076 */ 00077 typedef osg::NodeCallback CallbackType; 00078 00079 /** 00080 * The type of the element used as parameter in the () operator. 00081 */ 00082 typedef osg::Node HandledType; 00083 00084 /** 00085 * Call traversal method if existing for the specific callback type. This calls osg::NodeCallback::traverse. 00086 * 00087 * \param inst the instance to use 00088 * \param handled the instance of the handled object 00089 * \param nv the node visitor 00090 */ 00091 static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv ) 00092 { 00093 inst->traverse( handled, nv ); 00094 } 00095 }; 00096 00097 /** 00098 * StateAttributes have their own callback type and do NOT provide a traverse method. 00099 */ 00100 template <> 00101 class WGECallbackTraits< osg::StateAttribute > 00102 { 00103 public: 00104 00105 /** 00106 * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case. 00107 */ 00108 typedef osg::StateAttribute::Callback CallbackType; 00109 00110 /** 00111 * The type of the element used as parameter in the () operator. 00112 */ 00113 typedef osg::StateAttribute HandledType; 00114 00115 /** 00116 * Call traversal method if existing for the specific callback type. 00117 */ 00118 static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ ) 00119 { 00120 // no traverse allowed 00121 } 00122 }; 00123 00124 /** 00125 * StateSets have their own callback type and do NOT provide a traverse method. 00126 */ 00127 template <> 00128 class WGECallbackTraits< osg::StateSet > 00129 { 00130 public: 00131 00132 /** 00133 * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case. 00134 */ 00135 typedef osg::StateSet::Callback CallbackType; 00136 00137 /** 00138 * The type of the element used as parameter in the () operator. 00139 */ 00140 typedef osg::StateSet HandledType; 00141 00142 /** 00143 * Call traversal method if existing for the specific callback type. 00144 */ 00145 static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ ) 00146 { 00147 // no traverse allowed 00148 } 00149 }; 00150 00151 /** 00152 * Drawables have their own callback type and do NOT provide a traverse method. 00153 */ 00154 template <> 00155 class WGECallbackTraits< osg::Drawable > 00156 { 00157 public: 00158 00159 /** 00160 * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case. 00161 */ 00162 typedef osg::Drawable::UpdateCallback CallbackType; 00163 00164 /** 00165 * The type of the element used as parameter in the () operator. 00166 */ 00167 typedef osg::Drawable HandledType; 00168 00169 /** 00170 * Call traversal method if existing for the specific callback type. 00171 */ 00172 static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ ) 00173 { 00174 // no traverse allowed 00175 } 00176 }; 00177 00178 00179 #endif // WGECALLBACKTRAITS_H 00180