Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CalculatorFactory.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 core/pose/metrics/CalculatorFactory.cc
11 /// @brief CalculatorFactory class
12 /// @author John Karanicolas
13 
14 // Unit headers
16 
18 
19 // AUTO-REMOVED #include <core/pose/Pose.hh>
20 // AUTO-REMOVED #include <basic/MetricValue.hh>
21 
22 // Utility headers
23 #include <basic/Tracer.hh>
24 #include <utility/exit.hh>
25 
26 // C++ Headers
27 #include <map>
28 // AUTO-REMOVED #include <list>
29 #include <iostream>
30 
31 #include <utility/vector1.hh>
32 
33 
34 namespace core {
35 namespace pose {
36 namespace metrics {
37 
38 
39 void CalculatorFactory::register_calculator( std::string const & calculator_name, PoseMetricCalculatorOP const new_calculator ) {
40  if ( check_calculator_exists( calculator_name ) ) {
41  basic::Error() << "Cannot register a calculator with name: " << calculator_name << std::endl;
42  basic::Error() << "This calculator already exists" << std::endl;
43  utility_exit();
44  }
45  calculators_.insert( std::make_pair ( calculator_name, new_calculator ) );
46  return;
47 }
48 
49 
51  std::map< std::string, PoseMetricCalculatorOP >::const_iterator calculator_iter;
52  calculator_iter = calculators_.find( calculator_name );
53  if (calculator_iter == calculators_.end() ) {
54  // this calculator has not yet been setup
55  return false;
56  }
57  return true;
58 }
59 
60 
61 /// @brief remove a calculator from the factory
62 /// @return true if calculator removed, false if no such calculator
63 bool CalculatorFactory::remove_calculator( std::string const & calculator_name ) {
64  std::map< std::string, PoseMetricCalculatorOP >::iterator i = calculators_.find( calculator_name );
65 
66  if ( i != calculators_.end() ) {
67  calculators_.erase( i );
68  return true;
69  }
70 
71  return false;
72 }
73 
74 
75 /// @brief clear all calculators from factory
76 /// @return false if no calculators in list, true otherwise
78  if ( calculators_.empty() ) {
79  return false;
80  }
81 
82  calculators_.clear();
83  return true;
84 }
85 
86 
88  std::map< std::string, PoseMetricCalculatorOP >::const_iterator calculator_iter;
89  calculator_iter = calculators_.find( calculator_name );
90  if (calculator_iter == calculators_.end() ) {
91  // this calculator has not yet been setup
92  basic::Error() << "Could not find calculator " << calculator_name << " - need to register it before use" << std::endl;
93  utility_exit();
94  }
95  return calculator_iter->second->clone();
96 }
97 
98 
99 
100 } // metrics
101 } // pose
102 } // core