torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VisitorApplier.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_VISITORAPPLIER_HPP
17 #define TORC_GENERIC_VISITORAPPLIER_HPP
18 
19 namespace torc {
20 namespace generic {
21 
22 /**
23  * This is an utility functor class that can be used to apply
24  * visitor to a list of genOM objects. The type _Tp should be
25  * replaced by the visitor type.
26  */
27 
28 template <typename _Tp> class VisitorApplier {
29 public:
30  VisitorApplier(_Tp& inVisitor) :
31  mVisitor(inVisitor) {
32  }
33 
34  template <typename _Up> void operator()(const boost::shared_ptr<_Up>& inVisited) const
35  throw (Error) {
36  try {
37  inVisited->accept(mVisitor);
38  } catch(Error& e) {
39  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
40  throw;
41  }
42  }
43 private:
44  /*mutable*/ _Tp& mVisitor;
45 };
46 
47 } //namespace generic
48 } //namespace torc
49 
50 #endif // TORC_GENERIC_VISITORAPPLIER_HPP
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void operator()(const boost::shared_ptr< _Up > &inVisited) const
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73