14

Object

The Object class implements the base messages of the So-o model. All the other classes inherit from the Object class.

All the code for the So-o Object class is in the file Object.c.

  1. #define InvalidClassProperty "%s::%s Invalid class property"
  2. #define InvalidInstanceProperty "%s::%s Invalid instance property"
  3. #define InvalidClassMessage "%s::%s Invalid class message"
  4. #define InvalidInstanceMessage "%s::%s Invalid instance message"
  5.  
  6. #define NotImplemented "%s::%s Not implemented"
  7. #define SubclassResponsibility "%s::%s Subclass responsibility"
  8.  
  9. #define InvalidArgument "%s::%s Invalid argument"

Defines the texts of the error messages returned by the Object class.

  1. class Object;
  2.  
  3. void defclassObject() {
  4.     selector _c_messages[] = {
  5.         "get",                      METHOD(c_get),
  6.         "set",                      METHOD(c_set),
  7.         "make",                     METHOD(c_make),
  8.         "new",                      METHOD(c_new),
  9.         "initialize",               METHOD(c_initialize),
  10.         "free",                     METHOD(c_free),
  11.         "class",                    METHOD(c_class),
  12.         "name",                     METHOD(c_name),
  13.         "revision",                 METHOD(c_revision),
  14.         "superclass",               METHOD(c_superclass),
  15.         "toString",                 METHOD(c_toString),
  16.         "error",                    METHOD(c_error),
  17.         "doesNotContain",           METHOD(c_doesNotContain),
  18.         "doesNotRecognize",         METHOD(c_doesNotRecognize),
  19.         "notImplemented",           METHOD(c_notImplemented),
  20.         "subclassResponsibility",   METHOD(c_subclassResponsibility),
  21.         "invalidArgument",          METHOD(c_invalidArgument),
  22.         "classMethodFor",           METHOD(c_classMethodFor),
  23.         "instanceMethodFor",        METHOD(c_instanceMethodFor),
  24.         "classMessages",            METHOD(c_classMessages),
  25.         "instanceMessages",         METHOD(c_instanceMessages),
  26.         "classProperties",          METHOD(c_classProperties),
  27.         "instanceProperties",       METHOD(c_instanceProperties),
  28.         "addClassMessage",          METHOD(c_addClassMessage),
  29.         "removeClassMessage",       METHOD(c_removeClassMessage),
  30.         "addInstanceMessage",       METHOD(c_addInstanceMessage),
  31.         "removeInstanceMessage",    METHOD(c_removeInstanceMessage),
  32.         "addClassProperty",         METHOD(c_addClassProperty),
  33.         "removeClassProperty",      METHOD(c_removeClassProperty),
  34.         "addInstanceProperty",      METHOD(c_addInstanceProperty),
  35.         "removeInstanceProperty",   METHOD(c_removeInstanceProperty),
  36.         0, 0
  37.     };
  38.  
  39.     selector _i_messages[] = {
  40.         "get",                      METHOD(i_get),
  41.         "set",                      METHOD(i_set),
  42.         "init",                     METHOD(i_init),
  43.         "free",                     METHOD(i_free),
  44.         "class",                    METHOD(i_class),
  45.         "superclass",               METHOD(i_superclass),
  46.         "toString",                 METHOD(i_toString),
  47.         "isKindOf",                 METHOD(i_isKindOf),
  48.         "respondsTo",               METHOD(i_respondsTo),
  49.         "methodFor",                METHOD(i_methodFor),
  50.         "delegate",                 METHOD(i_delegate),
  51.         "setDelegate",              METHOD(i_setDelegate),
  52.         "getDelegate",              METHOD(i_getDelegate),
  53.         "copy",                     METHOD(i_copy),
  54.         "assume",                   METHOD(i_assume),
  55.         "print",                    METHOD(i_print),
  56.         "error",                    METHOD(i_error),
  57.         "doesNotContain",           METHOD(i_doesNotContain),
  58.         "doesNotRecognize",         METHOD(i_doesNotRecognize),
  59.         "notImplemented",           METHOD(i_notImplemented),
  60.         "subclassResponsibility",   METHOD(i_subclassResponsibility),
  61.         "subclassResponsibility",   METHOD(i_subclassResponsibility),
  62.         "invalidArgument",          METHOD(i_invalidArgument),
  63.         "messages",                 METHOD(i_messages),
  64.         "properties",               METHOD(i_properties),
  65.         0, 0
  66.     };
  67.  
  68.     Object = class_new("Object", 0, 1, 0, 0, _c_messages, _i_messages);
  69. }

