Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EvaluatorFactory.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/evaluation/EvaluatorFactory.cc
11 /// @brief Factory for creating Evaluators objects
12 /// @author Matthew O'Meara (mattjomeara@gmail.com)
13 
14 // Unit Headers
18 
19 // Package Headers
20 #include <basic/Tracer.hh>
21 #include <utility/tag/Tag.hh>
22 
23 // Project Headers
25 #include <utility/vector0.hh>
26 
27 // Boost Headers
28 #include <boost/foreach.hpp>
29 #define foreach BOOST_FOREACH
30 
31 // C++ Headers
32 #include <sstream>
33 
34 //Auto Headers
35 #include <utility/vector1.hh>
36 
37 
38 
39 
40 
41 namespace protocols {
42 namespace evaluation {
43 
44 using std::endl;
45 using std::string;
46 using std::pair;
47 using std::stringstream;
48 using core::pose::Pose;
54 
55 static basic::Tracer tr("protocols.evaluator.EvaluatorFactory");
56 
57 EvaluatorFactory * EvaluatorFactory::instance_( 0 );
58 
59 /// @details Private constructor insures correctness of singleton.
61 
63  const EvaluatorFactory &
64 ) {}
65 
67 
68 
71 {
72  if ( instance_ == 0 ) {
74  }
75  return instance_;
76 }
77 
78 
79 void
81  EvaluatorCreatorCOP creator
82 ) {
83  types_.push_back(pair<string,EvaluatorCreatorCOP>(creator->type_name(), creator));
84 }
85 
86 
87 void
89  string const & type_name,
90  MetaPoseEvaluator & eval
91 ) {
92 
93  tr.Trace << "generate Evaluator of type " << type_name << std::endl;
94 
95  bool found(false);
96 
97  for(EvaluatorCreatorMap::const_iterator type = types_.begin(), type_end = types_.end(); type != type_end; ++type) {
98  if(type->first == type_name){
99  type->second->add_evaluators(eval);
100  found=true;
101  break;
102  }
103  }
104  if (!found) {
105  stringstream error_msg;
106  error_msg
107  << "Attempting to create unrecognized Evaluator "
108  << "'" << type_name << "'." << endl
109  << "check spelling or "
110  << "register a new Evaluator in the EvaluatorFactory" << endl
111  << "known Evaluator types are:" << endl;
112 
113  for(EvaluatorCreatorMap::const_iterator type = types_.begin(), type_end = types_.end(); type != type_end; ++type) {
114  error_msg << "\t" << type->first << endl;
115  }
116  utility_exit_with_message(error_msg.str());
117  }
118 }
119 
120 void
122  MetaPoseEvaluator & eval ) {
123 
124  for(EvaluatorCreatorMap::const_iterator type = types_.begin(), type_end = types_.end(); type != type_end; ++type) {
125  type->second->add_evaluators(eval);
126  }
127 }
128 
129 } // namespace
130 } // namespace