SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
smtk
common
Singleton.h
1
//=========================================================================
2
// Copyright (c) Kitware, Inc.
3
// All rights reserved.
4
// See LICENSE.txt for details.
5
//
6
// This software is distributed WITHOUT ANY WARRANTY; without even
7
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
// PURPOSE. See the above copyright notice for more information.
9
//=========================================================================
10
11
#ifndef smtk_common_Singleton_h
12
#define smtk_common_Singleton_h
13
14
namespace
smtk
15
{
16
namespace
common
17
{
18
template
<
typename
T>
19
class
Singleton
20
{
21
public
:
22
typedef
T Type;
23
static
typename
T::Ptr& instance();
24
25
private
:
26
virtual
~
Singleton
() =
default
;
27
inline
explicit
Singleton
() =
default
;
28
};
29
30
template
<
typename
T>
31
typename
T::Ptr&
Singleton<T>::instance
()
32
{
33
static
typename
T::Ptr instance =
nullptr
;
34
if
(instance ==
nullptr
)
35
{
36
instance = T::create();
37
}
38
return
instance;
39
}
40
}
// namespace common
41
}
// namespace smtk
42
43
#endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition:
doc.h:33
smtk::common::Singleton
Definition:
Singleton.h:19
Generated by
1.8.17