File: gsm_map_key.h

package info (click to toggle)
gsmlib 1.10+20120414.gita5e5ae9a-0.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 3,468 kB
  • ctags: 1,907
  • sloc: cpp: 12,315; sh: 11,376; ansic: 2,366; makefile: 263; sed: 93
file content (128 lines) | stat: -rw-r--r-- 3,363 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// *************************************************************************
// * GSM TA/ME library
// *
// * File:    gsm_map_key.h
// *
// * Purpose: Common MapKey implementation for the multimaps in
// *          gsm_sorted_sms_store and gsm_sorted_phonebook
// *
// * Author:  Peter Hofmann (software@pxh.de)
// *
// * Created: 5.11.1999
// *************************************************************************

#ifndef GSM_MAP_KEY_H
#define GSM_MAP_KEY_H

#include <gsmlib/gsm_sms_codec.h>

namespace gsmlib
{
  // sort order for MapKeys

  enum SortOrder {ByText = 0, ByTelephone = 1, ByIndex = 2, ByDate = 3,
                  ByType = 4, ByAddress = 5};

  // wrapper for map key, can access Sortedtore to get sortOrder()

  template <class SortedStore> class MapKey
  {
  public:
    SortedStore &_myStore;   // my store
    // different type keys
    Address _addressKey;
    Timestamp _timeKey;
    int _intKey;
    std::string _strKey;

  public:
    // constructors for the different sort keys
    MapKey(SortedStore &myStore, Address key) :
      _myStore(myStore), _addressKey(key) {}
    MapKey(SortedStore &myStore, Timestamp key) :
      _myStore(myStore), _timeKey(key) {}
    MapKey(SortedStore &myStore, int key) :
      _myStore(myStore), _intKey(key) {}
    MapKey(SortedStore &myStore, std::string key) :
      _myStore(myStore), _strKey(key) {}

/*
    friend
    bool operator< 
#ifndef WIN32
	<>
#endif
	                 (const MapKey<SortedStore> &x,
                      const MapKey<SortedStore> &y);
    friend
    bool operator==
#ifndef WIN32
	<>
#endif
	                  (const MapKey<SortedStore> &x,
                       const MapKey<SortedStore> &y);
*/
  };

  // compare two keys
  template <class SortedStore>
    extern bool operator<(const MapKey<SortedStore> &x,
                          const MapKey<SortedStore> &y);
  template <class SortedStore>
    extern bool operator==(const MapKey<SortedStore> &x,
                           const MapKey<SortedStore> &y);
  
  // MapKey members
  
  template <class SortedStore>
    bool operator<(const MapKey<SortedStore> &x,
                           const MapKey<SortedStore> &y)
    {
      assert(&x._myStore == &y._myStore);

      switch (x._myStore.sortOrder())
      {
      case ByDate:
        return x._timeKey < y._timeKey;
      case ByAddress:
        return x._addressKey < y._addressKey;
      case ByIndex:
      case ByType:
        return x._intKey < y._intKey;
      case ByTelephone:
        return Address(x._strKey) < Address(y._strKey);
      case ByText:
        return x._strKey < y._strKey;
      default:
        assert(0);
        return true;
      }
    }

  template <class SortedStore>
    bool operator==(const MapKey<SortedStore> &x,
                            const MapKey<SortedStore> &y)
    {
      assert(&x._myStore == &y._myStore);

      switch (x._myStore.sortOrder())
      {
      case ByDate:
        return x._timeKey == y._timeKey;
      case ByAddress:
        return x._addressKey == y._addressKey;
      case ByIndex:
      case ByType:
        return x._intKey == y._intKey;
      case ByTelephone:
        return Address(x._strKey) == Address(y._strKey);
      case ByText:
        return x._strKey == y._strKey;
      default:
        assert(0);
        return true;
      }
    }
};

#endif // GSM_MAP_KEY_H