/usr/share/tcltk/xotcl1.6.7-patterns/Singleton.xotcl is in xotcl 1.6.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # $Id: Singleton.xotcl,v 1.7 2006/09/27 08:12:40 neumann Exp $
package provide xotcl::pattern::singleton 0.8
package require XOTcl
namespace eval ::xotcl::pattern::singleton {
namespace import ::xotcl::*
Class SingletonBase
SingletonBase instproc getInstance args {
my instvar _instance
if {[info exists _instance]} {
return $_instance
}
return ""
}
#
# A simple pattern mixin that makes a class to a non-specializable singleton
#
Class NonSpecializableSingleton -superclass SingletonBase
NonSpecializableSingleton instproc create args {
my instvar _instance
if {![info exists _instance]} {
set _instance [self]
next
}
return $_instance
}
NonSpecializableSingleton instproc getInstance {} {
if {[info exists _instance]} {
my instvar _instance
return $_instance
}
return ""
}
#
# Specializable Singleton
#
Class Singleton -superclass {SingletonBase Class}
Singleton instproc singletonFilter args {
switch -exact [self calledproc] {
init {
set registrationclass [lindex [self filterreg] 0]
$registrationclass instvar _instance
if {![info exists _instance]} {
set _instance [self]
next
} else {
my destroy
}
return $_instance
}
default {
return [next]
}
}
}
Singleton instproc init args {
my instfilter add singletonFilter
#
# specialized singletons have to look up the singleton class
# first
Class instproc getInstance {} {
foreach sc [my info superclass] {
if {[$sc info class] eq "::Singleton"} {
return [$sc getInstance]
} else {
return ""
}
}
}
next
}
namespace export SingletonBase NonSpecializableSingleton Singleton
}
namespace import ::xotcl::pattern::singleton::*
|