Defines the class Object, a global variable. defclassObject builds the class Object and assigns the address of its container to the variable Object. NOTE: If necessary, defclass automatically calls defclassObject.

The Object class is the only class which doesn't inherit from a superclass. It doesn't have any class or instance properties. It implements all the base messages of the So-o model.

CLASS METHODS

free
SYNOPSIS

void free(class self)

DESCRIPTION

free frees the space allocated by self, i.e. all the lists allocated by the class and the container of the class.

IMPORTANT: free doesn't free the space which might be allocated for the values of the attributes of the class.

CODE
  1. static void c_free(class self) {
  2.     class_free(self);
  3. }

free calls class_free and returns nothing.

initialize
SYNOPSIS

class initialize(class self)

DESCRIPTION

initialize is automatically sent by defclass to a new class. The initialize method defined by the Object class does nothing.

initialize is usually redefined by a class which must initialize its class properties.

CODE
  1. static class c_initialize (class self) {
  2.     return self;
  3. }

initialize does nothing and returns self.

class
name
revision
superclass
SYNOPSIS

class class(class self)

char *name(class self)

int revision(class self)

class superclass(class self)

DESCRIPTION

class returns the class of the class self, i.e. self.

name returns the name of the class self.

revision returns the revision number of the class self.

superclass returns the superclass of the class self, NULL if self is Object, the Object class.

CODE
  1. static class c_class(class self) {
  2.     return self;
  3. }
  4.  
  5. static const char* c_name(class self) {
  6.     return class_name(self);
  7. }
  8.  
  9. static unsigned int c_revision(class self) {
  10.     return class_revision(self);
  11. }
  12.  
  13. static class c_superclass(class self) {
  14.     return class_superclass(self);
  15. }

class returns self. name, revision and superclass return the result of the functions class_name, class_revision and class_superclass of the Object Layer.

get
set
SYNOPSIS

value get(class self, property prop)

class set(class self, property prop, value val)

DESCRIPTION

get returns the value of the property prop of self.

set sets the value of the property prop of self to val.

CODE
  1. static value c_get(class self, va_list va) {
  2.     property prop = va_arg(va, property);
  3.  
  4.     return class_get(self, prop);
  5. }
  6.  
  7. static class c_set(class self, va_list va) {
  8.     property prop = va_arg(va, property);
  9.     value val = va_arg(va, value);
  10.  
  11.     return class_set(self, prop, val);
  12. }

get extracts the parameter prop from the argument list va and returns the result of the function class_get of the Object Layer. set extracts the parameters prop and val from the argument list va and calls the function class_set of the Object Layer which returns self.

make
new
SYNOPSIS

instance make(class self)

instance new(class self[, arg ...])

DESCRIPTION

make returns a new instance of self.

new creates an instance of self, sends it the message init with all the parameters of the message following self and returns the new initialized instance.

IMPORTANT: Always create an instance with new.

CODE
  1. static instance c_make(class self) {
  2.     return class_make(self);
  3. }
  4.  
  5. static instance c_new(class self, va_list va) {
  6.     return (instance)object_send_message_va((instance)class_send_message(self, "make").p, "init", va).p;
  7. }

make returns the result of the function class_make of the Object Layer.

new creates an instance by sending make to self, sends it init with the parameters of the message following self and returns the new instance.

toString
SYNOPSIS

char *toString(class self)

