34

Once

  1. Object
    1. Once

A Once class creates only one instance.

  1. #include "So-o.h"
  2.  
  3. class Once;

Loads the declarations of the data types and functions of So-o. Defines the class Once.

  1. void defclassOnce() {
  2.     property _c_properties[] = {
  3.         "instance",
  4.         0
  5.     };
  6.     selector _c_messages[] = {
  7.         "new",  METHOD(c_new),
  8.         0, 0
  9.     };
  10.  
  11.     Once = defclass("Once", 0, 1, _c_properties, 0, _c_messages, 0);
  12. }

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
  1. static instance c_new(class self, va_list va) {
  2.     instance i = sendmsg(self, "get", "instance").p;
  3.  
  4.     if (!i) {
  5.         i = superapply(Once, self, "new", va).p;
  6.         sendmsg(self, "set", "instance", i);
  7.     }
  8.  
  9.     return i;
  10. }

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.

SEE ALSO

Application

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].