Skip to content
Snippets Groups Projects
Commit 3cd5bcc5 authored by Scott Snyder's avatar Scott Snyder Committed by Frank Winklmeier
Browse files

AthContainers: Add AuxTypeRegistry::checkAuxID.

AthContainers: Add AuxTypeRegistry::checkAuxID.

Add a method to verify that an auxid is being used with the correct type.
Also fix wording in some comments.
parent be9a6299
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-2023 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
/**
* @file AthContainers/AuxTypeRegistry.h
......@@ -90,7 +89,7 @@ public:
* The type of the item is given by the template parameter @c T,
* and the @c ALLOC gives the type of the vector allocator.
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
template <class T, class ALLOC = AuxAllocator_t<T> >
SG::auxid_t getAuxID (const std::string& name,
......@@ -109,7 +108,7 @@ public:
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t getAuxID (const std::type_info& ti,
const std::string& name,
......@@ -129,7 +128,7 @@ public:
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t getAuxID (const std::type_info& ti_alloc,
const std::type_info& ti,
......@@ -150,7 +149,7 @@ public:
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t getAuxID (const std::string& alloc_type,
const std::type_info& ti,
......@@ -171,7 +170,38 @@ public:
SG::auxid_t findAuxID( const std::string& name,
const std::string& clsname = "") const;
/**
* @brief Verify type for an aux variable.
* @param auxid The ID of the variable to check.
* @param flags Optional flags qualifying the type. See above.
*
* If the type of @c auxid is not compatible with the supplied
* types @c T / @c ALLOC, then throw a @c SG::ExcAuxTypeMismatch exception.
* Also may throw @c SG::ExcAtomicMismatch.
*/
template <class T, class ALLOC = AuxAllocator_t<T> >
void checkAuxID (const SG::auxid_t auxid,
const Flags flags = Flags::None);
/**
* @brief Verify type for an aux variable.
* @param auxid The ID of the variable to check.
* @param ti Type of the aux data item.
* @param ti_alloc Type of the vector allocator.
* @param flags Optional flags qualifying the type. See above.
*
* If the type of @c auxid is not compatible with the supplied
* types @c ti / @c ti_alloc, then throw a @c SG::ExcAuxTypeMismatch exception.
* Also may throw @c SG::ExcAtomicMismatch.
*/
void checkAuxID (const SG::auxid_t auxid,
const std::type_info& ti,
const std::type_info& ti_alloc,
const Flags flags);
/**
* @brief Construct a new vector to hold an aux item.
* @param auxid The desired aux data item.
......@@ -493,7 +523,7 @@ private:
*
* If the aux data item already exists, check to see if the provided
* type matches the type that was used before. If so, then set
* return the auxid; otherwise, raise @c SG::ExcAuxTypeMismatch.
* return the auxid; otherwise, throw @c SG::ExcAuxTypeMismatch.
*
* If the aux data item does not already exist, then see if we
* have a factory registered for this @c type_info. If not, then
......
......@@ -21,7 +21,7 @@ namespace SG {
* The type of the item is given by the template parameter @c T,
* and the @c ALLOC gives the type of the vector allocator.
* If an item with the same name was previously requested
* with a different type, then raise an @c AuxTypeMismatch exception.
* with a different type, then throw an @c AuxTypeMismatch exception.
*/
template <class T, class ALLOC>
SG::auxid_t
......@@ -34,6 +34,24 @@ AuxTypeRegistry::getAuxID (const std::string& name,
}
/**
* @brief Verify type for an aux variable.
* @param auxid The ID of the variable to check.
* @param flags Optional flags qualifying the type. See above.
*
* If the type of @c auxid is not compatible with the supplied
* types @c T / @c ALLOC, then throw a @c SG::ExcAuxTypeMismatch exception.
* Also may throw @c SG::ExcAtomicMismatch.
*/
template <class T, class ALLOC>
void
AuxTypeRegistry::checkAuxID (const SG::auxid_t auxid,
const Flags flags /*= Flags::None*/)
{
return checkAuxID (auxid, typeid(T), typeid(ALLOC), flags);
}
/**
* @brief Return the vector factory for a given auxid.
* @param auxid The desired aux data item.
......
......@@ -76,7 +76,7 @@ size_t AuxTypeRegistry::numVariables() const
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t AuxTypeRegistry::getAuxID (const std::type_info& ti,
const std::string& name,
......@@ -100,7 +100,7 @@ SG::auxid_t AuxTypeRegistry::getAuxID (const std::type_info& ti,
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t AuxTypeRegistry::getAuxID (const std::type_info& ti_alloc,
const std::type_info& ti,
......@@ -125,7 +125,7 @@ SG::auxid_t AuxTypeRegistry::getAuxID (const std::type_info& ti_alloc,
* Return @c null_auxid if we don't know how to make vectors of @a ti.
* (Use @c addFactory to register additional types.)
* If an item with the same name was previously requested
* with a different type, then raise @c SG::ExcAuxTypeMismatch.
* with a different type, then throw @c SG::ExcAuxTypeMismatch.
*/
SG::auxid_t AuxTypeRegistry::getAuxID (const std::string& alloc_type,
const std::type_info& ti,
......@@ -164,6 +164,39 @@ AuxTypeRegistry::findAuxID( const std::string& name,
}
/**
* @brief Verify type for an aux variable.
* @param auxid The ID of the variable to check.
* @param ti Type of the aux data item.
* @param ti_alloc Type of the vector allocator.
* @param flags Optional flags qualifying the type. See above.
*
* If the type of @c auxid is not compatible with the supplied
* types @c ti / @c ti_alloc, then throw a @c SG::ExcAuxTypeMismatch exception.
* Also may throw @c SG::ExcAtomicMismatch.
*/
void AuxTypeRegistry::checkAuxID (const SG::auxid_t auxid,
const std::type_info& ti,
const std::type_info& ti_alloc,
const Flags flags)
{
typeinfo_t& m = m_types.at (auxid);
if ( ! ((&ti == m.m_ti || strcmp(ti.name(), m.m_ti->name()) == 0) &&
m.checkAlloc (&ti_alloc, nullptr)))
{
throw SG::ExcAuxTypeMismatch (auxid, ti, *m.m_ti,
SG::normalizedTypeinfoName (ti_alloc),
m.m_alloc_name);
}
if (CxxUtils::test (m.m_flags, Flags::Atomic) &&
!CxxUtils::test (flags, Flags::Atomic))
{
throw SG::ExcAtomicMismatch (auxid, ti);
}
}
/**
* @brief Construct a new vector to hold an aux item.
* @param auxid The desired aux data item.
......@@ -685,7 +718,7 @@ AuxTypeRegistry::~AuxTypeRegistry()
*
* If the aux data item already exists, check to see if the provided
* type matches the type that was used before. If so, then set
* return the auxid; otherwise, raise @c SG::ExcAuxTypeMismatch.
* return the auxid; otherwise, throw @c SG::ExcAuxTypeMismatch.
*
* If the aux data item does not already exist, then see if we
* have a factory registered for this @c type_info. If not, then
......
......@@ -130,6 +130,9 @@ void test_type(const std::string& typname,
EXPECT_EXCEPTION (SG::ExcAuxTypeMismatch, r.getAuxID<char> (name, clsname));
r.checkAuxID<T> (auxid);
EXPECT_EXCEPTION (SG::ExcAuxTypeMismatch, r.checkAuxID<char> (auxid));
r.getAuxID<char> (name, "otherclass");
assert (r.getName (auxid) == name);
......@@ -489,6 +492,7 @@ void test_atomic()
assert (r.getFlags (auxid2) == SG::AuxVarFlags::Atomic);
EXPECT_EXCEPTION (SG::ExcAtomicMismatch, r.getAuxID<int> ("atest2"));
EXPECT_EXCEPTION (SG::ExcAtomicMismatch, r.checkAuxID<int> (auxid2));
}
......
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