/usr/include/gsmlib/gsm_sorted_phonebook_base.h is in libgsmme-dev 1.10+20120414.gita5e5ae9a-0.3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | // *************************************************************************
// * GSM TA/ME library
// *
// * File: gsm_sorted_phonebook_base.h
// *
// * Purpose: Virtual base class for alphabetically sorted phonebook
// * The infrastructure in this module allows custom backends for
// * storing phonebook entries to be integrated into gsmlib
// * (eg. LDAP- or RDBMS-based phonebook stores).
// *
// * Author: Peter Hofmann (software@pxh.de)
// *
// * Created: 5.6.2000
// *************************************************************************
#ifndef GSM_SORTED_PHONEBOOK_BASE_H
#define GSM_SORTED_PHONEBOOK_BASE_H
#include <gsmlib/gsm_util.h>
#include <gsmlib/gsm_map_key.h>
#include <string>
#include <map>
#include <fstream>
namespace gsmlib
{
// a single entry in a phonebook
class PhonebookEntryBase : public RefBase
{
protected:
bool _changed; // set to true if _telephone or _text changed
std::string _telephone;
std::string _text;
int _index; // my position in the phonebook
// == -1 if not used (can only happen if
// phonebook is read from file)
bool _useIndex; // compare indices in operator==,
// use _index for inserting into
// Phonebook
public:
PhonebookEntryBase() :
_changed(false), _index(-1), _useIndex(false) {}
// convenience constructor
PhonebookEntryBase(std::string telephone, std::string text, int index = -1) :
_changed(false), _telephone(telephone), _text(text),
_index(index), _useIndex(false) {}
// accessor functions
virtual void set(std::string telephone, std::string text, int index = -1,
bool useIndex = false)
throw(GsmException);
virtual std::string text() const throw(GsmException);
virtual std::string telephone() const throw(GsmException);
// return true if both telephone and text are empty
bool empty() const throw(GsmException);
// set to true if operator== should compare the _index as well
void setUseIndex(bool useIndex)
{_useIndex = useIndex;}
bool useIndex() const {return _useIndex;}
// equality operator
// if one of the operands has _useIndex == true
// takes _index and e._index into account
bool operator==(const PhonebookEntryBase &e) const;
// return index
int index() const {return _index;}
// return true if entry changed
bool changed() const {return _changed;}
// reset the changed status (ie. if synced to file)
void resetChanged() {_changed = false;}
// return deep copy of this entry
virtual Ref<PhonebookEntryBase> clone();
PhonebookEntryBase(const PhonebookEntryBase &e) throw(GsmException);
PhonebookEntryBase &operator=(const PhonebookEntryBase &e)
throw(GsmException);
virtual ~PhonebookEntryBase() {}
};
// MapKey for sortedPhonebook
class SortedPhonebookBase;
typedef MapKey<SortedPhonebookBase> PhoneMapKey;
// maps text or telephone to entry
typedef std::multimap<PhoneMapKey, PhonebookEntryBase*> PhonebookMap;
// iterator for SortedPhonebook that hides the "second" member of the map
typedef PhonebookMap::iterator PhonebookMapIterator;
class SortedPhonebookIterator : public PhonebookMapIterator
{
public:
SortedPhonebookIterator() {}
SortedPhonebookIterator(PhonebookMap::iterator i) :
PhonebookMapIterator(i) {}
PhonebookEntryBase &operator*()
{return *((PhonebookMap::iterator)*this)->second;}
PhonebookEntryBase *operator->()
{return ((PhonebookMap::iterator)*this)->second;}
};
// virtual base class for sorted phonebooks
class SortedPhonebookBase : public RefBase, public NoCopy
{
public:
// iterator defs
typedef SortedPhonebookIterator iterator;
typedef PhonebookMap::size_type size_type;
// return maximum telephone number length
virtual unsigned int getMaxTelephoneLen() const = 0;
// return maximum entry description length
virtual unsigned int getMaxTextLen() const = 0;
// handle sorting
virtual void setSortOrder(SortOrder newOrder) = 0;
virtual SortOrder sortOrder() const = 0;
// phonebook traversal commands
// these are suitable to use stdc++ lib algorithms and iterators
// traversal commands
virtual iterator begin() = 0;
virtual iterator end() = 0;
// the size macros return the number of used entries
virtual int size() const = 0;
virtual int max_size() const = 0;
virtual int capacity() const = 0;
virtual bool empty() const throw(GsmException) = 0;
// existing iterators remain valid after an insert or erase operation
// return position
// insert only writes to available positions
// warning: insert fails silently if size() == max_size()
virtual iterator insert(const PhonebookEntryBase& x) throw(GsmException)
= 0;
virtual iterator insert(iterator position, const PhonebookEntryBase& x)
throw(GsmException) = 0;
virtual PhonebookMap::size_type count(std::string &key) = 0;
virtual iterator find(std::string &key) = 0;
virtual iterator lower_bound(std::string &key) = 0;
virtual iterator upper_bound(std::string &key) = 0;
virtual std::pair<iterator, iterator> equal_range(std::string &key) = 0;
virtual PhonebookMap::size_type count(int key) = 0;
virtual iterator find(int key) = 0;
virtual iterator lower_bound(int key) = 0;
virtual iterator upper_bound(int key) = 0;
virtual std::pair<iterator, iterator> equal_range(int key) = 0;
virtual size_type erase(std::string &key) throw(GsmException) = 0;
virtual size_type erase(int key) throw(GsmException) = 0;
virtual void erase(iterator position) throw(GsmException) = 0;
virtual void erase(iterator first, iterator last) throw(GsmException) = 0;
virtual void clear() throw(GsmException) = 0;
// synchronize SortedPhonebookBase with storage
virtual void sync() throw(GsmException) = 0;
virtual ~SortedPhonebookBase() {}
};
typedef Ref<SortedPhonebookBase> SortedPhonebookRef;
// base factory class for custom backends
class CustomPhonebookFactory
{
public:
virtual ~CustomPhonebookFactory() { }
// return sorted phonebook object given the source specification
// (eg. database name, URL, etc.)
virtual SortedPhonebookRef createPhonebook(std::string source)
throw(GsmException) = 0;
};
// registry for custom backends
class CustomPhonebookRegistry
{
// registered factories
static std::map<std::string, CustomPhonebookFactory*> *_factoryList;
public:
// register a factory class for a specific backend
// (case does not matter for backend name)
static void registerCustomPhonebookFactory(std::string backendName,
CustomPhonebookFactory *factory)
throw(GsmException);
// return a phonebook object given the backend name and the source
// specification
static SortedPhonebookRef
createPhonebook(std::string backendName, std::string source) throw(GsmException);
};
};
#endif // GSM_SORTED_PHONEBOOK_BASE_H
|