1f0bfeaa8Sopenharmony_ci/* 2f0bfeaa8Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3f0bfeaa8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f0bfeaa8Sopenharmony_ci * you may not use this file except in compliance with the License. 5f0bfeaa8Sopenharmony_ci * You may obtain a copy of the License at 6f0bfeaa8Sopenharmony_ci * 7f0bfeaa8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f0bfeaa8Sopenharmony_ci * 9f0bfeaa8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f0bfeaa8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f0bfeaa8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f0bfeaa8Sopenharmony_ci * See the License for the specific language governing permissions and 13f0bfeaa8Sopenharmony_ci * limitations under the License. 14f0bfeaa8Sopenharmony_ci */ 15f0bfeaa8Sopenharmony_ci 16f0bfeaa8Sopenharmony_ci#ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PM_SMARTPTR_UTIL_H 17f0bfeaa8Sopenharmony_ci#define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PM_SMARTPTR_UTIL_H 18f0bfeaa8Sopenharmony_ci 19f0bfeaa8Sopenharmony_ci#include "pm_ptr_util.h" 20f0bfeaa8Sopenharmony_ci 21f0bfeaa8Sopenharmony_cinamespace OHOS { 22f0bfeaa8Sopenharmony_cinamespace PurgeableMem { 23f0bfeaa8Sopenharmony_ci#define MAKE_UNIQUE(ptrSelf, classType, errLog, errAction, ...) \ 24f0bfeaa8Sopenharmony_ci do { \ 25f0bfeaa8Sopenharmony_ci ptrSelf = nullptr; \ 26f0bfeaa8Sopenharmony_ci try { \ 27f0bfeaa8Sopenharmony_ci ptrSelf = std::make_unique<classType>(__VA_ARGS__); \ 28f0bfeaa8Sopenharmony_ci } catch (...) { \ 29f0bfeaa8Sopenharmony_ci HILOG_ERROR(LOG_CORE, errLog); \ 30f0bfeaa8Sopenharmony_ci } \ 31f0bfeaa8Sopenharmony_ci if (ptrSelf == nullptr) { \ 32f0bfeaa8Sopenharmony_ci errAction; \ 33f0bfeaa8Sopenharmony_ci } \ 34f0bfeaa8Sopenharmony_ci } while (0) 35f0bfeaa8Sopenharmony_ci} /* namespace PurgeableMem */ 36f0bfeaa8Sopenharmony_ci} /* namespace OHOS */ 37f0bfeaa8Sopenharmony_ci#endif /* OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PM_SMARTPTR_UTIL_H */ 38