SST/macro
event_location.h
Go to the documentation of this file.
1 #ifndef EVENT_LOCATION_H
2 #define EVENT_LOCATION_H
3 
5 #include <sprockit/errors.h>
6 
7 namespace sstmac {
8 
9 struct event_loc_id {
10  int32_t location;
13 
15  location(uninitialized.location) {
16  }
17 
18  explicit event_loc_id(topology_id id) :
19  location(uint32_t(id)) {
20  }
21 
22  explicit event_loc_id(endpoint_id id) :
23  location(-(uint32_t(id)+1)) {
24  }
25 
26  bool
27  is_node_id() const {
28  return location < 0;
29  }
30 
31  bool
32  is_switch_id() const {
33  return location >= 0 && location != null.location;
34  }
35 
36  node_id
38 #if SSTMAC_SANITY_CHECK
39  if (is_switch_id()) {
41  "event_location::convert_to_node_id: not a node id");
42  }
43  else if (is_null()) {
45  "event_location::convert_node_id: null id");
46  }
47 #endif
48  return node_id(-(location+1));
49  }
50 
51  switch_id
53 #if SSTMAC_SANITY_CHECK
54  if (is_null()) {
56  "event_location::convert_switch_id: null id");
57  }
58  else if (is_node_id()) {
60  "event_location::convert_to_switch_id: not a switch id");
61  }
62 #endif
63  return switch_id(location);
64  }
65 
66  bool
67  is_null() const {
68  return location == null.location;
69  }
70 
73  location = uint32_t(id);
74  return (*this);
75  }
76 
79  location = -uint32_t(id);
80  return (*this);
81  }
82 
83 };
84 
85 inline bool
86 operator==(const event_loc_id& a, const event_loc_id& b){
87  return a.location == b.location;
88 }
89 
90 inline bool
91 operator!=(const event_loc_id& a, const event_loc_id& b){
92  return a.location != b.location;
93 }
94 
95 inline bool
96 operator<(const event_loc_id& a, const event_loc_id& b){
97  return a.location < b.location;
98 }
99 
100 inline std::ostream&
101 operator<<(std::ostream& os, const event_loc_id& loc){
102  if(loc.is_node_id()){
103  os << loc.convert_to_node_id();
104  }
105  else {
106  os << loc.convert_to_switch_id();
107  }
108  return os;
109 }
110 
111 }
112 
113 #endif // EVENT_LOCATION_H
114 
int32_t topology_id
Definition: node_address.h:22
static event_loc_id uninitialized
bool operator!=(const event_loc_id &a, const event_loc_id &b)
node_id convert_to_node_id() const
bool is_switch_id() const
static event_loc_id null
event_loc_id & operator=(topology_id id)
std::ostream & operator<<(std::ostream &os, const event_loc_id &loc)
bool operator<(const event_loc_id &a, const event_loc_id &b)
event_loc_id(endpoint_id id)
bool operator==(const event_loc_id &a, const event_loc_id &b)
uint32_t endpoint_id
Definition: node_address.h:19
event_loc_id & operator=(endpoint_id id)
topology_id switch_id
Definition: node_address.h:23
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
event_loc_id(topology_id id)
#define spkt_throw(exc,...)
Definition: errors.h:44
switch_id convert_to_switch_id() const
endpoint_id node_id
Definition: node_address.h:20
bool is_node_id() const
bool is_null() const
Error indicating some internal value was unexpected.
Definition: errors.h:83