nameFinder.h

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQSERVER_NAMEFINDER_H
00019 #define EQSERVER_NAMEFINDER_H
00020 
00021 #include "configVisitor.h"  // base class
00022 #include "types.h"
00023  
00024 namespace eq
00025 {
00026 namespace server
00027 {
00028 
00029 template< typename P, typename T > class NameFinder : public P
00030 {
00031 public:
00032     NameFinder( const std::string& name ) 
00033             : _name( name ), _result( 0 ) {}
00034     virtual ~NameFinder(){}
00035 
00036     virtual VisitorResult visitPre( T* node ) { return visit( node ); }
00037     virtual VisitorResult visit( T* node )
00038         {
00039             if( node->getName() == _name )
00040             {
00041                 _result = node;
00042                 return TRAVERSE_TERMINATE;
00043             }
00044             return TRAVERSE_CONTINUE;
00045         }
00046 
00047     T* getResult() { return _result; }
00048 
00049 private:
00050     const std::string _name;
00051     T*                _result;
00052 };
00053 
00054 typedef NameFinder< ConfigVisitor, Observer > ObserverFinder;
00055 typedef NameFinder< ConstConfigVisitor, const Observer > ConstObserverFinder;
00056 
00057 typedef NameFinder< ConfigVisitor, Layout > LayoutFinder;
00058 typedef NameFinder< ConstConfigVisitor, const Layout > ConstLayoutFinder;
00059 
00060 typedef NameFinder< ConfigVisitor, View > ViewFinder;
00061 typedef NameFinder< ConstConfigVisitor, const View > ConstViewFinder;
00062 
00063 typedef NameFinder< ConfigVisitor, Canvas > CanvasFinder;
00064 typedef NameFinder< ConstConfigVisitor, const Canvas > ConstCanvasFinder;
00065 
00066 typedef NameFinder< ConfigVisitor, Segment > SegmentFinder;
00067 typedef NameFinder< ConstConfigVisitor, const Segment > ConstSegmentFinder;
00068 
00069 typedef NameFinder< ConfigVisitor, Channel > ChannelFinder;
00070 typedef NameFinder< ConstConfigVisitor, const Channel > ConstChannelFinder;
00071 
00072 }
00073 }
00074 
00075 #endif // EQSERVER_NAMEFINDER_H
00076 
00077 
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8