-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyify.h
More file actions
66 lines (56 loc) · 1.58 KB
/
Keyify.h
File metadata and controls
66 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _KEYIFY_H_
#define _KEYIFY_H_
// The following templates are used to quickly and easily create a class that
// wraps around a simple type (such as an int) and can be put into TwoWayList
// or (In)EfficientMap.
// The "Keyify" template attaches both a Swap and an IsEqual (so a simple type
// can be used with either TwoWayList or (In)EfficientMap).
// For example, the following is valid code, which uses Keyify to attach a Swap
// and IsEqual to an int:
//
// void IntSwap (int& a, int& b) {
// int temp;
// temp = a;
// a = b;
// b = temp;
// }
//
// int IntCheck (int& a, int& b) {
// return (a == b);
// }
//
// int main () {
//
// typedef Keyify <int, IntSwap, IntCheck> keyifiedInt;
// InefficientMap <keyifiedInt, keyifiedInt> foo;
// keyifiedInt bar1, bar2;
//
// bar1 = 12;
// bar2 = 43;
// foo.Insert (bar1, bar2);
// ...
//
// SPECIAL NOTE: ONLY USE THESE TEMPLATES WITH SIMPLE TYPES (int, double, etc.)
// These templates use the = operation, so they are only safe with such types.
// If the type is more complicated, then create a class with Swap and IsEqual.
#include <string>
using namespace std;
template <class Type>
class Keyify {
private:
Type data;
public:
void Swap (Keyify &withMe);
void CopyFrom (Keyify &withMe);
Keyify (const Type castFromMe);
operator Type();
Type getData();
int IsEqual(Keyify &checkMe);
int LessThan(Keyify &checkMe);
Keyify ();
virtual ~Keyify ();
};
typedef Keyify<double> KeyDouble;
typedef Keyify<int> KeyInt;
typedef Keyify<string> KeyString;
#endif //_KEYIFY_H_