Changes in src/helpers.hpp [0de7e8:d9f51c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/helpers.hpp
r0de7e8 rd9f51c 20 20 #include "defs.hpp" 21 21 #include "log.hpp" 22 #include "memoryallocator.hpp"23 22 24 23 /********************************************** definitions *********************************/ … … 52 51 bool IsValidNumber( const char *string); 53 52 int CompareDoubles (const void * a, const void * b); 54 double * ReturnFullMatrixforSymmetric(const double * const cell_size);55 double * InverseMatrix(const double * const A);56 53 void performCriticalExit(); 57 54 … … 197 194 }; 198 195 196 /************ struct to contain simple enumerations ***************/ 197 template <class C> 198 struct enumeration{ 199 enumeration() : max(0) {} 200 enumeration(unsigned int i) : max(i) {} 201 enumeration(const enumeration &src) : 202 there(src.there), 203 back(src.back), 204 max(src.max) 205 {} 206 enumeration &operator=(const enumeration &src){ 207 /* no self-assignment check needed */ 208 there = src.there; 209 back = src.back; 210 max = src.max; 211 return *this; 212 } 213 void add(const C &value){ 214 if(!there.count(value)){ 215 there[value]=max; 216 back[max++]=value; 217 } 218 } 219 unsigned int getMax() const{ 220 return max; 221 } 222 223 map<C,unsigned int> there; 224 map<unsigned int,C> back; 225 private: 226 unsigned int max; 227 }; 228 229 /***** A counter to generate sequential numbers *******************/ 230 struct counter{ 231 inline counter() : count(0){}; 232 inline counter(int i) : count(i){}; 233 inline unsigned int operator()(){ 234 return count++; 235 } 236 private: 237 unsigned int count; 238 }; 239 240 template <class C,class ForwardIterator> 241 enumeration<C> enumerate(ForwardIterator first,ForwardIterator last){ 242 enumeration<C> res; 243 for_each(first,last,bind1st(mem_fun(&enumeration<C>::add),&res)); 244 return res; 245 } 246 199 247 #endif /*HELPERS_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.