mirror of
git://sourceware.org/git/libabigail.git
synced 2024-12-18 16:04:34 +00:00
beededda29
Introduce a compatibility layer for C++11 code by adding include/abg-cxx-compat.h. abg-cxx-compat defines a new namespace abg_compat and defines abg_compat::hash abg_compat::shared_ptr abg_compat::weak_ptr abg_compat::dynamic_pointer_cast abg_compat::static_pointer_cast abg_compat::unordered_map abg_compat::unordered_set based on definitions from std::tr1 (std=gnu++98) or std:: (std=gnu++11). I decided for introducing abg_compat:: rather than polluting abigail:: to allow an easier transition to C++11 at a later time and to not subtly break existing code. As the shared_ptr in C++11 defines shared_ptr::operator bool() explicit, some locations where a shared_ptr is assigned to boolean, needed to be adjusted to explicitly cast to bool. * include/abg-cxx-compat.h: new file introducing the abg_compat namespace to provide C++11 functionality from either std::tr1 or std:: * include/Makefile.am: Add the new abg-cxx-compat.h to source distribution. * include/abg-comparison.h: replace std::tr1 usage by abg_compat and adjust includes accordingly: likewise * include/abg-diff-utils.h: likewise * include/abg-fwd.h: likewise * include/abg-ini.h: likewise * include/abg-interned-str.h: likewise * include/abg-ir.h: likewise * include/abg-libxml-utils.h: likewise * include/abg-libzip-utils.h: likewise * include/abg-reporter.h: likewise * include/abg-sptr-utils.h: likewise * include/abg-suppression.h: likewise * include/abg-tools-utils.h: likewise * include/abg-workers.h: likewise * src/abg-comp-filter.cc: likewise * src/abg-comparison-priv.h: likewise * src/abg-corpus.cc: likewise * src/abg-dwarf-reader.cc: likewise * src/abg-hash.cc: likewise * src/abg-ir.cc: likewise * src/abg-reader.cc: likewise * src/abg-suppression.cc: likewise * src/abg-tools-utils.cc: likewise * src/abg-writer.cc: likewise * tests/test-diff-filter.cc: likewise * tests/test-diff-pkg.cc: likewise * tests/test-read-dwarf.cc: likewise * tests/test-read-write.cc: likewise * tests/test-types-stability.cc: likewise * tests/test-write-read-archive.cc: likewise * tools/abicompat.cc: likewise * tools/abidiff.cc: likewise * tools/abidw.cc: likewise * tools/abilint.cc: likewise * tools/abipkgdiff.cc: likewise Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
144 lines
3.8 KiB
C++
144 lines
3.8 KiB
C++
// -*- mode: C++ -*-
|
|
//
|
|
// Copyright (C) 2013-2019 Red Hat, Inc.
|
|
//
|
|
// This file is part of the GNU Application Binary Interface Generic
|
|
// Analysis and Instrumentation Library (libabigail). This library is
|
|
// free software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU Lesser General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option) any
|
|
// later version.
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// General Lesser Public License for more details.
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this program; see the file COPYING-LGPLV3. If
|
|
// not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/// @file
|
|
///
|
|
/// Utilities to ease the wrapping of C types into std::tr1::shared_ptr
|
|
|
|
#ifndef __ABG_SPTR_UTILS_H__
|
|
#define __ABG_SPTR_UTILS_H__
|
|
|
|
#include <regex.h>
|
|
#include <libxml/xmlreader.h>
|
|
#include "abg-cxx-compat.h"
|
|
|
|
namespace abigail
|
|
{
|
|
|
|
/// Namespace for the utilities to wrap C types into std::tr1::shared_ptr.
|
|
namespace sptr_utils
|
|
{
|
|
|
|
using abg_compat::shared_ptr;
|
|
|
|
/// This is to be specialized for the diverse C types that needs
|
|
/// wrapping in shared_ptr.
|
|
///
|
|
/// @tparam T the type of the C type to wrap in a shared_ptr.
|
|
///
|
|
/// @param p a pointer to wrap in a shared_ptr.
|
|
///
|
|
/// @return then newly created shared_ptr<T>
|
|
template<class T>
|
|
shared_ptr<T>
|
|
build_sptr(T* p);
|
|
|
|
/// This is to be specialized for the diverse C types that needs
|
|
/// wrapping in shared_ptr.
|
|
///
|
|
/// This variant creates a pointer to T and wraps it into a
|
|
/// shared_ptr<T>.
|
|
///
|
|
/// @tparam T the type of the C type to wrap in a shared_ptr.
|
|
///
|
|
/// @return then newly created shared_ptr<T>
|
|
template<class T>
|
|
shared_ptr<T>
|
|
build_sptr();
|
|
|
|
/// A convenience typedef for a shared pointer of xmlTextReader.
|
|
typedef shared_ptr<xmlTextReader> reader_sptr;
|
|
|
|
/// Specialization of sptr_utils::build_sptr for xmlTextReader
|
|
template<>
|
|
reader_sptr
|
|
build_sptr<xmlTextReader>(xmlTextReader *p);
|
|
|
|
/// A convenience typedef for a shared pointer of xmlChar.
|
|
typedef shared_ptr<xmlChar> xml_char_sptr;
|
|
|
|
/// Specialization of build_str for xmlChar.
|
|
template<>
|
|
xml_char_sptr build_sptr<xmlChar>(xmlChar *p);
|
|
|
|
/// A convenience typedef for a shared pointer of regex_t.
|
|
typedef shared_ptr<regex_t> regex_t_sptr;
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>(regex_t *p);
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>();
|
|
|
|
/// A deleter for shared pointers that ... doesn't delete the object
|
|
/// managed by the shared pointer.
|
|
struct noop_deleter
|
|
{
|
|
template<typename T>
|
|
void
|
|
operator()(const T*)
|
|
{}
|
|
};
|
|
|
|
/// A delete functor for a shared_ptr of regex_t.
|
|
struct regex_t_deleter
|
|
{
|
|
/// The operator called to de-allocate the pointer to regex_t
|
|
/// embedded in a shared_ptr<regex_t>
|
|
///
|
|
/// @param r the pointer to regex_t to de-allocate.
|
|
void
|
|
operator()(::regex_t* r)
|
|
{
|
|
regfree(r);
|
|
delete r;
|
|
}
|
|
};//end struct regex_deleter
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
///
|
|
/// This is used to wrap a pointer to regex_t into a
|
|
/// shared_ptr<regex_t>.
|
|
///
|
|
/// @param p the bare pointer to regex_t to wrap into a shared_ptr<regex_t>.
|
|
///
|
|
/// @return the shared_ptr<regex_t> that wraps @p p.
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>(regex_t *p);
|
|
|
|
/// Specialization of sptr_utils::build_sptr for regex_t.
|
|
///
|
|
/// This creates a pointer to regex_t and wraps it into a shared_ptr<regex_t>.
|
|
///
|
|
/// @return the shared_ptr<regex_t> wrapping the newly created regex_t*
|
|
template<>
|
|
regex_t_sptr
|
|
build_sptr<regex_t>();
|
|
|
|
}// end namespace sptr_utils
|
|
}// end namespace abigail
|
|
|
|
#endif //__ABG_SPTR_UTILS_H__
|