DESCRIPTION

toString returns the result of the function class_tostring of the Object Layer which returns a string representation of self, i.e. the word class followed by the name of the class between parenthesis. This method can be redefined to add a string representation of the attributes of a class.

IMPORTANT: The string is formatted in a static area. It must be used before this method is called again.

CODE
  1. static char *c_toString(class self) {
  2.     return class_tostring(self);
  3. }

toString returns the result of the function class_tostring of the Object Layer.

addClassMessage
removeClassMessage
addInstanceMessage
removeInstanceMessage
SYNOPSIS

class addClassMessage(class self, message msg, method func)

class removeClassMessage(class self, message msg)

class addInstanceMessage(class self, message msg, method func)

class removeInstanceMessage(class self, message msg)

DESCRIPTION

addClassMessage adds the class message msg with the method func to self.

removeClassMessage removes the class message msg from self.

addInstanceMessage adds the instance message msg with the method func to self.

removeInstanceMessage removes the instance message msg from self.

CODE
  1. static class c_addClassMessage(class self, va_list va) {
  2.     message msg = va_arg(va, message);
  3.     method func = va_arg(va, method);
  4.  
  5.     return class_add_class_message(self, msg, func);
  6. }
  7.  
  8. static class c_removeClassMessage(class self, va_list va) {
  9.     message msg = va_arg(va, message);
  10.  
  11.     return class_remove_class_message(self, msg);
  12. }
  13.  
  14. static class c_addInstanceMessage(class self, va_list va) {
  15.     message msg = va_arg(va, message);
  16.     method func = va_arg(va, method);
  17.  
  18.     return class_add_instance_message(self, msg, func);
  19. }
  20.  
  21. static class c_removeInstanceMessage(class self, va_list va) {
  22.     message msg = va_arg(va, message);
  23.  
  24.     return class_remove_instance_message(self, msg);
  25. }

addClassMessage and addInstanceMessage extract the parameters msg and func from the argument list va and return the result of the functions class_add_class_message and class_add_instance_message of the Object Layer. removeClassMessage and removeInstanceMessage extract the parameter msg from the argument list va and return the result of the functions class_remove_class_message and class_remove_instance_message of the Object Layer.

addClassProperty
removeClassProperty
addInstanceProperty
removeInstanceProperty
SYNOPSIS

class addClassProperty(class self, property prop)

class removeClassProperty(class self, property prop)

class addInstanceProperty(class self, property prop)

class removeInstanceProperty(class self, property prop)

DESCRIPTION

addClassProperty adds the class property prop to self.

removeClassProperty removes the class property prop from self.

addInstanceProperty adds the instance property prop to self.

removeInstanceProperty removes the instance property prop from self.

CODE
  1. static class c_addClassProperty(class self, va_list va) {
  2.     property prop = va_arg(va, property);
  3.  
  4.     return class_add_class_property(self, prop);
  5. }
  6.  
  7. static class c_removeClassProperty(class self, va_list va) {
  8.     property prop = va_arg(va, property);
  9.  
  10.     return class_remove_class_property(self, prop);
  11. }
  12.  
  13. static class c_addInstanceProperty(class self, va_list va) {
  14.     property prop = va_arg(va, property);
  15.  
  16.     return class_add_instance_property(self, prop);
  17. }
  18.  
  19. static class c_removeInstanceProperty(class self, va_list va) {
  20.     property prop = va_arg(va, property);
  21.  
  22.     return class_remove_instance_property(self, prop);
  23. }

addClassProperty, removeClassProperty, addInstanceProperty and removeInstanceProperty extract the parameter prop from the argument list va and return the result of the functions class_add_class_property, class_remove_class_property, class_add_instance_property and class_remove_instance_property of the Object Layer.

error
doesNotContain
doesNotRecognize
notImplemented
subclassResponsibility
invalidArgument
SYNOPSIS

class error(class self, char *err[, arg ...])

class doesNotContain(class self, property prop)

