00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/generic/om/VisitorApplier.hpp $ 00003 // $Id: VisitorApplier.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 #ifndef TORC_GENERIC_OM_VISITORAPPLIER_HPP 00017 #define TORC_GENERIC_OM_VISITORAPPLIER_HPP 00018 00019 namespace torc 00020 { 00021 namespace generic 00022 { 00023 00024 /** 00025 * This is an utility functor class that can be used to apply 00026 * visitor to a list of genOM objects. The type _Tp should be 00027 * replaced by the visitor type. 00028 */ 00029 00030 template<typename _Tp> 00031 class VisitorApplier { 00032 public: 00033 VisitorApplier( _Tp &inVisitor ) 00034 :mVisitor( inVisitor ) { 00035 } 00036 00037 template<typename _Up> 00038 void 00039 operator()( const boost::shared_ptr<_Up> &inVisited 00040 ) const throw( Error ) { 00041 try 00042 { 00043 inVisited->accept( mVisitor ); 00044 } 00045 catch( Error &e ) 00046 { 00047 e.setCurrentLocation( __FUNCTION__, 00048 __FILE__, __LINE__ ); 00049 throw; 00050 } 00051 } 00052 private: 00053 _Tp &mVisitor; 00054 }; 00055 00056 } //namespace generic 00057 } //namespace torc 00058 00059 00060 #endif // TORC_GENERIC_OM_VISITORAPPLIER_HPP