~ubuntu-branches/ubuntu/trusty/gsmlib/trusty

« back to all changes in this revision

Viewing changes to gsmlib/gsm_map_key.h

  • Committer: Bazaar Package Importer
  • Author(s): Mikael Hedin
  • Date: 2002-01-24 12:59:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020124125907-b7qkpokx5283jdpu
Tags: upstream-1.8
ImportĀ upstreamĀ versionĀ 1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// *************************************************************************
 
2
// * GSM TA/ME library
 
3
// *
 
4
// * File:    gsm_map_key.h
 
5
// *
 
6
// * Purpose: Common MapKey implementation for the multimaps in
 
7
// *          gsm_sorted_sms_store and gsm_sorted_phonebook
 
8
// *
 
9
// * Author:  Peter Hofmann (software@pxh.de)
 
10
// *
 
11
// * Created: 5.11.1999
 
12
// *************************************************************************
 
13
 
 
14
#ifndef GSM_MAP_KEY_H
 
15
#define GSM_MAP_KEY_H
 
16
 
 
17
#include <gsmlib/gsm_sms_codec.h>
 
18
 
 
19
namespace gsmlib
 
20
{
 
21
  // sort order for MapKeys
 
22
 
 
23
  enum SortOrder {ByText = 0, ByTelephone = 1, ByIndex = 2, ByDate = 3,
 
24
                  ByType = 4, ByAddress = 5};
 
25
 
 
26
  // wrapper for map key, can access Sortedtore to get sortOrder()
 
27
 
 
28
  template <class SortedStore> class MapKey
 
29
  {
 
30
    SortedStore &_myStore;   // my store
 
31
    // different type keys
 
32
    Address _addressKey;
 
33
    Timestamp _timeKey;
 
34
    int _intKey;
 
35
    string _strKey;
 
36
 
 
37
  public:
 
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) {}
 
47
 
 
48
    friend
 
49
    bool operator< 
 
50
#ifndef WIN32
 
51
        <>
 
52
#endif
 
53
                         (const MapKey<SortedStore> &x,
 
54
                      const MapKey<SortedStore> &y);
 
55
    friend
 
56
    bool operator==
 
57
#ifndef WIN32
 
58
        <>
 
59
#endif
 
60
                          (const MapKey<SortedStore> &x,
 
61
                       const MapKey<SortedStore> &y);
 
62
  };
 
63
 
 
64
  // compare two keys
 
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);
 
71
  
 
72
  // MapKey members
 
73
  
 
74
  template <class SortedStore>
 
75
    bool gsmlib::operator<(const MapKey<SortedStore> &x,
 
76
                           const MapKey<SortedStore> &y)
 
77
    {
 
78
      assert(&x._myStore == &y._myStore);
 
79
 
 
80
      switch (x._myStore.sortOrder())
 
81
      {
 
82
      case ByDate:
 
83
        return x._timeKey < y._timeKey;
 
84
      case ByAddress:
 
85
        return x._addressKey < y._addressKey;
 
86
      case ByIndex:
 
87
      case ByType:
 
88
        return x._intKey < y._intKey;
 
89
      case ByTelephone:
 
90
        return Address(x._strKey) < Address(y._strKey);
 
91
      case ByText:
 
92
        return x._strKey < y._strKey;
 
93
      default:
 
94
        assert(0);
 
95
        return true;
 
96
      }
 
97
    }
 
98
 
 
99
  template <class SortedStore>
 
100
    bool gsmlib::operator==(const MapKey<SortedStore> &x,
 
101
                            const MapKey<SortedStore> &y)
 
102
    {
 
103
      assert(&x._myStore == &y._myStore);
 
104
 
 
105
      switch (x._myStore.sortOrder())
 
106
      {
 
107
      case ByDate:
 
108
        return x._timeKey == y._timeKey;
 
109
      case ByAddress:
 
110
        return x._addressKey == y._addressKey;
 
111
      case ByIndex:
 
112
      case ByType:
 
113
        return x._intKey == y._intKey;
 
114
      case ByTelephone:
 
115
        return Address(x._strKey) == Address(y._strKey);
 
116
      case ByText:
 
117
        return x._strKey == y._strKey;
 
118
      default:
 
119
        assert(0);
 
120
        return true;
 
121
      }
 
122
    }
 
123
};
 
124
 
 
125
#endif // GSM_MAP_KEY_H