class doesNotRecognize(class self, message msg)

class notImplemented(class self, message msg)

class subclassResponsibility(class self, message msg)

class invalidArgument(class self, message msg)

DESCRIPTION

error prints a message on the error output flow stderr. The text of the message is formatted with the function vprintf with in argument err and the parameters of the message following err.

doesNotContain sends the message error to self with in argument the constant InvalidClassProperty, the name of the class self and the property prop.

doesNotRecognize sends the message error to self with in argument the constant InvalidClassMessage, the name of the class self and the message msg.

notImplemented sends the message error to self with in argument the constant NotImplemented, the name of the class self and the message msg.

subclassResponsibility sends the message error to self with in argument the constant SubclassResponsibility, the name of the class self and the message msg.

invalidArgument sends the message error to self with in argument the constant InvalidArgument, the name of the class self and the message msg.

doesNotContain and doesNotRecognize are sent by the Object Layer. notImplemented is generally sent by a method which isn't coded yet while subclassResponsibility is sent by a method which must be implemented by a subclass of an abstract class. invalidArgument is sent by a method which was passed a wrong argument.

CODE
  1. static class c_error (class self, va_list va) {
  2.     const char *err = va_arg(va, char *);
  3.  
  4.     vfprintf(stderr, err, va);
  5.  
  6.     fprintf(stderr, "\n");
  7.  
  8.     return self;
  9. }
  10.  
  11. static class c_doesNotContain(class self, va_list va) {
  12.     message msg = va_arg(va, message);
  13.  
  14.     class_send_message(self, "error", InvalidClassProperty, class_name(self), msg);
  15.  
  16.     return self;
  17. }
  18.  
  19. static class c_doesNotRecognize(class self, va_list va) {
  20.     message msg = va_arg(va, message);
  21.  
  22.     class_send_message(self, "error", InvalidClassMessage, class_name(self), msg);
  23.  
  24.     return self;
  25. }
  26.  
  27. static class c_notImplemented(class self, va_list va) {
  28.     message msg = va_arg(va, message);
  29.  
  30.     class_send_message(self, "error", NotImplemented, class_name(self), msg);
  31.  
  32.     return self;
  33. }
  34.  
  35. static class c_subclassResponsibility(class self, va_list va) {
  36.     message msg = va_arg(va, message);
  37.  
  38.     class_send_message(self, "error", SubclassResponsibility, class_name(self), msg);
  39.  
  40.     return self;
  41. }
  42.  
  43. static class c_invalidArgument(class self, va_list va) {
  44.     message msg = va_arg(va, message);
  45.  
  46.     class_send_message(self, "error", InvalidArgument, class_name(self), msg);
  47.  
  48.     return self;
  49. }

error extracts the parameter err from the argument list va and prints the error message err formatted with the rest of the arguments following err with vprintf then prints a newline. doesNotContain, doesNotRecognize, notImplemented, subclassResponsibility and invalidArgument extract the parameter msg from the argument list va and send the message error to self with in argument the constant of the corresponding error message and its parameters.

classMethodFor
instanceMethodFor
SYNOPSIS

method classMethodFor(class self, message msg)

method instanceMethodFor(class self, message msg)

DESCRIPTION

classMethodFor returns the function which implements the class message msg of self.

instanceMethodFor returns the function which implements the instance message msg of self.

CODE
  1. static method c_classMethodFor(class self, va_list va) {
  2.     message msg = va_arg(va, message);
  3.  
  4.     return class_find_class_method(self, msg);
  5. }
  6.  
  7. static method c_instanceMethodFor(class self, va_list va) {
  8.     message msg = va_arg(va, message);
  9.  
  10.     return class_find_instance_method(self, msg);
  11. }

classMethodFor and instanceMethodFor extract the parameter msg from the argument list va and return the result of the functions class_find_class_method and class_find_instance_method of the Object Layer.

classMessages
instanceMessages
classProperties
instanceProperties
SYNOPSIS

message *classMessages(class self, int inherit)

message *instanceMessages(class self, int inherit)

property *classProperties(class self, int inherit)

property *instanceProperties(class self, int inherit)

DESCRIPTION

classMessages returns the class messages of self in an array terminated by a '\0'. If inherit is different from 0, classMessages also returns the class messages inherited from all the superclasses of self.

instanceMessages returns the instance messages of self in an array terminated by a '\0'. If inherit is different from 0, instanceMessages also returns the instance messages inherited from all the superclasses of self.

classProperties returns the class properties of self in an array terminated by a '\0'. If inherit is different from 0, classProperties also returns the class properties inherited from all the superclasses of self.

instanceProperties returns the instance properties of self in an array terminated by a '\0'. If inherit is different from 0, classProperties also returns the class properties inherited from all the superclasses of self.

IMPORTANT: The array returned by these functions is allocated and must be freed.

CODE
  1. static message *c_classMessages(class self, va_list va) {
  2.     int inherit = va_arg(va, int);
  3.  
  4.     alist ml = alist_new();
  5.     class c = self;
  6.  
  7.     do {
  8.         alist msglist = class_class_messages(c);
  9.  
  10.         if (msglist)
  11.             alist_merge(ml, msglist);
  12.  
  13.         if (!inherit)
  14.             break;
  15.  
  16.         c = class_superclass(c);
  17.     }
  18.     while (c);
  19.  
  20.     message *msgs = (message *)alist_keys(ml);
  21.  
  22.     alist_free(ml);
  23.  
  24.     return msgs;
  25. }
  26.  
  27. static message *c_instanceMessages(class self, va_list va) {
  28.     int inherit = va_arg(va, int);
  29.  
  30.     alist ml = alist_new();
  31.     class c = self;
  32.  
  33.     do {
  34.         alist msglist = class_instance_messages(c);
  35.  
  36.         if (msglist)
  37.             alist_merge(ml, msglist);
  38.  
  39.         if (!inherit)
  40.             break;
  41.  
  42.         c = class_superclass(c);
  43.     }
  44.     while (c);
  45.  
  46.     message *msgs = (message *)alist_keys(ml);
  47.  
  48.     alist_free(ml);
  49.  
  50.     return msgs;
  51. }

classMessages and instanceMessagees extract the parameter inherit from the argument list va. The associative list ml is used to hold temporarily all the collected messages. They proceed by merging the class or the instance messages of self in ml, and, if inherit is different from 0, all the class or the instance messages of the superclasses of self. They return the array allocated by alist_keys with ml in argument.

  1. static property *c_classProperties(class self, va_list va) {
  2.     int inherit = va_arg(va, int);
  3.  
  4.     list pl = list_new();
  5.     class c = self;
  6.  
  7.     do {
  8.         list proplist = class_class_properties(c);
  9.  
  10.         if (proplist)
  11.             list_merge(pl, proplist);
  12.  
  13.         if (!inherit)
  14.             break;
  15.  
  16.         c = class_superclass(c);
  17.     }
  18.     while (c);
  19.  
  20.     property *props = (property *)list_values(pl);
  21.  
  22.     list_free(pl);
  23.  
  24.     return props;
  25. }
  26.  
  27. static property *c_instanceProperties(class self, va_list va) {
  28.     int inherit = va_arg(va, int);
  29.  
  30.     list pl = list_new();
  31.     class c = self;
  32.  
  33.     do {
  34.         list proplist = class_instance_properties(c);
  35.  
  36.         if (proplist)
  37.             list_merge(pl, proplist);
  38.  
  39.         if (!inherit)
  40.             break;
  41.  
  42.         c = class_superclass(c);
  43.     }
  44.     while (c);
  45.  
  46.     property *props = (property *)list_values(pl);
  47.  
  48.     list_free(pl);
  49.  
  50.     return props;
  51. }

