Skip to content
Snippets Groups Projects
Commit afe21e23 authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'safe_clid.AthenaKernel-20200816' into 'master'

AthenaKernel+SGTools: Move safe_clid from SGTools to AthenaKernel.

See merge request !35649
parents 4beb1a54 8bb0c1f2
No related branches found
No related tags found
No related merge requests found
// This file's extension implies that it's C, but it's really -*- C++ -*-.
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// $Id: safe_clid.h,v 1.2 2005-11-08 22:01:30 ssnyder Exp $
/**
* @file SGTools/safe_clid.h
* @file AthenaKernel/tools/safe_clid.h
* @author scott snyder
* @date Nov 2005
* @brief Find the class ID of a type, without triggering an error
......@@ -30,8 +28,8 @@
* to include @a has_classID_tag, or this function won't work.
*/
#ifndef SGTOOLS_SAFECLID_H
#define SGTOOLS_SAFECLID_H
#ifndef ATHENAKERNEL_SAFECLID_H
#define ATHENAKERNEL_SAFECLID_H
#include "GaudiKernel/ClassID.h"
......@@ -46,13 +44,13 @@ namespace SG {
* is not defined.
*/
template <class T>
CLID safe_clid();
constexpr CLID safe_clid();
} // namespace SG
#include "SGTools/safe_clid.icc"
#include "AthenaKernel/tools/safe_clid.icc"
#endif // not SGTOOLS_SAFECLID_H
#endif // not ATHENAKERNEL_SAFECLID_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// $Id: safe_clid.icc,v 1.2 2007-12-14 03:12:34 binet Exp $
/**
* @file SGTools/safe_clid.icc
* @file AthenaeKernel/tools/safe_clid.icc
* @author scott snyder
* @date Nov 2005
* @brief Find the class ID of a type, without triggering an error
......@@ -13,8 +11,7 @@
*/
#include "AthenaKernel/ClassID_traits.h"
#include "AthenaKernel/tools/type_tools.h"
#include "boost/type_traits/remove_pointer.hpp"
#include <type_traits>
namespace SG {
......@@ -55,15 +52,15 @@ namespace SG {
// Decl 1
template <class T>
CLID safe_clid_1 (T*, typename ClassID_traits<T>::has_classID_tag);
constexpr CLID safe_clid_1 (T*, typename ClassID_traits<T>::has_classID_tag);
// Decl 2
template <class T, class U>
CLID safe_clid_1 (T, U);
constexpr CLID safe_clid_1 (T, U);
// This is the public entry point.
template <class T>
CLID safe_clid()
constexpr CLID safe_clid()
{
return safe_clid_1 ((T*)0, std::true_type());
}
......@@ -75,7 +72,7 @@ CLID safe_clid()
// So we can go ahead and ask for the ID in this case.
template <class T>
CLID safe_clid_1 (T*, typename ClassID_traits<T>::has_classID_tag)
constexpr CLID safe_clid_1 (T*, typename ClassID_traits<T>::has_classID_tag)
{
return ClassID_traits<T>::ID();
}
......@@ -93,7 +90,7 @@ CLID safe_clid_1 (T*, typename ClassID_traits<T>::has_classID_tag)
template <class T, bool B>
struct safe_clid_2
{
static CLID clid() { return CLID_NULL; }
constexpr static CLID clid() { return CLID_NULL; }
};
// This specialization is used if @a T does derive from @a DataObject.
......@@ -101,7 +98,7 @@ struct safe_clid_2
template <class T>
struct safe_clid_2<T, true>
{
static CLID clid() { return ClassID_traits<T>::ID(); }
constexpr static CLID clid() { return ClassID_traits<T>::ID(); }
};
// This is the definition corresponding to decl 2 above.
......@@ -109,9 +106,9 @@ struct safe_clid_2<T, true>
// Note that here @a T will be a pointer to the class we're
// actually interested in, so we need to strip a pointer.
template <class T, class U>
CLID safe_clid_1 (T, U)
constexpr CLID safe_clid_1 (T, U)
{
typedef typename boost::remove_pointer<T>::type typ;
using typ = std::remove_pointer_t<T>;
return safe_clid_2<typ, ClassID_traits<typ>::s_isDataObject>::clid();
}
......
......@@ -93,6 +93,10 @@ atlas_add_test( ClassName_test
SOURCES test/ClassName_test.cxx
LINK_LIBRARIES AthenaKernel )
atlas_add_test( safe_clid_test
SOURCES test/safe_clid_test.cxx
LINK_LIBRARIES AthenaKernel )
atlas_add_test( BaseInfo_test
SOURCES test/BaseInfo_test.cxx
LINK_LIBRARIES AthenaKernel )
......
AthenaKernel/safe_clid_test
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#undef NDEBUG
#include "SGTools/safe_clid.h"
#include "AthenaKernel/tools/safe_clid.h"
#include "AthenaKernel/CLASS_DEF.h"
#include "GaudiKernel/DataObject.h"
#include <cassert>
......@@ -22,6 +22,7 @@ struct C
int main()
{
std::cout << "AthenaKernel/safe_clid_test\n";
assert (SG::safe_clid<int> () == 0);
assert (SG::safe_clid<A> () == 0);
assert (SG::safe_clid<B> () == 98765);
......
......@@ -25,11 +25,6 @@ atlas_add_test( VersionedKey_test
test/VersionedKey_test.cxx
LINK_LIBRARIES SGTools )
atlas_add_test( safe_clid_test
SOURCES
test/safe_clid_test.cxx
LINK_LIBRARIES SGTools )
atlas_add_test( exceptions_test
SOURCES
test/exceptions_test.cxx
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment