CARMA C++
WorkResult.h
Go to the documentation of this file.
1 #ifndef CARMA_UTIL_WORKRESULT_H
2 #define CARMA_UTIL_WORKRESULT_H
3 
4 
8 
9 
10 #include <algorithm>
11 #include <map>
12 #include <set>
13 #include <string>
14 
15 
16 struct timeval;
17 struct timespec;
18 
19 
20 namespace carma {
21 namespace util {
22 
23 
24 class WorkResult;
25 
26 
30  friend class WorkResult;
31 
32  public:
33  class WaitError;
34  class PostError;
35 
36  typedef enum {
37  GOOD_POST_STATE,
38  LATE_POST_STATE,
39  LATE_DROPPED_POST_STATE,
40  NO_WAITERS_DROPPED_POST_STATE
41  } PostState;
42 
43  explicit WorkResultSet( const ::std::string & id );
44 
45  WorkResultSet( const WorkResultSet & rhs );
46 
47  virtual ~WorkResultSet( );
48 
49  WorkResultSet & operator=( const WorkResultSet & rhs );
50 
51  void swap( WorkResultSet & rhs );
52 
53  ::std::string getId( ) const;
54 
55  WorkResult addKey( const ::std::string & key );
56 
57  ::std::map< ::std::string, WorkResult >
58  addKeys( const ::std::set< ::std::string > & keys );
59 
60  void removeKeys( const ::std::set< ::std::string > & keys );
61 
62  void waitForAll( unsigned long milliseconds,
63  bool requireNormal,
64  PostState postStateAfterTimeout ) const;
65 
66  void waitForAll( const struct ::timeval & absTimeout,
67  bool requireNormal,
68  PostState postStateAfterTimeout ) const;
69 
70  void waitForAll( const struct ::timespec & absTimeout,
71  bool requireNormal,
72  PostState postStateAfterTimeout ) const;
73 
74  // Testing and debugging utility methods
75 
76  void verifyKeys( const ::std::set< ::std::string > & keys ) const;
77 
78  private:
79  class Impl;
80 
81  Impl * impl_;
82 };
83 
84 
86 class WorkResult {
87  friend class WorkResultSet;
88 
89  public:
90  WorkResult( const WorkResult & rhs );
91 
92  virtual ~WorkResult( );
93 
94  WorkResult & operator=( const WorkResult & rhs );
95 
96  void swap( WorkResult & rhs );
97 
98  void postNormal( );
99 
100  void postAbnormal( const ::std::string & errorText );
101 
102  private:
103  WorkResult( WorkResultSet::Impl * setImpl,
104  const ::std::string & key );
105 
106  WorkResultSet::Impl * setImpl_;
107  ::std::string key_;
108 };
109 
110 
111 } // namespace carma::util
112 } // namespace carma
113 
114 
115 inline void
116 carma::util::WorkResultSet::swap( WorkResultSet & rhs )
117 {
118  ::std::swap( impl_, rhs.impl_ );
119 }
120 
121 
123 carma::util::WorkResultSet::operator=( const WorkResultSet & rhs )
124 {
125  WorkResultSet temp( rhs );
126 
127  swap( temp );
128 
129  return *this;
130 }
131 
132 
133 inline void
134 carma::util::WorkResult::swap( WorkResult & rhs )
135 {
136  ::std::swap( setImpl_, rhs.setImpl_ );
137  key_.swap( rhs.key_ );
138 }
139 
140 
142 carma::util::WorkResult::operator=( const WorkResult & rhs )
143 {
144  WorkResult temp( rhs );
145 
146  swap( temp );
147 
148  return *this;
149 }
150 
151 
152 #endif
An abstract collection of the results of servicing a collection of work requests. ...
Definition: WorkResult.h:29
Abstract result of servicing a work request.
Definition: WorkResult.h:86
::std::set< K > keys(const ::std::map< K, V > &in)
Return the keys of a map as a set.