Line data Source code
1 :
2 : /* Copyright (c) 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_NAMEFINDER_H
19 : #define EQFABRIC_NAMEFINDER_H
20 :
21 : #include "types.h"
22 :
23 : namespace eq
24 : {
25 : namespace fabric
26 : {
27 : template< class T, class V > class NameFinder : public V
28 : {
29 : public:
30 3917 : NameFinder( const std::string& name )
31 3917 : : _name( name ), _result( 0 ) {}
32 3917 : virtual ~NameFinder(){}
33 :
34 4439 : virtual VisitorResult visitPre( T* entity ) { return visit( entity ); }
35 23033 : virtual VisitorResult visit( T* entity )
36 : {
37 23033 : if( entity->getName() == _name )
38 : {
39 3917 : _result = entity;
40 3917 : return TRAVERSE_TERMINATE;
41 : }
42 19116 : return TRAVERSE_CONTINUE;
43 : }
44 :
45 3917 : T* getResult() { return _result; }
46 :
47 : private:
48 : const std::string _name;
49 : T* _result;
50 : };
51 :
52 : }
53 : }
54 : #endif // EQFABRIC_NAMEFINDER_H
55 :
56 :
|