• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_WM_SINGLE_INSTANCE_H
17 #define OHOS_WM_SINGLE_INSTANCE_H
18 namespace OHOS {
19 namespace Rosen {
20 #define WM_DECLARE_SINGLE_INSTANCE_BASE(className)          \
21 public:                                                     \
22     static className& GetInstance();                        \
23     className(const className&) = delete;                   \
24     className& operator= (const className&) = delete;       \
25     className(className&&) = delete;                        \
26     className& operator= (className&&) = delete;            \
27 
28 #define WM_DECLARE_SINGLE_INSTANCE(className)  \
29     WM_DECLARE_SINGLE_INSTANCE_BASE(className) \
30 protected:                                     \
31     className() = default;                     \
32     virtual ~className() = default;            \
33 
34 #define WM_IMPLEMENT_SINGLE_INSTANCE(className) \
35 className& className::GetInstance()             \
36 {                                               \
37     static className instance;                  \
38     return instance;                            \
39 }                                               \
40 
41 } // namespace OHOS
42 }
43 #endif // OHOS_SINGLE_INSTANCE_H
44