Add mechanism for gdl2.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29866 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-03-07 13:35:07 +00:00
parent 95ced52af1
commit 53165d0baf
3 changed files with 114 additions and 24 deletions

View file

@ -757,30 +757,6 @@ GSProtocolFromName(const char *name)
}
/**
* <p>A Behavior can be seen as a "Protocol with an implementation" or a
* "Class without any instance variables". A key feature of behaviors
* is that they give a degree of multiple inheritance.
* </p>
* <p>Behavior methods, when added to a class, override the class's
* superclass methods, but not the class's methods.
* </p>
* <p>It's not the case that a class adding behaviors from another class
* must have "no instance vars". The receiver class just has to have the
* same layout as the behavior class (optionally with some additional
* ivars after those of the behavior class).
* </p>
* <p>This function provides Behaviors without adding any new syntax to
* the Objective C language. Simply define a class with the methods you
* want to add, then call this function with that class as the behavior
* argument.
* </p>
* <p>This function should be called in the +initialize method of the receiver.
* </p>
* <p>If you add several behaviors to a class, be aware that the order of
* the additions is significant.
* </p>
*/
void
GSObjCAddClassBehavior(Class receiver, Class behavior)
{
@ -853,6 +829,55 @@ GSObjCAddClassBehavior(Class receiver, Class behavior)
GSFlushMethodCacheForClass (receiver);
}
void
GSObjCAddClassOverride(Class receiver, Class override)
{
unsigned int count;
Method *methods;
if (YES == class_isMetaClass(receiver))
{
fprintf(stderr, "Trying to add override (%s) to meta class (%s)\n",
class_getName(override), class_getName(receiver));
abort();
}
if (YES == class_isMetaClass(override))
{
fprintf(stderr, "Trying to add meta class as override (%s) to (%s)\n",
class_getName(override), class_getName(receiver));
abort();
}
if (class_getInstanceSize(receiver) < class_getInstanceSize(override))
{
fprintf(stderr, "Trying to add override (%s) with instance "
"size larger than class (%s)\n",
class_getName(override), class_getName(receiver));
abort();
}
BDBGPrintf("Adding override to class %s\n", class_getName(receiver));
BDBGPrintf(" instance methods from %s\n", class_getName(override));
/* Add instance methods */
methods = class_copyMethodList(override, &count);
if (methods != NULL)
{
GSObjCAddMethods (receiver, methods, YES);
free(methods);
}
/* Add class methods */
BDBGPrintf("Adding class methods from %s\n",
class_getName(object_getClass(override)));
methods = class_copyMethodList(object_getClass(override), &count);
if (methods != NULL)
{
GSObjCAddMethods (object_getClass(receiver), methods, YES);
free(methods);
}
GSFlushMethodCacheForClass (receiver);
}