Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
36
Task/Singleton/C++/singleton-3.cpp
Normal file
36
Task/Singleton/C++/singleton-3.cpp
Normal 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.
|
||||
}
|
||||
7
Task/Singleton/Eiffel/singleton-1.e
Normal file
7
Task/Singleton/Eiffel/singleton-1.e
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class
|
||||
SINGLETON
|
||||
create {SINGLETON_ACCESS}
|
||||
default_create
|
||||
feature
|
||||
-- singleton features go here
|
||||
end
|
||||
10
Task/Singleton/Eiffel/singleton-2.e
Normal file
10
Task/Singleton/Eiffel/singleton-2.e
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
frozen class
|
||||
SINGLETON_ACCESS
|
||||
feature
|
||||
singleton: SINGLETON
|
||||
once ("PROCESS")
|
||||
create Result
|
||||
ensure
|
||||
Result /= Void
|
||||
end
|
||||
end
|
||||
3
Task/Singleton/Eiffel/singleton-3.e
Normal file
3
Task/Singleton/Eiffel/singleton-3.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s: SINGLETON -- declaration somewhere
|
||||
|
||||
s := (create{SINGLETON_ACCESS}).singleton -- in some routine
|
||||
27
Task/Singleton/Forth/singleton.fth
Normal file
27
Task/Singleton/Forth/singleton.fth
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue