Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopsDefinerFactory.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/loops/loops_definers/LoopsDefinerFactory.cc
11 /// @brief Factory for creating LoopsDefiner objects
12 /// @author Matthew O'Meara (mattjomeara@gmail.com)
13 
14 // Unit Headers
18 
19 // Package Headers
20 #include <basic/Tracer.hh>
21 
22 // Project Headers
23 #include <utility/vector0.hh>
24 #include <utility/vector1.hh>
25 #include <utility/exit.hh>
26 
27 // Boost Headers
28 #include <boost/foreach.hpp>
29 #define foreach BOOST_FOREACH
30 
31 // C++ Headers
32 #include <string>
33 #include <sstream>
34 
35 namespace protocols {
36 namespace loops {
37 namespace loops_definers {
38 
39 using std::endl;
40 using std::string;
41 using std::stringstream;
42 using utility::vector1;
43 
44 
45 static basic::Tracer tr("protocols.loops.loops_definers.LoopsDefinerFactory");
46 
47 LoopsDefinerFactory * LoopsDefinerFactory::instance_( 0 );
48 
49 /// @details Private constructor insures correctness of singleton.
51 
53  const LoopsDefinerFactory &
54 ) {}
55 
57 
58 
61 {
62  if ( instance_ == 0 ) {
64  }
65  return instance_;
66 }
67 
68 
69 void
71  LoopsDefinerCreatorOP creator
72 ) {
73  types_[ creator->type_name() ] = creator;
74 }
75 
76 bool
78  string const & type_name
79 ) const {
80  LoopsDefinerCreatorMap::const_iterator iter = types_.find( type_name );
81  return iter != types_.end();
82 }
83 
86  std::string const & type_name
87 ) {
88 
89  tr.Trace << "generate LoopsDefiner of type " << type_name << std::endl;
90  LoopsDefinerCreatorMap::const_iterator iter = types_.find( type_name );
91  if (iter != types_.end()) {
92  return iter->second->create_loops_definer();
93  } else {
94  stringstream error_msg;
95  error_msg
96  << "Attempting to create unrecognized LoopsDefiner "
97  << "'" << type_name << "'." << endl
98  << "check spelling or "
99  << "register a new LoopsDefiner with the LoopsDefinerFactory" << endl
100  << "known LoopsDefiner types are:" << endl;
101 
102  foreach(const LoopsDefinerCreatorMap::value_type& type, types_){
103  error_msg << "\t" << type.first << endl;
104  }
105  utility_exit_with_message(error_msg.str());
106  }
107  return 0;
108 }
109 
112 ) const {
113  vector1< string > collection;
114  LoopsDefinerCreatorMap::const_iterator iter = types_.begin();
115  while ( iter != types_.end() ) {
116  collection.push_back(iter->first);
117  iter++;
118  }
119  return collection;
120 }
121 
122 
123 } // namespace
124 } // namespace
125 } // namespace