source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/experimental/counteddictionary.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 742 bytes
Line 
1#ifndef _COUNTEDDICTIONARY_H_
2#define _COUNTEDDICTIONARY_H_
3
4template <class Dict>
5class CountedDictionary : public Dict {
6public:
7  class Entry : public Dict::Entry {};
8
9  __forceinline CountedDictionary (void)
10    : num (0)
11  {}
12
13  __forceinline void clear (void) {
14    num = 0;
15    Dict::clear();
16  }
17
18  __forceinline Entry * get (void) {
19    Entry * e = (Entry *) Dict::get();
20    if (e) {
21      --num;
22    }
23    return e;
24  }
25
26  __forceinline Entry * remove (void) {
27    Entry * e = (Entry *) Dict::remove();
28    if (e) {
29      --num;
30    }
31    return e;
32  }
33
34  __forceinline void insert (Entry * e) {
35    Dict::insert (e);
36    ++num;
37  }
38
39  __forceinline int getNumber (void) const {
40    return num;
41  }
42
43private:
44  int num;
45};
46
47#endif
Note: See TracBrowser for help on using the repository browser.