12 #ifndef SSTMAC_COMMON_MESSAGES_PAIRPAYLOAD_H_INCLUDED 13 #define SSTMAC_COMMON_MESSAGES_PAIRPAYLOAD_H_INCLUDED 17 #include <sstmac/common/messages/payload.h> 27 template<
typename T1,
typename T2>
38 size_t size =
sizeof(T1) +
sizeof(T2)) :
39 data1_(inval1), data2_(inval2), size_(size) {
44 size_t size =
sizeof(T1) +
sizeof(T2)) :
45 data1_(other.data1_), data2_(other.data2_), size_(size) {
75 const std::pair<T1, T2>
90 virtual const payload::const_ptr
91 add(
const payload::const_ptr &other)
const {
94 T1 newval1 = casted->data().first +
data().first;
95 T2 newval2 = casted->data().second +
data().second;
96 payload::const_ptr ret =
construct(newval1, newval2);
105 virtual const payload::const_ptr
106 min(
const payload::const_ptr &other)
const {
109 if (data1_ < casted->
data().first) {
114 casted->data().second);
124 virtual const payload::const_ptr
125 max(
const payload::const_ptr &other)
const {
128 if (data1_ > casted->data().first) {
133 casted->data().second);
144 equals(
const payload::const_ptr &other)
const {
147 return data() == casted->data();
156 const payload::const_ptr
159 "pairpayload: logical_or doesn't make sense");
167 const payload::const_ptr
170 "pairpayload: logical_xor doesn't make sense");
178 const payload::const_ptr
181 "pairpayload: logical_and doesn't make sense");
200 std::stringstream ss;
201 ss <<
"pairpayload(" << data1_ <<
", " << data2_ <<
")";
213 template<
typename T1,
typename T2>
230 size_t s = (
sizeof(T1) +
sizeof(T2)) * size;
243 size_t s = (
sizeof(T1) +
sizeof(T2)) * size;
284 return size_ * (
sizeof(T1) +
sizeof(T2));
292 virtual const payload::const_ptr
293 add(
const payload::const_ptr &other)
const {
295 size_t s = (
sizeof(T1) +
sizeof(T2)) * size_;
299 for (
int i = 0; i <
size_; i++) {
300 newdata->
a = thisdata->
a + thatdata->
a;
301 newdata->
b = thisdata->
b + thatdata->
b;
306 payload::const_ptr ret =
construct(newdata, size_,
false);
315 virtual const payload::const_ptr
316 min(
const payload::const_ptr &other)
const {
318 "pairpayloadvector::less_than - doesn't make sense");
327 virtual const payload::const_ptr
328 max(
const payload::const_ptr &other)
const {
330 "pairpayloadvector::greater_than - doesn't make sense");
339 equals(
const payload::const_ptr &other)
const {
344 for (
int i = 0; i < size_ && ret; i++) {
345 ret = ret && (thisdata->
a == thatdata->
a);
346 ret = ret && (thisdata->
b == thatdata->
b);
358 const payload::const_ptr
361 "pairpayloadvector: logical_or doesn't make sense");
369 const payload::const_ptr
372 "pairpayloadvector: logical_xor doesn't make sense");
380 const payload::const_ptr
383 "pairpayloadvector: logical_and doesn't make sense");
394 "pairpayloadvector: serialize unimplemented");
403 std::stringstream ss;
404 ss <<
"pairpayloadvector(" << size_ <<
")";
virtual long byte_length() const
const payload::const_ptr logical_xor(const payload::const_ptr &other) const
Logical xor comparator.
Network payload consisting of a value with sensible copy semantics.
const payload::const_ptr logical_and(const payload::const_ptr &other) const
Logical and comparator.
sprockit::refcount_ptr< pairpayloadvector< T1, T2 > > ptr
virtual const payload::const_ptr add(const payload::const_ptr &other) const
Add operator.
const void * data() const
Access the underlying data in a const context.
void * memcpy(const VariablePtr< T > &dst, const VariablePtr< T > &src, size_t size)
virtual void serialize_order(sprockit::spkt_serializer *ser) const
Serialize this object into the spkt_serializer, for running in parallel simulation.
virtual const payload::const_ptr max(const payload::const_ptr &other) const
Greater than comparator, to only be used for the maxloc operation.
pair_payload(const T1 &inval1, const T2 &inval2, size_t size=sizeof(T1)+sizeof(T2))
Construction time.
#define ptr_safe_cast(type,...)
First entry in VA_ARGS is the obj Second entry is optional being an error msg.
virtual bool equals(const payload::const_ptr &other) const
Equals comparator.
const std::pair< T1, T2 > data() const
Access the underlying data in a const context.
std::pair< T1, T2 > data_unconst()
Access the underlying data in a non-const context.
void * data_unconst()
Access the underlying data in a non-const context.
virtual std::string to_string() const
Strinfier.
const payload::const_ptr logical_or(const payload::const_ptr &other) const
Logical or comparator.
T1 data1_
The data we keep.
virtual const payload::const_ptr min(const payload::const_ptr &other) const
Less than comparator, to only be used for the minloc mpi operation.
static pairpayloadvector< T1, T2 >::const_ptr construct(void *start, size_t size, bool copy=true)
Construct a new valuepayload.
virtual bool equals(const payload::const_ptr &other) const
Equals comparator.
virtual long byte_length() const
pair_payload< T1, T2 > PairPayload
sprockit::refcount_ptr< const pairpayloadvector< T1, T2 > > const_ptr
virtual std::string to_string() const
Strinfier.
Network payload consisting of a value with sensible copy semantics.
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
pairpayloadvector(const pairpayloadvector< T1, T2 > &other, size_t size)
Private copy constructor.
virtual const payload::const_ptr add(const payload::const_ptr &other) const
Add operator.
sprockit::refcount_ptr< const pair_payload< T1, T2 > > const_ptr
#define spkt_throw_printf(exc, template_str,...)
payload::const_ptr clone() const
Clone this object.
pair_payload(const pair_payload< T1, T2 > &other, size_t size=sizeof(T1)+sizeof(T2))
Private copy constructor.
virtual void serialize_order(sprockit::spkt_serializer *ser) const
Serialize this object into the spkt_serializer, for running in parallel simulation.
pairpayloadvector(void *start, size_t size, bool copy)
Construction time.
void * buf_
The data we keep.
const payload::const_ptr logical_xor(const payload::const_ptr &other) const
Logical xor comparator.
payload::const_ptr clone() const
Clone this object.
A function was intentionally unimplemented because it doesn't make sense, or it is ongoing work...
virtual const payload::const_ptr max(const payload::const_ptr &other) const
Greater than comparator, to only be used for the maxloc operation.
virtual const payload::const_ptr min(const payload::const_ptr &other) const
Less than comparator, to only be used for the minloc mpi operation.
virtual ~pairpayloadvector()
sprockit::refcount_ptr< pair_payload< T1, T2 > > ptr
const payload::const_ptr logical_and(const payload::const_ptr &other) const
Logical and comparator.
static pair_payload< T1, T2 >::const_ptr construct(const T1 &inval1, const T2 &inval2)
Construct a new valuepayload.
const payload::const_ptr logical_or(const payload::const_ptr &other) const
Logical or comparator.