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