Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DataLoaderFactory.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/jd2/parser/DataLoaderFactory.cc
11 /// @brief Implementation of the factory class for the parser's DataLoader classes
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 // Unit headers
16 
17 // Package Headers
19 
20 // Utility Headers
21 #include <utility/exit.hh>
22 
23 // C++ headers
24 // AUTO-REMOVED #include <iostream>
25 
26 #include <utility/vector1.hh>
27 
28 
29 namespace protocols {
30 namespace jd2 {
31 namespace parser {
32 
33 DataLoaderFactory * DataLoaderFactory::instance_( 0 );
34 
36 
39  if ( !instance_ ) {
41  }
42  return instance_;
43 }
44 
45 void
47 {
48  //std::cout << "DataLoaderFactory::factory_register of " << creator->keyname() << std::endl;
49 
50  runtime_assert( creator );
51  std::string const loader_type( creator->keyname() );
52  if ( loader_type == "UNDEFINED NAME" ) {
53  utility_exit_with_message("Can't map derived DataLoader with undefined type name.");
54  }
55  if ( dataloader_creator_map_.find( loader_type ) != dataloader_creator_map_.end() ) {
56  utility_exit_with_message("DataLoaderFactory::factory_register already has a DataLoaderCreator with name \"" + loader_type + "\". Conflicting Filter names" );
57  }
58  dataloader_creator_map_[ loader_type ] = creator;
59 
60 }
61 
62 /// @brief Create a DataLoader given its identifying string
64 DataLoaderFactory::newDataLoader( std::string const & loader_type ) const
65 {
66 
67  //std::cout << "DataLoaderFactory::newDataLoader of " << loader_type << std::endl;
68 
69  LoaderMap::const_iterator iter( dataloader_creator_map_.find( loader_type ) );
70  if ( iter != dataloader_creator_map_.end() ) {
71  if ( ! iter->second ) {
72  utility_exit_with_message( "Error: DataLoaderCreatorOP prototype for " + loader_type + " is NULL!" );
73  }
74  return iter->second->create_loader();
75  } else {
76  utility_exit_with_message( loader_type + " is not known to the DataLoaderFactory. Was it registered via a DataLoaderRegistrator in one of the init.cc files (devel/init.cc or protocols/init.cc)?" );
77  return NULL;
78  }
79 
80 }
81 
83 
84 } //namespace parser
85 } //namespace jd2
86 } //namespace protocols