Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceFactory.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/sequence/SequenceFactory.cc
11 /// @brief Factory for creating various types of sequences.
12 /// @author James Thompson
13 
18 
19 #include <basic/Tracer.hh>
20 #include <utility/exit.hh>
21 #include <utility/file/file_sys_util.hh>
22 
23 #include <utility/vector1.hh>
24 
25 
26 namespace core {
27 namespace sequence {
28 
29 static basic::Tracer tr("core.sequence.SequenceFactory");
30 
31 SequenceFactory * SequenceFactory::instance_( 0 );
32 
33 /// @details Private constructor insures correctness of singleton.
35 
38 {
39  if ( instance_ == 0 ) {
41  }
42  return instance_;
43 }
44 
45 void
47 {
48  seq_types_[ creator->keyname() ] = creator;
49 }
50 
52  std::string const & fn,
53  std::string const & type_name
54 ) {
55  SequenceOP seq = get_sequence(type_name);
56  tr.Debug << "reading from filename " << fn << std::endl;
57  if ( utility::file::file_exists(fn) ) {
58  seq->read_from_file(fn);
59  } else {
60  tr.Error << "Error: file " << fn << " doesn't exist!" << std::endl;
61  }
62  return seq;
63 }
64 
67 {
68  tr.Trace << "generate sequence of type " << type_name << std::endl;
69  SequenceCreatorMap::const_iterator iter = seq_types_.find( type_name );
70  if ( iter != seq_types_.end() ) {
71  return iter->second->create_sequence();
72  } else {
73 
74  using std::string;
75  using utility::vector1;
76  string msg("SequenceFactory::get_instance()->get_sequence: ");
77  msg += type_name + " does not name a known SequenceType --> " +
78  "check spelling or register new Sequence type in SequenceFactory!";
79 
80  msg += "known types are:\n";
82  for ( vector1< string >::const_iterator it = types.begin(), end = types.end(); it != end; ++it ) {
83  msg += *it + "\n";
84  }
85 
86  utility_exit_with_message( msg );
87  }
88  return 0;
89 }
90 
93  using std::string;
94  using utility::vector1;
95 
96  vector1< string > seq_names;
97  for ( SequenceCreatorMap::const_iterator
98  it = seq_types_.begin(), end = seq_types_.end(); it != end; ++it ) {
99  seq_names.push_back( it->first );
100  }
101 
102  return seq_names;
103 }
104 
106 {
107  seq_types_[ creator->keyname() ] = creator;
108 }
109 
112 {
113  SequenceCreatorMap::const_iterator iter = seq_types_.find( type_name );
114  if ( iter != seq_types_.end() ) {
115  return iter->second;
116  } else {
117 
118  using std::string;
119  using utility::vector1;
120  string msg("SequenceFactory::get_creator: ");
121  msg += type_name + " does not name a known SequenceType --> " +
122  "check spelling or register new Sequence type in SequenceFactory!";
123 
124  msg += "known types are:\n";
126  for ( vector1< string >::const_iterator it = types.begin(), end = types.end(); it != end; ++it ) {
127  msg += *it + "\n";
128  }
129 
130  utility_exit_with_message( msg );
131  }
132  return 0;
133 }
134 
135 } // sequence
136 } // core