classProperties and instanceProperties extract the parameter inherit from the argument list va. The list pl is used to hold all the collected properties. They proceed by merging the class or the instance properties of self in pl, and, if inherit is different from 0, all the class or the instance properties of the superclasses of self. They return the array allocated by list_values with pl in argument.

INSTANCE METHODS

free
SYNOPSIS

void free(instance self)

DESCRIPTION

free frees the space allocated by self, i.e. the list of attributes allocated by the instance and the container of the instance.

IMPORTANT: free doesn't free the space which might be allocated for the values of the attributes of the instance.

CODE
  1. static void i_free(instance self) {
  2.     object_free(self);
  3. }

free calls object_free and returns nothing.

init
SYNOPSIS

instance init(instance self[, arg ...])

DESCRIPTION

init is automatically sent by new to a new instance. The init method defined by the Object class does nothing.

init is usually redefined by a class which must initialize its instance properties.

CODE
  1. static instance i_init(instance self, va_list va) {
  2.     return self;
  3. }

init does nothing and returns self.

class
superclass
SYNOPSIS

class class(instance self)

class superclass(instance self)

DESCRIPTION

class returns the class of self.

superclass returns the superclass of the class of self, NULL if self is an instance of the Object class.

CODE
  1. static class i_class(instance self) {
  2.     return object_class(self);
  3. }
  4.  
  5. static class i_superclass(instance self) {
  6.     return class_superclass(object_class(self));
  7. }

class returns the result of the function object_class of the Object Layer. superclass returns the result of the function class_superclass with the class of self in argument.

assume
isKindOf
methodFor
respondsTo
SYNOPSIS

instance assume(instance self, class c)

int isKindOf(instance self, class c)

method methodFor(instance self, message msg)

int respondsTo(instance self,message msg)

DESCRIPTION

assume changes the class of self to c. The values of the properties of the former class of self which are not part of the class class are preserved but they are not accessible.

isKindOf returns 1 if self is an instance of the class or a subclass of c or 0 if not.

methodFor returns the function which implements the message msg for self or NULL if self doesn't respond to msg.

respondsTo returns 1 if self has a method for the message message, 0 if not.

CODE
  1. static instance i_assume(instance self, va_list va) {
  2.     class c = va_arg(va, class);
  3.  
  4.     return object_assume(self, c);
  5. }
  6.  
  7. static int i_isKindOf(instance self, va_list va) {
  8.     class c = va_arg(va, class);
  9.  
  10.     return class_is_kind_of(object_class(self), c);
  11. }
  12.  
  13. static method i_methodFor(instance self, va_list va) {
  14.     message msg = va_arg(va, message);
  15.  
  16.     return class_find_instance_method(object_class(self), msg);
  17. }
  18.  
  19. static int i_respondsTo(instance self, va_list va) {
  20.     return i_methodFor(self, va) ? 1 : 0;
  21. }

assume extracts the class c from the argument list va and calls the function object_assume of the Object Layer with c in argument. isKindOf extracts the class c c from the argument list va and returns the result of the function class_is_kind_of of the Object Layer with in argument the class of self and c. methodFor extracts the parameter msg from the argument list va and returns the result of the function class_find_instance_method of the Object Layer with in argument the class of self and msg. respondsTo extracts the parameter msg from the argument list va and returns 1 if the result of the function class_find_instance_method of the Object Layer with in argument the class of self and msg isn't NULL, 0 otherwise.

get
set
SYNOPSIS

value get(instance self, property prop)

instance set(instance self, property prop, value val)

DESCRIPTION

get returns the value of the property prop of self.

set sets the value of the property prop of self to val.

If prop isn't a property of self, the message doesNotContain is sent to self with prop in argument.

CODE
  1. static value i_get(instance self, va_list va) {
  2.     property prop = va_arg(va, property);
  3.  
  4.     return object_get(self, prop);
  5. }
  6.  
  7. static instance i_set(instance self, va_list va) {
  8.     property prop = va_arg(va, property);
  9.     value val = va_arg(va, value);
  10.  
  11.     return object_set(self, prop, val);
  12. }

