From db57a973534f099af2b150f1a1307d1948553d9f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 19 Mar 2017 12:55:36 +0100 Subject: Add typed identity to manager modules and stream flags --- xmpp-vala/src/core/xmpp_stream.vala | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'xmpp-vala/src/core') diff --git a/xmpp-vala/src/core/xmpp_stream.vala b/xmpp-vala/src/core/xmpp_stream.vala index 57eafe45..f3be115d 100644 --- a/xmpp-vala/src/core/xmpp_stream.vala +++ b/xmpp-vala/src/core/xmpp_stream.vala @@ -101,11 +101,14 @@ public class XmppStream { flags.add(flag); } - public XmppStreamFlag? get_flag(string ns, string id) { + public bool has_flag(FlagIdentity? identity) { + return get_flag(identity) != null; + } + + public T? get_flag(FlagIdentity? identity) { + if (identity == null) return null; foreach (var flag in flags) { - if (flag.get_ns() == ns && flag.get_id() == id) { - return flag; - } + if (identity.matches(flag)) return identity.cast(flag); } return null; } @@ -225,6 +228,24 @@ public class XmppStream { } } +public class FlagIdentity : Object { + public string ns { get; private set; } + public string id { get; private set; } + + public FlagIdentity(string ns, string id) { + this.ns = ns; + this.id = id; + } + + public T? cast(XmppStreamFlag module) { + return (T?) module; + } + + public bool matches(XmppStreamFlag module) { + return module.get_ns() == ns && module.get_id() == id; + } +} + public abstract class XmppStreamFlag { public abstract string get_ns(); public abstract string get_id(); -- cgit v1.2.3-54-g00ecf