Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ContactTypes.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/frag_picker/ContactTypes.cc
11 /// @brief fragment picker contact types
12 /// @author David E. Kim (dekim@u.washington.edu)
13 
14 // package headers
16 
17 // Utility headers
18 #include <utility/exit.hh>
19 #include <utility/vector1.hh>
20 
21 // C++ headers
22 #include <map>
23 
24 namespace protocols {
25 namespace frag_picker {
26 
27 
28 /// BEGIN: local functions
29 
30 /// @brief setup the map that converts string name to enum
31 std::map< std::string, ContactType > setup_name2type() {
32  std::map< std::string, ContactType > n2t;
33  n2t[ "ca" ] = CA;
34  n2t[ "cb" ] = CB;
35  n2t[ "cen" ] = CEN;
36  n2t[ "unk" ] = UNK;
37  return n2t;
38 }
39 
40 /// @brief map that converts string name to enum
41 inline
42 std::map< std::string, ContactType > & name2type() {
43  // static initialization only happens once
44  static std::map< std::string, ContactType > * name2contacttype_ = new std::map< std::string, ContactType >( setup_name2type() );
45  return *name2contacttype_;
46 }
47 
48 /// @brief setup the vector that maps enum to string name
51  for ( std::map< std::string, ContactType >::const_iterator iter = name2type().begin(),
52  iter_end = name2type().end(); iter != iter_end; ++iter ) {
53  t2n[ iter->second ] = iter->first;
54  }
55  return t2n;
56 }
57 
58 /// @brief vector that maps enum to string name
59 inline
61  // static initialization only happens once
63  return *contacttype2name_;
64 }
65 
66 /// END: local functions
67 
68 //////////////////////////////////////////////////////////
69 /// @brief give a string name and return its enum type
70 //////////////////////////////////////////////////////////
72 contact_type( std::string const & name ) {
73  std::map< std::string, ContactType >::const_iterator iter = name2type().find( name );
74  if ( iter == name2type().end() ) {
75  utility_exit_with_message( "unrecognized contact type " + name );
76  }
77  return iter->second;
78 }
79 
80 ///////////////////////////////////////////////////////
81 /// @brief give an enum type and return the string name
82 ///////////////////////////////////////////////////////
85  if (type > num_contact_types ) return "ContactTypeOutofRange";
86  return type2name()[ type ];
87 }
88 
89 
90 } // namespace frag_picker
91 } // namespace protocols
92