lib: reworked the bookmark parser
[barry.git] / opensync-plugin / src / idmap.h
blob4229df2ab90aedfc1cd34dbeb0f607bcac627cba
1 //
2 // \file uidmap.h
3 // Class that maps opensync UID strings to Blackberry
4 // Record ID's and back.
5 //
7 /*
8 Copyright (C) 2007-2010, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRY_SYNC_UIDMAP_H__
24 #define __BARRY_SYNC_UIDMAP_H__
26 #include <map>
27 #include <string>
28 #include <stdint.h>
30 class idmap
32 public:
33 typedef std::string uid_type;
34 typedef uint32_t rid_type; // record ID
35 typedef std::map<uid_type, rid_type> map_type;
36 typedef map_type::iterator iterator;
37 typedef map_type::const_iterator const_iterator;
39 private:
40 // blank objects, so references work
41 uid_type m_blank_uid;
42 rid_type m_blank_rid;
44 // the map data
45 map_type m_map;
47 public:
48 idmap();
49 ~idmap();
51 bool Load(const char *filename);
52 bool Save(const char *filename) const;
54 bool UidExists(const uid_type &uid, const_iterator *it = 0) const;
55 bool RidExists(const rid_type &rid, const_iterator *it = 0) const;
57 const uid_type& GetUid(const rid_type &rid) const;
58 const rid_type& GetRid(const uid_type &uid) const;
60 const uid_type& operator[] (const rid_type &rid) const;
61 const rid_type& operator[] (const uid_type &uid) const;
63 // returns map::end() if either id already exists, otherwise
64 // returns newly mapped item iterator.
66 // The other versions of the function are to make conversion
67 // between different types easier, giving ability to map
68 // with any reasonable type, and then access the real
69 // values through the iterator if needed.
70 const_iterator Map(const uid_type &uid, const rid_type &rid);
71 const_iterator Map(unsigned long uid_number, const rid_type &rid);
72 const_iterator Map(unsigned long uid_number, const std::string &rid_string);
74 void Unmap(iterator i) { m_map.erase(i); }
75 void UnmapUid(const uid_type &uid);
76 void UnmapRid(const rid_type &rid);
78 // some stl-like functions
79 iterator begin() { return m_map.begin(); }
80 iterator end() { return m_map.end(); }
81 void clear() { m_map.clear(); }
84 #endif