summaryrefslogtreecommitdiff
path: root/include
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
parent5046973a41e412afd06d6a78a3b9bce226e3cf50 (diff)
always hated these long expressions: contact_iter makes them much shorter
Diffstat (limited to 'include')
-rw-r--r--include/m_database.h31
-rw-r--r--include/m_protoint.h2
2 files changed, 33 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
diff --git a/include/m_protoint.h b/include/m_protoint.h
index 5a7e115a74..e9477ce530 100644
--- a/include/m_protoint.h
+++ b/include/m_protoint.h
@@ -169,6 +169,8 @@ public:
__forceinline void setWString(const char *name, const wchar_t* value) { db_set_ws(NULL, m_szModuleName, name, value); }
__forceinline void setWString(MCONTACT hContact, const char *name, const wchar_t* value) { db_set_ws(hContact, m_szModuleName, name, value); }
+ __forceinline contact_iter acc_contact_iter() const { return contact_iter(m_szModuleName); }
+
//////////////////////////////////////////////////////////////////////////////////////
// Service functions