Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DataMap.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
11 /// @brief
12 /// @author Sarel Fleishman
13 
14 // Unit Headers
16 
17 // Package headers
18 
19 // Project headers
20 // ObjexxFCL Headers
21 
22 // C++ Headers
23 // AUTO-REMOVED #include <string>
24 #include <map>
25 
26 // Utility Headers
27 #include <utility/pointer/ReferenceCount.hh>
28 #include <basic/Tracer.hh>
29 
30 namespace protocols {
31 namespace moves {
32 
33 static basic::Tracer TR( "protocols.moves.DataMap" );
34 
37 
38 bool
39 DataMap::add( std::string const type, std::string const name, utility::pointer::ReferenceCountOP const op ){
40  if( has( type, name ) ){
41  TR<<"A datum of type "<<type<<" and name "<<name<<" has been added before. I'm not adding again. This is probably a BIG error but I'm letting it pass!"<<std::endl;
42  return false;
43  }
44 
45  data_map_[ type ].insert(std::make_pair( name, op ) );
46  return true;
47 }
48 
49 bool
50 DataMap::has( std::string const type, std::string const name/*=""*/ ) const {
51  std::map< std::string, std::map< std::string, utility::pointer::ReferenceCountOP > >::const_iterator it;
52 
53  it = data_map_.find( type );
54  if( it == data_map_.end() ) return false;
55  std::map< std::string, utility::pointer::ReferenceCountOP >::const_iterator it2;
56  it2 = it->second.find( name );
57  if( it2 == it->second.end() ) return false;
58 
59  return true;
60 }
61 
62 std::map< std::string, utility::pointer::ReferenceCountOP > &
64  if( !has( type ) ) {
65 // "dummy_entry" serves as a placeholder while the datamap does not contain actual maps of this type.
66 // it is removed if the map is accessed.
67  add( type, "dummy_entry", 0 );
68  }
69 
70  std::map< std::string, utility::pointer::ReferenceCountOP > & m( data_map_.find( type )->second );
71  if ( m.size() > 1 ) {
72  std::map< std::string, utility::pointer::ReferenceCountOP >::iterator it;
73  it=m.find( "dummy_entry" );
74  m.erase( it );
75  }
76  return m;
77 }
78 
80 DataMap::size() const { return data_map_.size(); }
81 
83 DataMap::begin() { return data_map_.begin(); }
84 
86 DataMap::end() { return data_map_.end(); }
87 
89 DataMap::begin() const { return data_map_.begin(); }
90 
92 DataMap::end() const { return data_map_.end(); }
93 
94 } // moves
95 } // protocols