Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WUQueue.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/wum2/WUQueue.hh
11 /// @brief deque of WU with memory tracking
12 /// @author Ken Jung
13 
16 #include <sstream>
17 #include <iostream>
18 #ifdef USEBOOSTSERIALIZE
19 #include <boost/archive/binary_oarchive.hpp>
20 #endif
21 
22 namespace protocols{
23 namespace wum2{
24 
25 boost::uint64_t WUQueue::serialized_size( WorkUnitSP /*wu*/ ) {
26 #ifdef USEBOOSTSERIALIZE
27  std::stringstream s;
28  boost::archive::binary_oarchive oa(s);
29  oa << wu;
30  return s.str().length();
31 #else
32  std::cerr << "Memory usage tracked only if compiled against boost::serialize" << std::endl;
33  return 0;
34 #endif
35 }
36 
38  WorkUnitSP tmp;
39  if( empty() )
40  return tmp;
41  current_mem_ -= deque_.front().first;
42  tmp = deque_.front().second;
43  deque_.pop_front();
44  return tmp;
45 }
46 
47 // so much unnecessary copying
48 std::vector<WorkUnitSP> WUQueue::pop_all() {
49  std::vector<WorkUnitSP> tmp;
50  for( std::deque<wu_mem_pair>::iterator itr=deque_.begin(); itr != deque_.end(); itr++) {
51  tmp.push_back( itr->second );
52  }
53  deque_.clear();
54  return tmp;
55 }
56 
57 void WUQueue::push_back( std::vector<WorkUnitSP> wulist ) {
58  for( std::vector<WorkUnitSP>::iterator itr=wulist.begin(); itr != wulist.end(); itr++) {
59  push_back( *itr );
60  }
61 }
62 
64  boost::uint64_t mem_size = serialized_size( wu );
65  deque_.push_front( wu_mem_pair( mem_size, wu ) );
66  current_mem_ += mem_size;
67 }
68 
70  boost::uint64_t mem_size = serialized_size( wu );
71  deque_.push_back( wu_mem_pair( mem_size, wu ) );
72  current_mem_ += mem_size;
73 }
74 
75 }// wum2
76 }// protocols