Once
- Object
- Once
A Once class creates only one instance.
- #include "So-o.h"
- class Once;
Loads the declarations of the data types and functions of So-o. Defines the class Once.
- void defclassOnce() {
- property _c_properties[] = {
- "instance",
- 0
- };
- selector _c_messages[] = {
- "new", METHOD(c_new),
- 0, 0
- };
- Once = defclass("Once", 0, 1, _c_properties, 0, _c_messages, 0);
- }
Defines defclassOnce
, the constructeur of the class Once.
The Once class inherits from the Object class. The class property instance keeps the unique instance of the class. The Once class redefines the class message new.
CLASS METHODS
new
SYNOPSIS
instance new(class self[, arg ...])
DESCRIPTION
The first time new is called, it returns a new instance of class
.
The following times, it returns this same instance of class
.
new passes all the arg
parameters of the message to init.
CODE
- static instance c_new(class self, va_list va) {
- instance i = sendmsg(self, "get", "instance").p;
- if (!i) {
- i = superapply(Once, self, "new", va).p;
- sendmsg(self, "set", "instance", i);
- }
- return i;
- }
new
retrieves the class property instance.
If this property has no value yet, new
creates a new instance by calling the new
method inherited from the Object class with all the arguments of the message and saves the new instance in the class property instance.
new
returns the instance which was saved or the new instance.
Comments