Skip to content

Commit 473cf56

Browse files
committed
Merge pull request #5 from iklionsky/master
added stream operator overloads for cpu_spec
2 parents efca3f3 + 3145761 commit 473cf56

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

include/cpuaff/cpu_spec.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#pragma once
3232

3333
#include "fwd.hpp"
34+
#include <string>
35+
#include <iostream>
36+
#include <stdlib.h>
37+
#include <sstream>
3438

3539
namespace cpuaff
3640
{
@@ -63,6 +67,21 @@ class cpu_spec
6367
}
6468

6569
public:
70+
/*!
71+
* Parse a string into a cpu_spec
72+
*
73+
* \param rhs the string to parse
74+
*
75+
* \return a cpu_spec parsed from the string
76+
*/
77+
static inline cpu_spec parse(const std::string &rhs)
78+
{
79+
std::istringstream buf(rhs);
80+
cpu_spec spec;
81+
buf >> spec;
82+
return spec;
83+
}
84+
6685
/*!
6786
* Get the zero based socket identifier for this cpu_spec.
6887
*
@@ -157,6 +176,32 @@ class cpu_spec
157176
return (socket_ == rhs.socket_ && core_ == rhs.core_ &&
158177
processing_unit_ == rhs.processing_unit_);
159178
}
179+
/*!
180+
* Stream in operator
181+
*
182+
* \parse a string triplet of socket,core,processing_unit into a cpu spec
183+
*/
184+
friend inline std::istream &operator>>(std::istream &s, cpu_spec &rhs)
185+
{
186+
s >> rhs.socket_;
187+
s.get();
188+
s >> rhs.core_;
189+
s.get();
190+
s >> rhs.processing_unit_;
191+
192+
return s;
193+
}
194+
/*!
195+
* Stream out operator
196+
*
197+
* \ stream out socket,core,processing_unit
198+
*/
199+
200+
friend inline std::ostream &operator<<(std::ostream &s, const cpu_spec &rhs)
201+
{
202+
s << rhs.socket_ << "," << rhs.core_ << "," << rhs.processing_unit_;
203+
return s;
204+
}
160205

161206
private:
162207
socket_type socket_;

include/cpuaff/cpuaff.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ typedef traits::native_cpu_wrapper_type native_cpu_wrapper;
9696
*/
9797
typedef impl::basic_cpu_set< traits > cpu_set;
9898

99+
/*!
100+
* a set that can hold unique cpu_specs
101+
*/
102+
103+
typedef std::set< cpu_spec > cpu_spec_set;
104+
99105
/*!
100106
* round_robin_allocator is a utility class that takes a set of cpus
101107
* and returns them as requested in a round-robin fashion. It organizes the

include/cpuaff/impl/basic_cpu.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ class basic_cpu
148148
};
149149
} // namespace impl
150150
} // namespace cpuaff
151+
/*!
152+
* Stream operator
153+
*
154+
* \print id, numa, socket, core, processing unit
155+
*
156+
*/
151157

152158
template < typename TRAITS >
153159
std::ostream &operator<<(std::ostream &s,

include/cpuaff/impl/basic_round_robin_allocator.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class basic_round_robin_allocator
9696
return true;
9797
}
9898

99+
inline int size() { return cpu_queue_.size(); }
100+
99101
private:
100102
/*!
101103
* Initializes a basic_round_robin_allocator with the given set of cpus.
@@ -138,4 +140,4 @@ class basic_round_robin_allocator
138140
std::queue< cpu_type > cpu_queue_;
139141
};
140142
} // namespace impl
141-
} // namespace cpuaff
143+
} // namespace cpuaff

include/cpuaff/pci_device_description.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class pci_device_description
109109
} // namespace cpuaff
110110

111111
inline std::ostream &operator<<(std::ostream &s,
112-
const cpuaff::pci_device_description &dev)
112+
const cpuaff::pci_device_description &dev)
113113
{
114114
s << dev.vendor_description() << ":" << dev.device_description();
115115
return s;

0 commit comments

Comments
 (0)