1
// *************************************************************************
4
// * File: gsm_map_key.h
6
// * Purpose: Common MapKey implementation for the multimaps in
7
// * gsm_sorted_sms_store and gsm_sorted_phonebook
9
// * Author: Peter Hofmann (software@pxh.de)
11
// * Created: 5.11.1999
12
// *************************************************************************
17
#include <gsmlib/gsm_sms_codec.h>
21
// sort order for MapKeys
23
enum SortOrder {ByText = 0, ByTelephone = 1, ByIndex = 2, ByDate = 3,
24
ByType = 4, ByAddress = 5};
26
// wrapper for map key, can access Sortedtore to get sortOrder()
28
template <class SortedStore> class MapKey
30
SortedStore &_myStore; // my store
31
// different type keys
38
// constructors for the different sort keys
39
MapKey(SortedStore &myStore, Address key) :
40
_myStore(myStore), _addressKey(key) {}
41
MapKey(SortedStore &myStore, Timestamp key) :
42
_myStore(myStore), _timeKey(key) {}
43
MapKey(SortedStore &myStore, int key) :
44
_myStore(myStore), _intKey(key) {}
45
MapKey(SortedStore &myStore, string key) :
46
_myStore(myStore), _strKey(key) {}
53
(const MapKey<SortedStore> &x,
54
const MapKey<SortedStore> &y);
60
(const MapKey<SortedStore> &x,
61
const MapKey<SortedStore> &y);
65
template <class SortedStore>
66
extern bool operator<(const MapKey<SortedStore> &x,
67
const MapKey<SortedStore> &y);
68
template <class SortedStore>
69
extern bool operator==(const MapKey<SortedStore> &x,
70
const MapKey<SortedStore> &y);
74
template <class SortedStore>
75
bool gsmlib::operator<(const MapKey<SortedStore> &x,
76
const MapKey<SortedStore> &y)
78
assert(&x._myStore == &y._myStore);
80
switch (x._myStore.sortOrder())
83
return x._timeKey < y._timeKey;
85
return x._addressKey < y._addressKey;
88
return x._intKey < y._intKey;
90
return Address(x._strKey) < Address(y._strKey);
92
return x._strKey < y._strKey;
99
template <class SortedStore>
100
bool gsmlib::operator==(const MapKey<SortedStore> &x,
101
const MapKey<SortedStore> &y)
103
assert(&x._myStore == &y._myStore);
105
switch (x._myStore.sortOrder())
108
return x._timeKey == y._timeKey;
110
return x._addressKey == y._addressKey;
113
return x._intKey == y._intKey;
115
return Address(x._strKey) == Address(y._strKey);
117
return x._strKey == y._strKey;
125
#endif // GSM_MAP_KEY_H