Refactoring code for message logging protocols.
[charm.git] / src / ck-core / ckobjid.h
1 #ifndef _CKOBJID_H_
2 #define _CKOBJID_H_
3
4 union _ObjectID {
5         struct {
6                 CkChareID id;
7         } chare;
8         struct {
9                 CkGroupID id;
10                 int onPE;
11         } group; //also used for NodeGroups
12         struct s_array{
13                 CkGroupID id; //array id
14                 CkArrayIndexBase idx; //index
15         } array;
16 };
17
18 extern int totalCompares;
19
20 class CkObjID {
21 public:
22         ChareType type;
23         _ObjectID data;
24         CkObjID(){
25                 type = TypeInvalid;
26         };
27
28         inline operator CkHashCode()const{
29                 CkHashCode ret=circleShift(type,25);
30                 switch(type){
31                 case TypeChare:
32                 case TypeMainChare:
33                     ret += circleShift(data.chare.id.onPE,5);
34                     ret += circleShift((CmiInt8)data.chare.id.objPtr,3);
35                     break;
36                 case TypeGroup:
37                 case TypeNodeGroup:
38                     ret += circleShift(data.group.onPE,4);
39                     ret += circleShift(data.group.id.idx,6);
40                     break;
41                 case TypeArray:
42                     CkHashCode temp = data.array.idx.asChild().hash();
43                     //ret = circleShift(ret,13);
44                     //ret += circleShift(temp,11);
45                     ret += temp;
46                     break;
47                 }
48                 return ret;
49         }
50         
51         inline bool operator == (const CkObjID &t) const{
52                 
53                 if(type != t.type){
54                         return false;
55                 }
56                 switch (type){
57                         case TypeChare:
58                                 if((data.chare.id.onPE == t.data.chare.id.onPE) && (data.chare.id.objPtr == t.data.chare.id.objPtr)){
59                                         return true;
60                                 }else{
61                                         return false;
62                                 }
63                                 //break; unreachable
64                         case TypeGroup:
65                         case TypeNodeGroup:
66                                 if((data.group.onPE == t.data.group.onPE) && (data.group.id == t.data.group.id)){
67                                         return true;
68                                 }else{
69                                         return false;
70                                 }
71                                 //break; unreachable
72                         case TypeArray:
73                                 bool val;
74                                 if(data.array.id == t.data.array.id && data.array.idx.asChild().compare(t.data.array.idx.asChild())){
75                                         val = true;
76                                 }else{
77                                         val = false;
78                                 }
79                                 return val;
80                                 // break; unreachable
81                 }
82                 return false;
83         }
84         
85         void* getObject();
86
87         int guessPE();
88         
89         char *toString(char *buf) const;
90
91         inline void updatePosition(int PE);
92 };
93
94 PUPbytes(CkObjID)
95
96 typedef unsigned int MCount; //Message Count
97
98 #endif