source: src/Helpers/enumeration.hpp@ 9098f9

Last change on this file since 9098f9 was 115378, checked in by Frederik Heber <heber@…>, 15 years ago

Changes to allow for (re-)incorporation of CodePatterns into MoleCuilder.

library:

  • no more suffixed with version, this should be dealt by pkg-config (.pc) or a contained version information.
  • corrected and extended .pc file
  • m4 macro ax_codepatterns.m4 created to allow for easy checking with autotools

codepatterns-config:

  • if pkg-config fails there is a small tool that tells about necessary cflags and the likes to compile with CodePatterns library (this was developed before we noticed we had a (half-)working pkg-config present).

smaller changes:

  • moved all Helpers files to src/Helpers (again).
  • changed include paths for Assert.hpp, ... accordingly.
  • version is not prefixed with "v" anymore.
  • small stuff in fast_functions.hpp is absolete (stl::algorithms)
  • Helpers/enumeration.hpp contains enumeration class ("iterable enum")
  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 * enumerator.hpp
3 *
4 * Created on: Dec 21, 2010
5 * Author: heber
6 */
7
8#ifndef ENUMERATOR_HPP_
9#define ENUMERATOR_HPP_
10
11/************ struct to contain simple enumerations ***************/
12template <class C>
13struct enumeration{
14 enumeration() : max(0) {}
15 enumeration(unsigned int i) : max(i) {}
16 enumeration(const enumeration &src) :
17 there(src.there),
18 back(src.back),
19 max(src.max)
20 {}
21 enumeration &operator=(const enumeration &src){
22 /* no self-assignment check needed */
23 there = src.there;
24 back = src.back;
25 max = src.max;
26 return *this;
27 }
28 void add(const C &value){
29 if(!there.count(value)){
30 there[value]=max;
31 back[max++]=value;
32 }
33 }
34 unsigned int getMax() const{
35 return max;
36 }
37
38 map<C,unsigned int> there;
39 map<unsigned int,C> back;
40private:
41 unsigned int max;
42};
43
44/***** A counter to generate sequential numbers *******************/
45struct counter{
46 inline counter() : count(0){};
47 inline counter(int i) : count(i){};
48 inline unsigned int operator()(){
49 return count++;
50 }
51private:
52 unsigned int count;
53};
54
55template <class C,class ForwardIterator>
56enumeration<C> enumerate(ForwardIterator first,ForwardIterator last){
57 enumeration<C> res;
58 for_each(first,last,bind1st(mem_fun(&enumeration<C>::add),&res));
59 return res;
60}
61
62#endif /* ENUMERATOR_HPP_ */
Note: See TracBrowser for help on using the repository browser.