Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/helpers.hpp

    r0de7e8 rd9f51c  
    2020#include "defs.hpp"
    2121#include "log.hpp"
    22 #include "memoryallocator.hpp"
    2322
    2423/********************************************** definitions *********************************/
     
    5251bool IsValidNumber( const char *string);
    5352int CompareDoubles (const void * a, const void * b);
    54 double * ReturnFullMatrixforSymmetric(const double * const cell_size);
    55 double * InverseMatrix(const double * const A);
    5653void performCriticalExit();
    5754
     
    197194};
    198195
     196/************ struct to contain simple enumerations ***************/
     197template <class C>
     198struct 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;
     225private:
     226  unsigned int max;
     227};
     228
     229/***** A counter to generate sequential numbers *******************/
     230struct counter{
     231  inline counter() : count(0){};
     232  inline counter(int i) : count(i){};
     233  inline unsigned int operator()(){
     234    return count++;
     235  }
     236private:
     237  unsigned int count;
     238};
     239
     240template <class C,class ForwardIterator>
     241enumeration<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
    199247#endif /*HELPERS_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.