get extracts the parameter prop from the argument list va and returns the result of the function object_get of the Object Layer with in argument prop.

set extracts the parameters prop and val from the argument list va returns the result of the function object_set of the Object Layer with in argument prop and val.

copy
SYNOPSIS

instance copy(instance self)

DESCRIPTION

copy returns a copy of self.

IMPORTANT: copy doesn't copy the space which might be allocated for the values of the attributes of the instance.

CODE
  1. static instance i_copy(instance self) {
  2.     return object_copy(self);
  3. }

copy returns the result of the function copy of the Object Layer.

toString
SYNOPSIS

char *toString(instance self)

DESCRIPTION

toString returns the result of the function object_tostring of the Object Layer which returns a string representation of self, i.e. the word object followed by the name of the instance between parenthesis. This method can be redefined to add a string representation of the attributes of an instance.

IMPORTANT: The string is formatted in a static area. It must be used before this method is called again.

CODE
  1. static char *i_toString(instance self) {
  2.     return object_tostring(self);
  3. }

toString returns the result of the function object_tostring of the Object Layer.

print
SYNOPSIS

instance print(instance self, int eol)

DESCRIPTION

print writes the readable representation of self to the standard output. If eol isn't 0, print adds a newline.

  1. static instance i_print(instance self, va_list va) {
  2.     int eol = va_arg(va, int);
  3.  
  4.     printf("%s", (char *)object_send_message(self, "toString").p);
  5.  
  6.     if (eol)
  7.         printf("\n");
  8.  
  9.     return self;
  10. }

print extracts the parameter eol from the argument list va, writes the result of sending the message toString to self to the standard output and, if eol isn't 0, adds a newline.

delegate
setDelegate
getDelegate
SYNOPSIS

value delegate(instance self, message msg[, arg ...])

instance setDelegate(instance self, instance delegate)

instance getDelegate(instance self)

DESCRIPTION

delegate returns the result of sending the message msg and its arguments arg following msg to the delegate of self. If self doesn't have a delegate or if the delegate of self doesn't respond to the message msg, delegate returns 0.

setDelegate sets the attribute delegate of self to delegate.

getDelegate returns the delegate of self.

NOTE: Sending delegate, setDelegate or getDelegate to an instance which does have the property delegate sends the message doesNotContain to the instance.

CODE
  1. static value i_delegate(instance self, va_list va) {
  2.     instance delegate=object_get(self, "delegate").p;
  3.  
  4.     if (!delegate) {
  5.         return (value)0;
  6.     }
  7.  
  8.     message msg = va_arg(va, message);
  9.  
  10.     if (!object_send_message(delegate, "respondsTo", msg).i) {
  11.         return (value)0;
  12.     }
  13.  
  14.     return object_send_message_va(delegate, msg, va);
  15. }
  16.  
  17. static instance i_setDelegate(instance self, va_list va) {
  18.     instance delegate = va_arg(va, instance);
  19.  
  20.     return object_set(self, "delegate", (value)((void *)delegate));
  21. }
  22.  
  23. static instance i_getDelegate(instance self) {
  24.     return object_get(self, "delegate").p;
  25. }

delegate initializes delegate to the value of the property delegate of self. If delegate is NULL, returns 0. Extracts the parameter msg of the list of arguments va. If delegate doesn't respond to msg, returns 0. Otherwise, returns the result of sending msg with its arguments to delegate.

setDelegate extracts the parameter delegate from the list of arguments va and assigns it to the property delegate of self. getDelegate returns the value of the property delegate of self .

error
doesNotContain
doesNotRecognize
notImplemented
subclassResponsibility
invalidArgument
SYNOPSIS

instance error(instance self, char *err[, arg ...])

instance doesNotContain(instance self, property prop)

instance doesNotRecognize(instance self, message msg)

instance notImplemented(instance self, message msg)

instance subclassResponsibility(instance self, message msg)

instance invalidArgument(instance self, message msg)

