1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2// -*- mode: C++ -*- 3// 4// Copyright (C) 2013-2022 Red Hat, Inc. 5 6/// @file 7/// 8/// Utilities to ease the wrapping of C types into std::shared_ptr 9 10#ifndef __ABG_SPTR_UTILS_H__ 11#define __ABG_SPTR_UTILS_H__ 12 13#include <regex.h> 14#include <memory> 15 16 17namespace abigail 18{ 19 20/// Namespace for the utilities to wrap C types into std::shared_ptr. 21namespace sptr_utils 22{ 23 24using std::shared_ptr; 25 26/// This is to be specialized for the diverse C types that needs 27/// wrapping in shared_ptr. 28/// 29/// @tparam T the type of the C type to wrap in a shared_ptr. 30/// 31/// @param p a pointer to wrap in a shared_ptr. 32/// 33/// @return then newly created shared_ptr<T> 34template<class T> 35shared_ptr<T> 36build_sptr(T* p); 37 38/// This is to be specialized for the diverse C types that needs 39/// wrapping in shared_ptr. 40/// 41/// This variant creates a pointer to T and wraps it into a 42/// shared_ptr<T>. 43/// 44/// @tparam T the type of the C type to wrap in a shared_ptr. 45/// 46/// @return then newly created shared_ptr<T> 47template<class T> 48shared_ptr<T> 49build_sptr(); 50 51/// A deleter for shared pointers that ... doesn't delete the object 52/// managed by the shared pointer. 53struct noop_deleter 54{ 55 template<typename T> 56 void 57 operator()(const T*) 58 {} 59}; 60 61}// end namespace sptr_utils 62}// end namespace abigail 63 64#endif //__ABG_SPTR_UTILS_H__ 65