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.
- #define InvalidClassProperty "%s::%s Invalid class property"
- #define InvalidInstanceProperty "%s::%s Invalid instance property"
- #define InvalidClassMessage "%s::%s Invalid class message"
- #define InvalidInstanceMessage "%s::%s Invalid instance message"
- #define NotImplemented "%s::%s Not implemented"
- #define SubclassResponsibility "%s::%s Subclass responsibility"
- #define InvalidArgument "%s::%s Invalid argument"
Defines the texts of the error messages returned by the Object class.
- class Object;
- void defclassObject() {
- selector _c_messages[] = {
- "get", METHOD(c_get),
- "set", METHOD(c_set),
- "make", METHOD(c_make),
- "new", METHOD(c_new),
- "initialize", METHOD(c_initialize),
- "free", METHOD(c_free),
- "class", METHOD(c_class),
- "name", METHOD(c_name),
- "revision", METHOD(c_revision),
- "superclass", METHOD(c_superclass),
- "toString", METHOD(c_toString),
- "error", METHOD(c_error),
- "doesNotContain", METHOD(c_doesNotContain),
- "doesNotRecognize", METHOD(c_doesNotRecognize),
- "notImplemented", METHOD(c_notImplemented),
- "subclassResponsibility", METHOD(c_subclassResponsibility),
- "invalidArgument", METHOD(c_invalidArgument),
- "classMethodFor", METHOD(c_classMethodFor),
- "instanceMethodFor", METHOD(c_instanceMethodFor),
- "classMessages", METHOD(c_classMessages),
- "instanceMessages", METHOD(c_instanceMessages),
- "classProperties", METHOD(c_classProperties),
- "instanceProperties", METHOD(c_instanceProperties),
- "addClassMessage", METHOD(c_addClassMessage),
- "removeClassMessage", METHOD(c_removeClassMessage),
- "addInstanceMessage", METHOD(c_addInstanceMessage),
- "removeInstanceMessage", METHOD(c_removeInstanceMessage),
- "addClassProperty", METHOD(c_addClassProperty),
- "removeClassProperty", METHOD(c_removeClassProperty),
- "addInstanceProperty", METHOD(c_addInstanceProperty),
- "removeInstanceProperty", METHOD(c_removeInstanceProperty),
- 0, 0
- };
- selector _i_messages[] = {
- "get", METHOD(i_get),
- "set", METHOD(i_set),
- "init", METHOD(i_init),
- "free", METHOD(i_free),
- "class", METHOD(i_class),
- "superclass", METHOD(i_superclass),
- "toString", METHOD(i_toString),
- "isKindOf", METHOD(i_isKindOf),
- "respondsTo", METHOD(i_respondsTo),
- "methodFor", METHOD(i_methodFor),
- "delegate", METHOD(i_delegate),
- "setDelegate", METHOD(i_setDelegate),
- "getDelegate", METHOD(i_getDelegate),
- "copy", METHOD(i_copy),
- "assume", METHOD(i_assume),
- "print", METHOD(i_print),
- "error", METHOD(i_error),
- "doesNotContain", METHOD(i_doesNotContain),
- "doesNotRecognize", METHOD(i_doesNotRecognize),
- "notImplemented", METHOD(i_notImplemented),
- "subclassResponsibility", METHOD(i_subclassResponsibility),
- "subclassResponsibility", METHOD(i_subclassResponsibility),
- "invalidArgument", METHOD(i_invalidArgument),
- "messages", METHOD(i_messages),
- "properties", METHOD(i_properties),
- 0, 0
- };
- Object = class_new("Object", 0, 1, 0, 0, _c_messages, _i_messages);
- }
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
- static void c_free(class self) {
- class_free(self);
- }
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
- static class c_initialize (class self) {
- return self;
- }
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
- static class c_class(class self) {
- return self;
- }
- static const char* c_name(class self) {
- return class_name(self);
- }
- static unsigned int c_revision(class self) {
- return class_revision(self);
- }
- static class c_superclass(class self) {
- return class_superclass(self);
- }
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
- static value c_get(class self, va_list va) {
- property prop = va_arg(va, property);
- return class_get(self, prop);
- }
- static class c_set(class self, va_list va) {
- property prop = va_arg(va, property);
- value val = va_arg(va, value);
- return class_set(self, prop, val);
- }
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
- static instance c_make(class self) {
- return class_make(self);
- }
- static instance c_new(class self, va_list va) {
- return (instance)object_send_message_va((instance)class_send_message(self, "make").p, "init", va).p;
- }
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
- static char *c_toString(class self) {
- return class_tostring(self);
- }
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
- static class c_addClassMessage(class self, va_list va) {
- message msg = va_arg(va, message);
- method func = va_arg(va, method);
- return class_add_class_message(self, msg, func);
- }
- static class c_removeClassMessage(class self, va_list va) {
- message msg = va_arg(va, message);
- return class_remove_class_message(self, msg);
- }
- static class c_addInstanceMessage(class self, va_list va) {
- message msg = va_arg(va, message);
- method func = va_arg(va, method);
- return class_add_instance_message(self, msg, func);
- }
- static class c_removeInstanceMessage(class self, va_list va) {
- message msg = va_arg(va, message);
- return class_remove_instance_message(self, msg);
- }
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
- static class c_addClassProperty(class self, va_list va) {
- property prop = va_arg(va, property);
- return class_add_class_property(self, prop);
- }
- static class c_removeClassProperty(class self, va_list va) {
- property prop = va_arg(va, property);
- return class_remove_class_property(self, prop);
- }
- static class c_addInstanceProperty(class self, va_list va) {
- property prop = va_arg(va, property);
- return class_add_instance_property(self, prop);
- }
- static class c_removeInstanceProperty(class self, va_list va) {
- property prop = va_arg(va, property);
- return class_remove_instance_property(self, prop);
- }
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
- static class c_error (class self, va_list va) {
- const char *err = va_arg(va, char *);
- vfprintf(stderr, err, va);
- fprintf(stderr, "\n");
- return self;
- }
- static class c_doesNotContain(class self, va_list va) {
- message msg = va_arg(va, message);
- class_send_message(self, "error", InvalidClassProperty, class_name(self), msg);
- return self;
- }
- static class c_doesNotRecognize(class self, va_list va) {
- message msg = va_arg(va, message);
- class_send_message(self, "error", InvalidClassMessage, class_name(self), msg);
- return self;
- }
- static class c_notImplemented(class self, va_list va) {
- message msg = va_arg(va, message);
- class_send_message(self, "error", NotImplemented, class_name(self), msg);
- return self;
- }
- static class c_subclassResponsibility(class self, va_list va) {
- message msg = va_arg(va, message);
- class_send_message(self, "error", SubclassResponsibility, class_name(self), msg);
- return self;
- }
- static class c_invalidArgument(class self, va_list va) {
- message msg = va_arg(va, message);
- class_send_message(self, "error", InvalidArgument, class_name(self), msg);
- return self;
- }
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
- static method c_classMethodFor(class self, va_list va) {
- message msg = va_arg(va, message);
- return class_find_class_method(self, msg);
- }
- static method c_instanceMethodFor(class self, va_list va) {
- message msg = va_arg(va, message);
- return class_find_instance_method(self, msg);
- }
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
- static message *c_classMessages(class self, va_list va) {
- int inherit = va_arg(va, int);
- alist ml = alist_new();
- class c = self;
- do {
- alist msglist = class_class_messages(c);
- if (msglist)
- alist_merge(ml, msglist);
- if (!inherit)
- break;
- c = class_superclass(c);
- }
- while (c);
- message *msgs = (message *)alist_keys(ml);
- alist_free(ml);
- return msgs;
- }
- static message *c_instanceMessages(class self, va_list va) {
- int inherit = va_arg(va, int);
- alist ml = alist_new();
- class c = self;
- do {
- alist msglist = class_instance_messages(c);
- if (msglist)
- alist_merge(ml, msglist);
- if (!inherit)
- break;
- c = class_superclass(c);
- }
- while (c);
- message *msgs = (message *)alist_keys(ml);
- alist_free(ml);
- return msgs;
- }
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.
- static property *c_classProperties(class self, va_list va) {
- int inherit = va_arg(va, int);
- list pl = list_new();
- class c = self;
- do {
- list proplist = class_class_properties(c);
- if (proplist)
- list_merge(pl, proplist);
- if (!inherit)
- break;
- c = class_superclass(c);
- }
- while (c);
- property *props = (property *)list_values(pl);
- list_free(pl);
- return props;
- }
- static property *c_instanceProperties(class self, va_list va) {
- int inherit = va_arg(va, int);
- list pl = list_new();
- class c = self;
- do {
- list proplist = class_instance_properties(c);
- if (proplist)
- list_merge(pl, proplist);
- if (!inherit)
- break;
- c = class_superclass(c);
- }
- while (c);
- property *props = (property *)list_values(pl);
- list_free(pl);
- return props;
- }
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
- static void i_free(instance self) {
- object_free(self);
- }
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
- static instance i_init(instance self, va_list va) {
- return self;
- }
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
- static class i_class(instance self) {
- return object_class(self);
- }
- static class i_superclass(instance self) {
- return class_superclass(object_class(self));
- }
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
- static instance i_assume(instance self, va_list va) {
- class c = va_arg(va, class);
- return object_assume(self, c);
- }
- static int i_isKindOf(instance self, va_list va) {
- class c = va_arg(va, class);
- return class_is_kind_of(object_class(self), c);
- }
- static method i_methodFor(instance self, va_list va) {
- message msg = va_arg(va, message);
- return class_find_instance_method(object_class(self), msg);
- }
- static int i_respondsTo(instance self, va_list va) {
- return i_methodFor(self, va) ? 1 : 0;
- }
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
- static value i_get(instance self, va_list va) {
- property prop = va_arg(va, property);
- return object_get(self, prop);
- }
- static instance i_set(instance self, va_list va) {
- property prop = va_arg(va, property);
- value val = va_arg(va, value);
- return object_set(self, prop, val);
- }
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
- static instance i_copy(instance self) {
- return object_copy(self);
- }
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
- static char *i_toString(instance self) {
- return object_tostring(self);
- }
toString
returns the result of the function object_tostring
of the Object Layer.
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.
- static instance i_print(instance self, va_list va) {
- int eol = va_arg(va, int);
- printf("%s", (char *)object_send_message(self, "toString").p);
- if (eol)
- printf("\n");
- return self;
- }
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
- static value i_delegate(instance self, va_list va) {
- instance delegate=object_get(self, "delegate").p;
- if (!delegate) {
- return (value)0;
- }
- message msg = va_arg(va, message);
- if (!object_send_message(delegate, "respondsTo", msg).i) {
- return (value)0;
- }
- return object_send_message_va(delegate, msg, va);
- }
- static instance i_setDelegate(instance self, va_list va) {
- instance delegate = va_arg(va, instance);
- return object_set(self, "delegate", (value)((void *)delegate));
- }
- static instance i_getDelegate(instance self) {
- return object_get(self, "delegate").p;
- }
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
- static instance i_error (instance self, va_list va) {
- char *err = va_arg(va, char *);
- vfprintf(stderr, err, va);
- fprintf(stderr, "\n");
- return self;
- }
- static instance i_doesNotContain(instance self, va_list va) {
- message msg = va_arg(va, message);
- object_send_message(self, "error", InvalidInstanceProperty, class_name(object_class(self)), msg);
- return self;
- }
- static instance i_doesNotRecognize(instance self, va_list va) {
- message msg = va_arg(va, message);
- object_send_message(self, "error", InvalidInstanceMessage, class_name(object_class(self)), msg);
- return self;
- }
- static instance i_notImplemented(instance self, va_list va) {
- message msg = va_arg(va, message);
- object_send_message(self, "error", NotImplemented, class_name(object_class(self)), msg);
- return self;
- }
- static instance i_subclassResponsibility(instance self, va_list va) {
- message msg = va_arg(va, message);
- object_send_message(self, "error", SubclassResponsibility, class_name(object_class(self)), msg);
- return self;
- }
- static instance i_invalidArgument(instance self, va_list va) {
- message msg = va_arg(va, message);
- object_send_message(self, "error", InvalidArgument, class_name(object_class(self)), msg);
- return self;
- }
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
- static message *i_messages(instance self, va_list va) {
- return class_send_message_va(object_class(self), "instanceMessages", va).p;
- }
- static property *i_properties(instance self, va_list va) {
- return class_send_message_va(object_class(self), "instanceProperties", va).p;
- }
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.
Comments