10b9a52e3Sopenharmony_ci/* 20b9a52e3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 30b9a52e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 40b9a52e3Sopenharmony_ci * you may not use this file except in compliance with the License. 50b9a52e3Sopenharmony_ci * You may obtain a copy of the License at 60b9a52e3Sopenharmony_ci * 70b9a52e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 80b9a52e3Sopenharmony_ci * 90b9a52e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 100b9a52e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 110b9a52e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120b9a52e3Sopenharmony_ci * See the License for the specific language governing permissions and 130b9a52e3Sopenharmony_ci * limitations under the License. 140b9a52e3Sopenharmony_ci */ 150b9a52e3Sopenharmony_ci 160b9a52e3Sopenharmony_ci#ifndef SINGLE_INSTANCE_H 170b9a52e3Sopenharmony_ci#define SINGLE_INSTANCE_H 180b9a52e3Sopenharmony_ci 190b9a52e3Sopenharmony_cinamespace OHOS { 200b9a52e3Sopenharmony_cinamespace RME { 210b9a52e3Sopenharmony_ci#define DECLARE_SINGLE_INSTANCE_BASE(className) \ 220b9a52e3Sopenharmony_cipublic: \ 230b9a52e3Sopenharmony_ci static className& GetInstance(); \ 240b9a52e3Sopenharmony_ciprivate: \ 250b9a52e3Sopenharmony_ci className(const className&) = delete; \ 260b9a52e3Sopenharmony_ci className& operator=(const className &) = delete; \ 270b9a52e3Sopenharmony_ci className(className&&) = delete; \ 280b9a52e3Sopenharmony_ci className& operator=(className&&) = delete; \ 290b9a52e3Sopenharmony_ci 300b9a52e3Sopenharmony_ci#define DECLARE_SINGLE_INSTANCE(className) \ 310b9a52e3Sopenharmony_ci DECLARE_SINGLE_INSTANCE_BASE(className) \ 320b9a52e3Sopenharmony_ciprivate: \ 330b9a52e3Sopenharmony_ci className() = default; \ 340b9a52e3Sopenharmony_ci ~className() = default; \ 350b9a52e3Sopenharmony_ci 360b9a52e3Sopenharmony_ci#define IMPLEMENT_SINGLE_INSTANCE(className) \ 370b9a52e3Sopenharmony_ciclassName& className::GetInstance() \ 380b9a52e3Sopenharmony_ci{ \ 390b9a52e3Sopenharmony_ci static auto instance = new className(); \ 400b9a52e3Sopenharmony_ci return *instance; \ 410b9a52e3Sopenharmony_ci} 420b9a52e3Sopenharmony_ci} // namespace RME 430b9a52e3Sopenharmony_ci} // namespace OHOS 440b9a52e3Sopenharmony_ci#endif // SINGLE_INSTANCE_H 45