DESCRIPTION

error prints a message on the error output flow stderr. The text of the message is formatted with the function vprintf with in argument err and the parameters of the message following err.

doesNotContain sends the message error to self with in argument the constant InvalidInstanceProperty, the name of the class of self and the property prop.

doesNotRecognize sends the message error to self with in argument the constant InvalidInstanceMessage, the name of the class of self and the message msg.

notImplemented sends the message error to self with in argument the constant NotImplemented, the name of the class of self and the message msg.

subclassResponsibility sends the message error to self with in argument the constant SubclassResponsibility, the name of the class of self and the message msg.

invalidArgument sends the message error to self with in argument the constant InvalidArgument, the name of the class of self and the message msg.

doesNotContain and doesNotRecognize are sent by the Object Layer. notImplemented is generally sent by a method which isn't coded yet while subclassResponsibility is sent by a method which must be implemented by a subclass of an abstract class. invalidArgument is sent by a method which was passed a wrong argument.

CODE
  1. static instance i_error (instance self, va_list va) {
  2.     char *err = va_arg(va, char *);
  3.  
  4.     vfprintf(stderr, err, va);
  5.  
  6.     fprintf(stderr, "\n");
  7.  
  8.     return self;
  9. }
  10.  
  11. static instance i_doesNotContain(instance self, va_list va) {
  12.     message msg = va_arg(va, message);
  13.  
  14.     object_send_message(self, "error", InvalidInstanceProperty, class_name(object_class(self)), msg);
  15.  
  16.     return self;
  17. }
  18.  
  19. static instance i_doesNotRecognize(instance self, va_list va) {
  20.     message msg = va_arg(va, message);
  21.  
  22.     object_send_message(self, "error", InvalidInstanceMessage, class_name(object_class(self)), msg);
  23.  
  24.     return self;
  25. }
  26.  
  27. static instance i_notImplemented(instance self, va_list va) {
  28.     message msg = va_arg(va, message);
  29.  
  30.     object_send_message(self, "error", NotImplemented, class_name(object_class(self)), msg);
  31.  
  32.     return self;
  33. }
  34.  
  35. static instance i_subclassResponsibility(instance self, va_list va) {
  36.     message msg = va_arg(va, message);
  37.  
  38.     object_send_message(self, "error", SubclassResponsibility, class_name(object_class(self)), msg);
  39.  
  40.     return self;
  41. }
  42.  
  43. static instance i_invalidArgument(instance self, va_list va) {
  44.     message msg = va_arg(va, message);
  45.  
  46.     object_send_message(self, "error", InvalidArgument, class_name(object_class(self)), msg);
  47.  
  48.     return self;
  49. }

error extracts the parameter err from the argument list va and prints the error message err formatted with the rest of the arguments following err with vprintf then prints a newline.

doesNotContain, doesNotRecognize, notImplemented, subclassResponsibility and invalidArgument extract the parameter msg from the argument list va and send the message error to self with in argument the constant of the corresponding error message and its parameters.

messages
properties
SYNOPSIS

message *messages(instance self, int inherit)

property *properties(instance self, int inherit)

DESCRIPTION

messages returns the messages recognized by self in an array terminated by a '\0'. If inherit is different from 0, messages also returns the messages inherited from all the superclasses of self.

properties returns the properties of self in an array terminated by a '\0'. If inherit is different from 0, properties also returns the properties inherited from all the superclasses of self.

IMPORTANT: The array returned by these functions is allocated and must be freed.

CODE
  1. static message *i_messages(instance self, va_list va) {
  2.     return class_send_message_va(object_class(self), "instanceMessages", va).p;
  3. }
  4.  
  5. static property *i_properties(instance self, va_list va) {
  6.     return class_send_message_va(object_class(self), "instanceProperties", va).p;
  7. }

messages sends the message instanceMessages to the class of self with inherit in argument. properties sends the message instanceProperties to the class of self with inherit in argument.

SEE ALSO

Interface, Object Layer

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].