Changeset 793 for cpp/frams/util/usertags.h
- Timestamp:
- 05/29/18 16:51:14 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/usertags.h
r286 r793 41 41 */ 42 42 43 template<class ID, class T,int N> class UserTags43 template<class ID, class T, int N> class UserTags 44 44 { 45 static char reg[N];46 T data[N];47 48 UserTags() {memset(data,0,sizeof(data));}45 static char reg[N]; 46 T data[N]; 47 public: 48 UserTags() { memset(data, 0, sizeof(data)); } 49 49 50 /** allocate new id */ 51 static int newID() 52 { for(int i=1;i<N;i++) if (!reg[i]) {reg[i]=1; return i;} 53 DB(printf("Warning: UserTags run out of ids!\n")); 54 return 0; } 55 static void freeID(int id) 56 { reg[id]=0; } 57 T& operator[](int id) 50 /** allocate new id */ 51 static int newID() 58 52 { 59 DB(if (!id) printf("Warning: UserTags @ %p is using id=0\n",this);) 60 return data[id]; 53 for (int i = 1; i < N; i++) if (!reg[i]) { reg[i] = 1; return i; } 54 DB(printf("Warning: UserTags run out of ids!\n")); 55 return 0; 61 56 } 62 operator T() { return data[0]; } 63 void operator=(T x) { data[0]=x; } 57 static void freeID(int id) 58 { 59 reg[id] = 0; 60 } 61 T& operator[](int id) 62 { 63 DB(if (!id) printf("Warning: UserTags @ %p is using id=0\n", this);) 64 return data[id]; 65 } 66 operator T() { return data[0]; } 67 void operator=(T x) { data[0] = x; } 64 68 }; 65 69 66 70 #endif 67 68 69 70 71
Note: See TracChangeset
for help on using the changeset viewer.