summaryrefslogtreecommitdiff
path: root/include/m_database.h
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-16 20:01:14 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-16 20:01:14 +0300
commit39390b02dbd5aa7eb21a83773fa561b39f8828bc (patch)
tree7982eda1257f7466b5663c2865fdb7804c397257 /include/m_database.h
parent5046973a41e412afd06d6a78a3b9bce226e3cf50 (diff)
always hated these long expressions: contact_iter makes them much shorter
Diffstat (limited to 'include/m_database.h')
-rw-r--r--include/m_database.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 41ce36bef5..bfab8294c5 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -227,6 +227,37 @@ EXTERN_C MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szPr
EXTERN_C MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szProto);
#endif
+#if defined(__cplusplus)
+class contact_iter
+{
+ const char *m_szModule;
+
+public:
+ contact_iter(const char *m = nullptr) :
+ m_szModule(m)
+ {}
+
+ class iterator
+ {
+ MCONTACT hContact;
+ const char *m_szModule;
+
+ public:
+ __inline iterator(const char *_m, MCONTACT _h) :
+ hContact(_h),
+ m_szModule(_m)
+ {}
+
+ __inline iterator operator++() { hContact = ::db_find_next(hContact, m_szModule); return *this; }
+ __inline bool operator!=(const iterator &p) { return hContact != p.hContact; }
+ __inline operator const MCONTACT*() const { return &hContact; }
+ };
+
+ __inline iterator begin() const { return iterator(m_szModule, ::db_find_first(m_szModule)); }
+ __inline iterator end() const { return iterator(m_szModule, 0); }
+};
+#endif
+
/////////////////////////////////////////////////////////////////////////////////////////
// Database events