Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,36 @@
class Singleton
{
public:
static Singleton & Instance()
{
// Since it's a static variable, if the class has already been created,
// It won't be created again.
// And it **is** thread-safe in C++11.
static Singleton myInstance;
// Return a reference to our instance.
return myInstance;
}
// delete copy and move constructors and assign operators
Singleton(Singleton const&) = delete; // Copy construct
Singleton(Singleton&&) = delete; // Move construct
Singleton& operator=(Singleton const&) = delete; // Copy assign
Singleton& operator=(Singleton &&) = delete; // Move assign
// Any other public methods
protected:
Singleton()
{
// Constructor code goes here.
}
~Singleton()
{
// Destructor code goes here.
}
// And any other protected methods.
}

View file

@ -0,0 +1,7 @@
class
SINGLETON
create {SINGLETON_ACCESS}
default_create
feature
-- singleton features go here
end

View file

@ -0,0 +1,10 @@
frozen class
SINGLETON_ACCESS
feature
singleton: SINGLETON
once ("PROCESS")
create Result
ensure
Result /= Void
end
end

View file

@ -0,0 +1,3 @@
s: SINGLETON -- declaration somewhere
s := (create{SINGLETON_ACCESS}).singleton -- in some routine

View file

@ -0,0 +1,27 @@
include FMS-SI.f
\ A singleton is created by using normal Forth data
\ allocation words such as value or variable as instance variables.
\ Any number of instances of a singleton class may be
\ instantiated but they will all operate on the same shared data.
\ The data name space will remain private to objects of the class.
:class singleton
0 value a
0 value b
:m printa a . ;m
:m printb b . ;m
:m add-a ( n -- ) a + to a ;m
:m add-b ( n -- ) b + to b ;m
;class
singleton s1
singleton s2
singleton s3
4 s1 add-a
9 s2 add-b
s3 printa \ => 4
s3 printb \ => 9
s1 printb \ => 9
s2 printa \ => 4