Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
HashTemplateIterator.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE__HASHTEMPLATEITERATOR_H
13#define TT_INCLUDE__HASHTEMPLATEITERATOR_H
14
15
16
17#include "HashTemplateClass.h"
18
19
20
21template<typename Key, typename Value> class HashTemplateIterator
22{
23
24private:
25
26 uint hash; // 0000
27 int index; // 0004
28 HashTemplateClass<Key, Value>* table; // 0008
29
30
31 void increment()
32 {
33 index = table->entries[index].next;
34 if (index == -1)
35 {
36 for (hash++; hash < table->maxHashCount; hash++)
37 {
38 index = table->indices[hash];
39 if (index != -1)
40 break;
41 }
42 }
43 }
44
45
46
47public:
48
49
50
51 HashTemplateIterator(HashTemplateClass<Key, Value>& _table)
52 {
53 table = &_table;
54 reset();
55 }
56
57
58
59 void reset()
60 {
61 index = -1;
62
63 for (hash = 0; hash < table->maxHashCount; hash++)
64 {
65 index = table->indices[hash];
66 if (index != -1)
67 break;
68 }
69 }
70
71 // Removes the current element and advances to the next element.
72 void remove()
73 {
74 TT_ASSERT(*this);
75 const Key &k = getKey();
76 increment();
77 table->Remove(k);
78 }
79
80
81
82 const Key& getKey() { return table->entries[index].key; }
83 Value& getValue() { return table->entries[index].value; }
84
85 void operator++() { increment(); }
86 operator bool() const { return index != -1; }
87
88}; // 000C
89
90
91
92#endif