OpenWalnut  1.4.0
WGECallbackTraits.h
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      * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
00075      */
00076     typedef osg::NodeCallback CallbackType;
00077 
00078     /**
00079      * The type of the element used as parameter in the () operator.
00080      */
00081     typedef osg::Node HandledType;
00082 
00083     /**
00084      * Call traversal method if existing for the specific callback type. This calls osg::NodeCallback::traverse.
00085      *
00086      * \param inst the instance to use
00087      * \param handled the instance of the handled object
00088      * \param nv the node visitor
00089      */
00090     static void traverse( CallbackType* inst, HandledType* handled, osg::NodeVisitor* nv )
00091     {
00092         inst->traverse( handled, nv );
00093     }
00094 };
00095 
00096 /**
00097  * StateAttributes have their own callback type and do NOT provide a traverse method.
00098  */
00099 template <>
00100 class WGECallbackTraits< osg::StateAttribute >
00101 {
00102 public:
00103     /**
00104      * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
00105      */
00106     typedef osg::StateAttribute::Callback CallbackType;
00107 
00108     /**
00109      * The type of the element used as parameter in the () operator.
00110      */
00111     typedef osg::StateAttribute HandledType;
00112 
00113     /**
00114      * Call traversal method if existing for the specific callback type.
00115      */
00116     static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
00117     {
00118         // no traverse allowed
00119     }
00120 };
00121 
00122 /**
00123  * StateSets have their own callback type and do NOT provide a traverse method.
00124  */
00125 template <>
00126 class WGECallbackTraits< osg::StateSet >
00127 {
00128 public:
00129     /**
00130      * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
00131      */
00132     typedef osg::StateSet::Callback CallbackType;
00133 
00134     /**
00135      * The type of the element used as parameter in the () operator.
00136      */
00137     typedef osg::StateSet HandledType;
00138 
00139     /**
00140      * Call traversal method if existing for the specific callback type.
00141      */
00142     static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
00143     {
00144         // no traverse allowed
00145     }
00146 };
00147 
00148 /**
00149  * Drawables have their own callback type and do NOT provide a traverse method.
00150  */
00151 template <>
00152 class WGECallbackTraits< osg::Drawable >
00153 {
00154 public:
00155     /**
00156      * The real callback type. Some specific OSG classes have specific callbacks. Specialize this template in this case.
00157      */
00158     typedef osg::Drawable::UpdateCallback CallbackType;
00159 
00160     /**
00161      * The type of the element used as parameter in the () operator.
00162      */
00163     typedef osg::Drawable HandledType;
00164 
00165     /**
00166      * Call traversal method if existing for the specific callback type.
00167      */
00168     static void traverse( CallbackType* /*inst*/, HandledType* /*handled*/, osg::NodeVisitor* /*nv*/ )
00169     {
00170         // no traverse allowed
00171     }
00172 };
00173 
00174 
00175 #endif  // WGECALLBACKTRAITS_H
00176