SST/macro
unique_id.h
Go to the documentation of this file.
1 #ifndef UNIQUE_ID_H
2 #define UNIQUE_ID_H
3 
4 #include <sstream>
5 #include <stdint.h>
6 
7 #include <sprockit/spkt_config.h>
9 
10 namespace sstmac {
11 namespace hw {
12 
14  uint32_t src_node;
15  uint32_t msg_num;
16 
17  unique_event_id(uint32_t src, uint32_t num) :
18  src_node(src), msg_num(num) {
19  }
20 
22  src_node(-1), msg_num(0) {
23  }
24 
25  operator uint64_t() const {
26  //map onto single 64 byte number
27  uint64_t lo = msg_num;
28  uint64_t hi = (((uint64_t)src_node)<<32);
29  return lo | hi;
30  }
31 
32  std::string
33  to_string() const {
34  std::stringstream sstr;
35  sstr << "unique_id(" << src_node << "," << msg_num << ")";
36  return sstr.str();
37  }
38 
39  void
40  set_src_node(uint32_t src) {
41  src_node = src;
42  }
43 
44  void
45  set_seed(uint32_t seed) {
46  msg_num = seed;
47  }
48 
50  ++msg_num;
51  return *this;
52  }
53 
55  unique_event_id other(*this);
56  ++msg_num;
57  return other;
58  }
59 };
60 
61 
62 }
63 }
64 
66 template <>
67 class serialize<sstmac::hw::unique_event_id>
68 {
69  public:
70  void
71  operator()(sstmac::hw::unique_event_id& id, serializer& ser){
72  ser.primitive(id);
73  }
74 };
76 
77 
78 #if SPKT_HAVE_CPP11
79 namespace std {
80 template <>
81 struct hash<sstmac::hw::unique_event_id>
82  : public std::hash<uint64_t>
83 { };
84 }
85 #else
86 namespace sstmac { namespace hw {
87 inline std::size_t
89  return uint64_t(id);
90 }
91 }}
92 #endif
93 
94 
95 
96 #endif // UNIQUE_ID_H
unique_event_id operator++(int)
Definition: unique_id.h:54
std::size_t hash_value(const unique_event_id &id)
Definition: unique_id.h:88
void set_src_node(uint32_t src)
Definition: unique_id.h:40
std::string to_string() const
Definition: unique_id.h:33
void set_seed(uint32_t seed)
Definition: unique_id.h:45
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
#define START_SERIALIZATION_NAMESPACE
Definition: serializable.h:36
unique_event_id(uint32_t src, uint32_t num)
Definition: unique_id.h:17
#define END_SERIALIZATION_NAMESPACE
Definition: serializable.h:37
unique_event_id & operator++()
Definition: unique_id.h:49
void operator()(sstmac::hw::unique_event_id &id, serializer &ser)
Definition: unique_id.h:71