Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TaskOperationFactory.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/pack/task/operation/TaskOperationFactory.cc
11 /// @brief
12 /// @author ashworth
13 
15 
18 // AUTO-REMOVED #include <core/pack/task/operation/ResLvlTaskOperation.hh>
21 // AUTO-REMOVED #include <core/pack/task/operation/ResFilter.hh>
24 
25 #include <basic/Tracer.hh>
26 
27 #include <utility/exit.hh> // runtime_assert, utility_exit_with_message
28 #include <utility/io/izstream.hh>
29 #include <utility/tag/Tag.hh>
30 #include <utility/vector1.hh>
31 
32 #include <utility/vector0.hh>
33 
34 namespace core {
35 namespace pack {
36 namespace task {
37 namespace operation {
38 
39 static basic::Tracer TR("core.pack.task.operation.TaskOperationFactory");
40 
41 // special singleton functions
42 // initialize
43 TaskOperationFactory * TaskOperationFactory::instance_( 0 );
44 // get pointer to singleton
46 {
47  if ( ! instance_ ) {
49  }
50  return instance_;
51 }
52 
54 
55 ///@brief the default TaskOperations are now initialized in core/init.cc via the registrator/creator scheme
57 
58 void
60 {
61  if ( task_operation_creator_map_.find( creator->keyname() ) != task_operation_creator_map_.end() ) {
62  utility_exit_with_message( "Factory Name Conflict: Two or more TaskOperationCreators registered with the name " + creator->keyname() );
63  }
64  add_creator( creator );
65 }
66 
67 ///@brief add a TaskOperation prototype creator
68 void
70 {
71  runtime_assert( creator );
72  task_operation_creator_map_[ creator->keyname() ] = creator;
73 }
74 
75 bool TaskOperationFactory::has_type( std::string const & type ) const
76 {
77  return ( task_operation_creator_map_.find( type ) != task_operation_creator_map_.end() );
78 }
79 
80 ///@brief adds a ResLvlTaskOperation prototype creator to the child ResLvlTaskOperationFactory
81 void
83 {
85 }
86 
87 ///@brief adds a ResFilter prototype creator to the child ResFilterFactory
88 void
90 {
92 }
93 
94 ///@brief return new TaskOperation by key lookup in task_operation_creator_map_ (new TaskOperation parses Tag if provided)
95 /*!
96 Example Tag syntax for parser as of Summer 2009
97 
98 <ReadResfile name=rrf filename=myresfile/>
99 
100 or
101 
102 <OperateOnCertainResidues name=PROTEINnopack>
103  <PreventRepackingRLT/>
104  <ResidueHasProperty property=PROTEIN/>
105 </OperateOnCertainResidues>
106 
107 */
110  std::string const & type,
111  TagPtr tag /* = boost::shared_ptr< Tag >() */
112 ) const
113 {
114  TaskOperationCreatorMap::const_iterator iter( task_operation_creator_map_.find( type ) );
115  if ( iter != task_operation_creator_map_.end() ) {
116  TaskOperationOP task_operation( iter->second->create_task_operation() );
117  // parse tag if tag pointer is pointing to one
118  if ( tag.get() != NULL ) task_operation->parse_tag( tag );
119  return task_operation;
120  } else {
121  TR<<"Available options: ";
122  for( TaskOperationCreatorMap::const_iterator to_iter = task_operation_creator_map_.begin(); to_iter != task_operation_creator_map_.end(); ++to_iter )
123  TR<<to_iter->first<<", ";
124  TR<<std::endl;
125  utility_exit_with_message( type + " is not known to the TaskOperationFactory. Was its taskOperationCreator class registered at initialization?" );
126  return NULL;
127  }
128 }
129 
130 ///@brief recurse tag file to find TASKOPERATIONS definitions
131 void
133 {
135  TR.Trace << "Tag name " << tag->getName();
136  if ( tag->getTags().empty() ) { TR.Trace << " (empty)" << std::endl; return; }
137  else TR.Trace << std::endl;
138  TagPtrs const subtags( tag->getTags() );
139  if ( tag->getName() == "TASKOPERATIONS" ) {
140  for( TagPtrs::const_iterator tp( subtags.begin() ), tp_e( subtags.end() ); tp != tp_e; ++tp ) {
141  std::string const type( (*tp)->getName() );
142  TaskOperationOP new_to = newTaskOperation( type, *tp );
143  runtime_assert( new_to );
144  tops.push_back( new_to );
145  TR << "Created and parsed anonymous TaskOperation of type " << type << std::endl;
146  }
147  }
148  // recurse
149  for( TagPtrs::const_iterator tp( subtags.begin() ), tp_e( subtags.end() ); tp != tp_e; ++tp ) {
150  newTaskOperations( tops, *tp );
151  }
152 }
153 
154 void
156 {
157  utility::io::izstream fin;
158  fin.open( tagfilename.c_str() );
159  runtime_assert( fin.good() );
160  TagPtr tag = utility::tag::Tag::create(fin);
161  fin.close();
162  TR << "TaskOperationFactory parsing " << tagfilename << " to create TaskOperations:" << std::endl;
163  TR << tag << std::endl;
164  newTaskOperations( tops, tag );
165 }
166 
167 } //namespace operation
168 } //namespace task
169 } //namespace pack
170 } //namespace core