1 /* 2 * Copyright (c) 2021 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 PANDA_RUNTIME_TOOLING_PT_OBJECT_PRIVATE_H_ 17 #define PANDA_RUNTIME_TOOLING_PT_OBJECT_PRIVATE_H_ 18 19 #include "runtime/include/tooling/pt_object.h" 20 #include "pt_reference_private.h" 21 #include "macros.h" 22 23 namespace panda::tooling { 24 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) 25 class PtScopedObjectPrivate { 26 public: 27 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) PtScopedObjectPrivate(ObjectHeader * objectHeader)28 explicit PtScopedObjectPrivate(ObjectHeader *objectHeader) 29 { 30 ASSERT(objectHeader != nullptr); 31 PtLocalReference *localRef = PtCreateLocalReference(objectHeader); 32 object_ = PtObject(localRef); 33 } 34 ~PtScopedObjectPrivate()35 ~PtScopedObjectPrivate() 36 { 37 PtDestroyLocalReference(reinterpret_cast<PtLocalReference *>(object_.GetReference())); 38 } 39 GetObject()40 PtObject GetObject() const 41 { 42 return object_; 43 } 44 45 NO_COPY_SEMANTIC(PtScopedObjectPrivate); 46 NO_MOVE_SEMANTIC(PtScopedObjectPrivate); 47 48 private: 49 PtObject object_ {nullptr}; 50 }; 51 52 } // namespace panda::tooling 53 54 #endif // PANDA_RUNTIME_TOOLING_PT_OBJECT_PRIVATE_H_ 55