Artifact 67fc62df327a8de5e29deb5accbe7d527de6ce145a9558578bacf05264f44bb9:
- File
src/runtime/protocol.m
— part of check-in
[2a27cf3000]
at
2016-01-03 00:41:26
on branch trunk
— Update copyright
While at it, also update the mail address. (user: js, size: 1946) [annotate] [blame] [check-ins using] [more...]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #import "runtime.h" #import "runtime-private.h" @implementation Protocol @end const char* protocol_getName(Protocol *p) { return p->name; } bool protocol_isEqual(Protocol *a, Protocol *b) { return (strcmp(protocol_getName(a), protocol_getName(b)) == 0); } bool protocol_conformsToProtocol(Protocol *a, Protocol *b) { struct objc_protocol_list *pl; size_t i; if (protocol_isEqual(a, b)) return true; for (pl = a->protocol_list; pl != NULL; pl = pl->next) for (i = 0; i < pl->count; i++) if (protocol_conformsToProtocol(pl->list[i], b)) return true; return false; } bool class_conformsToProtocol(Class cls, Protocol *p) { struct objc_protocol_list *pl; struct objc_category **cats; long i, j; for (pl = cls->protocols; pl != NULL; pl = pl->next) for (i = 0; i < pl->count; i++) if (protocol_conformsToProtocol(pl->list[i], p)) return true; objc_global_mutex_lock(); if ((cats = objc_categories_for_class(cls)) == NULL) { objc_global_mutex_unlock(); return false; } for (i = 0; cats[i] != NULL; i++) { for (pl = cats[i]->protocols; pl != NULL; pl = pl->next) { for (j = 0; j < pl->count; j++) { if (protocol_conformsToProtocol( pl->list[j], p)) { objc_global_mutex_unlock(); return true; } } } } objc_global_mutex_unlock(); return false; }