Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

visitor.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                visitor.h  -  Base classes for visitor objects
00003                              -------------------
00004     begin                : Fri 7 July 2003
00005     copyright            : (C) 2003 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, visitor.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2003
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEVISITOR_H
00028 #define __NEVISITOR_H
00029 
00030 
00031 #include "base.h"
00032 
00033 
00040 namespace NeoEngine
00041 {
00042 
00043 
00051 class NEOENGINE_API BaseVisitor
00052 {
00053     public:
00054 
00057         virtual                                             ~BaseVisitor() {}
00058 };
00059 
00060 
00061 
00062 
00063 
00067 template < class NodeType > class Visitor : public virtual BaseVisitor
00068 {
00069     public:
00070 
00075         virtual void                                         Visit( NodeType &rkVisited ) = 0;
00076 };
00077 
00078 
00079 
00080 #if defined( _MSC_VER ) && ( _MSC_VER < 1300 )
00081 
00082 // MSVC++ 6 can't cope with a static template member method
00083 
00084 template < class NodeType > void AcceptImpl( NodeType &rkVisited, BaseVisitor &rkVisitor )
00085 {
00086     if( Visitor< NodeType > *pkVisitorImpl = dynamic_cast< Visitor< NodeType >* >( &rkVisitor ) )
00087         pkVisitorImpl->Visit( rkVisited );
00088 }
00089 
00090 #endif
00091 
00092 
00093 
00094 
00099 class NEOENGINE_API BaseVisitable
00100 {
00101     protected:
00102 
00103 #if !defined( _MSC_VER ) || ( _MSC_VER >= 1300 )
00104 
00110         template < class NodeType > static void              AcceptImpl( NodeType &rkVisited, BaseVisitor &rkVisitor )
00111         {
00112             if( Visitor< NodeType > *pkVisitorImpl = dynamic_cast< Visitor< NodeType >* >( &rkVisitor ) )
00113                 pkVisitorImpl->Visit( rkVisited );
00114         }
00115 
00116 #endif
00117 
00118     public:
00119 
00122         virtual                                             ~BaseVisitable() {}
00123 
00128         virtual void                                         Accept( BaseVisitor &rkVisitor ) = 0;
00129 };
00130 
00131 
00132 }; // namespace NeoEngine
00133 
00134 
00135 // This define only simplifies the visitable classes
00136 #if defined( _MSC_VER ) && ( _MSC_VER < 1300 )
00137 #  define DefineVisitable() inline virtual void Accept( NeoEngine::BaseVisitor &rkVisitor ) { NeoEngine::AcceptImpl( *this, rkVisitor ); }
00138 #else
00139 #  define DefineVisitable() inline virtual void Accept( NeoEngine::BaseVisitor &rkVisitor ) { AcceptImpl( *this, rkVisitor ); }
00140 #endif
00141 
00142 #endif // __NEVISITOR_H

Generated on Wed Jan 21 14:21:07 2004 for NeoEngine by doxygen 1.3.5