From 1525ec94c99f28997abd8a422b2d5c8893ada516 Mon Sep 17 00:00:00 2001 From: Christos Anastopoulos <christos.anastopoulos@cern.ch> Date: Mon, 8 Jun 2020 09:35:19 +0000 Subject: [PATCH] Identifier , default method, move inline to .icc, tidy --- DetectorDescription/Identifier/CMakeLists.txt | 1 - .../Identifier/ExpandedIdentifier.h | 221 +---------- .../Identifier/ExpandedIdentifier.icc | 161 ++++++++ .../Identifier/Identifier/HWIdentifier.h | 18 +- .../Identifier/Identifier/Identifier.h | 363 +----------------- .../Identifier/Identifier/Identifier.icc | 266 +++++++++++++ .../Identifier/Identifier/IdentifierHash.h | 104 +---- .../Identifier/Identifier/IdentifierHash.icc | 67 ++++ .../Identifier/src/ExpandedIdentifier.cxx | 12 +- .../Identifier/src/Identifiable.cxx | 4 +- .../Identifier/src/Identifier.cxx | 6 +- .../Identifier/src/Identifier32.cxx | 6 +- DetectorDescription/Identifier/src/Range.cxx | 64 +-- 13 files changed, 596 insertions(+), 697 deletions(-) create mode 100644 DetectorDescription/Identifier/Identifier/ExpandedIdentifier.icc create mode 100644 DetectorDescription/Identifier/Identifier/Identifier.icc create mode 100644 DetectorDescription/Identifier/Identifier/IdentifierHash.icc diff --git a/DetectorDescription/Identifier/CMakeLists.txt b/DetectorDescription/Identifier/CMakeLists.txt index aba3e4abfb2..7f3640b14a6 100644 --- a/DetectorDescription/Identifier/CMakeLists.txt +++ b/DetectorDescription/Identifier/CMakeLists.txt @@ -1,4 +1,3 @@ -# $Id: CMakeLists.txt 732166 2016-03-24 13:30:37Z krasznaa $ ################################################################################ # Package: Identifier ################################################################################ diff --git a/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h b/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h index 79e3ef1b642..985f7fa5ee6 100644 --- a/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h +++ b/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef IDENTIFIER_EXPANDEDIDENTIFIER_H @@ -123,20 +123,14 @@ public: } max_value_type; //---------------------------------------------------------------- - // Constructors + // Defaulted members //---------------------------------------------------------------- - - //---------------------------------------------------------------- - // Default constructor - //---------------------------------------------------------------- - ExpandedIdentifier (); - - //---------------------------------------------------------------- - // Copy constructor and assignment. - //---------------------------------------------------------------- - ExpandedIdentifier (const ExpandedIdentifier& other); - ExpandedIdentifier& operator= (const ExpandedIdentifier& other); - ExpandedIdentifier& operator= (ExpandedIdentifier&& other); + ExpandedIdentifier() = default; + ExpandedIdentifier(const ExpandedIdentifier& other) = default; + ExpandedIdentifier(ExpandedIdentifier&& other) = default; + ExpandedIdentifier& operator=(const ExpandedIdentifier& other) = default; + ExpandedIdentifier& operator=(ExpandedIdentifier&& other) = default; + ~ExpandedIdentifier() = default; //---------------------------------------------------------------- // Constructor from a subset of another ExpandedIdentifier @@ -220,204 +214,7 @@ private: }; //----------------------------------------------- -// inline definitions - - - // Constructors -//----------------------------------------------- -inline -ExpandedIdentifier::ExpandedIdentifier () -{ -} - -//----------------------------------------------- -inline -ExpandedIdentifier::ExpandedIdentifier (const ExpandedIdentifier& other) - : m_fields (other.m_fields) -{ -} - -//----------------------------------------------- -inline -ExpandedIdentifier& -ExpandedIdentifier::operator= (const ExpandedIdentifier& other) -{ - if (this != &other) { - m_fields = other.m_fields; - } - return *this; -} - -//----------------------------------------------- -inline -ExpandedIdentifier& -ExpandedIdentifier::operator= (ExpandedIdentifier&& other) -{ - if (this != &other) { - m_fields = std::move(other.m_fields); - } - return *this; -} - -//----------------------------------------------- -inline -ExpandedIdentifier::ExpandedIdentifier (const ExpandedIdentifier& other, size_type start) -{ - if (start < other.fields ()) - { - element_vector::const_iterator it = other.m_fields.begin (); - it += start; - - m_fields.insert (m_fields.end (), - it, - other.m_fields.end ()); - } -} - - // Modifications -//----------------------------------------------- -inline -void ExpandedIdentifier::add (element_type value) -{ - // Max size of id levels should be < 10 - if(m_fields.capacity() < 10) m_fields.reserve(10); - m_fields.push_back (value); -} - -//----------------------------------------------- -inline -ExpandedIdentifier& ExpandedIdentifier::operator << (element_type value) -{ - // Max size of id levels should be < 10 - if(m_fields.capacity() < 10) m_fields.reserve(10); - m_fields.push_back (value); - - return (*this); -} - -//----------------------------------------------- -inline -ExpandedIdentifier::element_type & ExpandedIdentifier::operator [] (size_type index) -{ - // Raises an exception if index is out-of-bounds. - return m_fields.at (index); -} - -//----------------------------------------------- -inline -void ExpandedIdentifier::clear () -{ - m_fields.clear (); -} - - - - // Accessors -//----------------------------------------------- -inline -ExpandedIdentifier::element_type ExpandedIdentifier::operator [] (size_type index) const -{ - // Raises an exception if index is out-of-bounds. - return m_fields.at (index); -} - -//----------------------------------------------- -inline -ExpandedIdentifier::size_type ExpandedIdentifier::fields () const -{ - return (m_fields.size ()); -} - - // Comparison operators - -//---------------------------------------------------------------- -inline -int ExpandedIdentifier::operator == (const ExpandedIdentifier& other) const -{ - const ExpandedIdentifier& me = *this; - const size_type my_fields = fields (); - const size_type other_fields = other.fields (); - - if (my_fields != other_fields) return (0); - - size_type field = 0; - for (; field < my_fields; ++field) - { - if (me[field] != other[field]) return (0); - } - - return (1); -} - -//---------------------------------------------------------------- -inline -int ExpandedIdentifier::operator != (const ExpandedIdentifier& other) const -{ - const ExpandedIdentifier& me = *this; - - return (!(me == other)); -} - -//----------------------------------------------- -inline -int ExpandedIdentifier::operator < (const ExpandedIdentifier& other) const -{ - const ExpandedIdentifier& me = *this; - const size_type my_fields = fields (); - const size_type other_fields = other.fields (); - - size_type field = 0; - for (;;) - { - if ((field == my_fields) || - (field == other_fields)) - { - // Someone has run out of fields. And up to now my_id == - // other_id. If the lengths are different, the following - // then defines the "shorter" one to be "less than". If - // the lengths are the same, then the two are NOT "less - // than". - return (my_fields < other_fields); - } - - element_type my_field = me[field]; - element_type other_field = other[field]; - - if (my_field < other_field) return (1); - if (my_field > other_field) return (0); - - field++; - } - - return (0); -} - -//----------------------------------------------- -inline -int ExpandedIdentifier::operator > (const ExpandedIdentifier& other) const -{ - const ExpandedIdentifier& me = *this; - - return (other < me); -} - -//---------------------------------------------------------------- -inline -int ExpandedIdentifier::match (const ExpandedIdentifier& other) const -{ - const ExpandedIdentifier& me = *this; - const size_type my_fields = fields (); - const size_type other_fields = other.fields (); - - const size_type fs = (my_fields < other_fields) ? my_fields : other_fields; - - for (size_type field = 0; field < fs; ++field) - { - if (me[field] != other[field]) return (0); - } - - return (1); -} +#include "Identifier/ExpandedIdentifier.icc" #endif diff --git a/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.icc b/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.icc new file mode 100644 index 00000000000..857f82a99ea --- /dev/null +++ b/DetectorDescription/Identifier/Identifier/ExpandedIdentifier.icc @@ -0,0 +1,161 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +//----------------------------------------------- +inline ExpandedIdentifier::ExpandedIdentifier(const ExpandedIdentifier& other, + size_type start) +{ + if (start < other.fields()) { + element_vector::const_iterator it = other.m_fields.begin(); + it += start; + + m_fields.insert(m_fields.end(), it, other.m_fields.end()); + } +} + +// Modifications +//----------------------------------------------- +inline void +ExpandedIdentifier::add(element_type value) +{ + // Max size of id levels should be < 10 + if (m_fields.capacity() < 10) + m_fields.reserve(10); + m_fields.push_back(value); +} + +//----------------------------------------------- +inline ExpandedIdentifier& +ExpandedIdentifier::operator<<(element_type value) +{ + // Max size of id levels should be < 10 + if (m_fields.capacity() < 10) + m_fields.reserve(10); + m_fields.push_back(value); + + return (*this); +} + +//----------------------------------------------- +inline ExpandedIdentifier::element_type& ExpandedIdentifier::operator[]( + size_type index) +{ + // Raises an exception if index is out-of-bounds. + return m_fields.at(index); +} + +//----------------------------------------------- +inline void +ExpandedIdentifier::clear() +{ + m_fields.clear(); +} + +// Accessors +//----------------------------------------------- +inline ExpandedIdentifier::element_type ExpandedIdentifier::operator[]( + size_type index) const +{ + // Raises an exception if index is out-of-bounds. + return m_fields.at(index); +} + +//----------------------------------------------- +inline ExpandedIdentifier::size_type +ExpandedIdentifier::fields() const +{ + return (m_fields.size()); +} + +// Comparison operators + +//---------------------------------------------------------------- +inline int +ExpandedIdentifier::operator==(const ExpandedIdentifier& other) const +{ + const ExpandedIdentifier& me = *this; + const size_type my_fields = fields(); + const size_type other_fields = other.fields(); + + if (my_fields != other_fields) + return (0); + + size_type field = 0; + for (; field < my_fields; ++field) { + if (me[field] != other[field]) + return (0); + } + + return (1); +} + +//---------------------------------------------------------------- +inline int +ExpandedIdentifier::operator!=(const ExpandedIdentifier& other) const +{ + const ExpandedIdentifier& me = *this; + + return (!(me == other)); +} + +//----------------------------------------------- +inline int +ExpandedIdentifier::operator<(const ExpandedIdentifier& other) const +{ + const ExpandedIdentifier& me = *this; + const size_type my_fields = fields(); + const size_type other_fields = other.fields(); + + size_type field = 0; + for (;;) { + if ((field == my_fields) || (field == other_fields)) { + // Someone has run out of fields. And up to now my_id == + // other_id. If the lengths are different, the following + // then defines the "shorter" one to be "less than". If + // the lengths are the same, then the two are NOT "less + // than". + return (my_fields < other_fields); + } + + element_type my_field = me[field]; + element_type other_field = other[field]; + + if (my_field < other_field) + return (1); + if (my_field > other_field) + return (0); + + field++; + } + + return (0); +} + +//----------------------------------------------- +inline int +ExpandedIdentifier::operator>(const ExpandedIdentifier& other) const +{ + const ExpandedIdentifier& me = *this; + + return (other < me); +} + +//---------------------------------------------------------------- +inline int +ExpandedIdentifier::match(const ExpandedIdentifier& other) const +{ + const ExpandedIdentifier& me = *this; + const size_type my_fields = fields(); + const size_type other_fields = other.fields(); + + const size_type fs = (my_fields < other_fields) ? my_fields : other_fields; + + for (size_type field = 0; field < fs; ++field) { + if (me[field] != other[field]) + return (0); + } + + return (1); +} + diff --git a/DetectorDescription/Identifier/Identifier/HWIdentifier.h b/DetectorDescription/Identifier/Identifier/HWIdentifier.h index 78f79305f01..6b2f7977a7a 100644 --- a/DetectorDescription/Identifier/Identifier/HWIdentifier.h +++ b/DetectorDescription/Identifier/Identifier/HWIdentifier.h @@ -15,7 +15,17 @@ class HWIdentifier : public Identifier { public: /// Default constructor - HWIdentifier (); + HWIdentifier() = default; + /// Default Copy constructor + HWIdentifier(const HWIdentifier& other) = default; + /// Default Move constructor + HWIdentifier(HWIdentifier&& other) = default; + /// Default Assignment operators + HWIdentifier& operator=(const HWIdentifier& old) = default; + /// Default Move Assignment operator + HWIdentifier& operator=(HWIdentifier&& old) = default; + /// Default dtor + ~HWIdentifier() = default; /// Constructor from value_type explicit HWIdentifier(value_type value); @@ -42,12 +52,6 @@ struct hash<HWIdentifier> }; } - - -inline HWIdentifier::HWIdentifier() - : Identifier::Identifier() -{} - inline HWIdentifier::HWIdentifier(value_type value) : Identifier::Identifier(value) {} diff --git a/DetectorDescription/Identifier/Identifier/Identifier.h b/DetectorDescription/Identifier/Identifier/Identifier.h index 502385156f6..e71f2ca918a 100644 --- a/DetectorDescription/Identifier/Identifier/Identifier.h +++ b/DetectorDescription/Identifier/Identifier/Identifier.h @@ -12,12 +12,10 @@ #include "GaudiKernel/MsgStream.h" #include "Identifier/Identifier32.h" - -#include <iostream> #include <boost/io/ios_state.hpp> #include <vector> #include <string> - +#include <iostream> /** **----------------------------------------------- ** @@ -35,7 +33,6 @@ class Identifier { public: - ///---------------------------------------------------------------- /// Define public typedefs ///---------------------------------------------------------------- @@ -56,8 +53,19 @@ public: ///---------------------------------------------------------------- /// Default constructor - Identifier (); - + Identifier() = default; + /// Default Copy constructor + Identifier(const Identifier& other) = default; + /// Default Move constructor + Identifier(Identifier&& other) = default; + /// Default Assignment operators + Identifier& operator=(const Identifier& old) = default; + /// Default Move Assignment operator + Identifier& operator=(Identifier&& old) = default; + /// Default dtor + ~Identifier() = default; + + ///Additional ctors /// Constructor from value_type explicit Identifier (value_type value); @@ -69,18 +77,15 @@ public: explicit Identifier (Identifier32::value_type value); explicit Identifier (int value); - /// Copy constructor - Identifier (const Identifier& other); + ///---------------------------------------------------------------- /// Modifications ///---------------------------------------------------------------- - - /// Assignment operator - Identifier& operator = (const Identifier& old); + + /// Assignment operators overloads Identifier& operator = (const Identifier32& old); Identifier& operator = (value_type value); - /// Assignment to avoid common implicit conversions and shift properly Identifier& operator = (Identifier32::value_type value); Identifier& operator = (int value); @@ -89,6 +94,7 @@ private: /// Bitwise operations Identifier& operator |= (value_type value); Identifier& operator &= (value_type value); + public: /// build from a string form - hexadecimal @@ -132,13 +138,6 @@ public: bool operator <= (const Identifier& other) const; bool operator >= (const Identifier& other) const; - //bool operator == (const Identifier32& other) const; - //bool operator != (const Identifier32& other) const; - //bool operator < (const Identifier32& other) const; - //bool operator > (const Identifier32& other) const; - //bool operator <= (const Identifier32& other) const; - //bool operator >= (const Identifier32& other) const; - /// Comparison operators with value_type. /// This is a hack, only because GeoAdaptors/GeoMuonHits wants to /// to compare explicitly with 0 as a test of whether the identifier @@ -194,7 +193,7 @@ private: //---------------------------------------------------------------- // The compact identifier data. //---------------------------------------------------------------- - value_type m_id; + value_type m_id = max_value; }; //----------------------------------------------- @@ -213,328 +212,6 @@ struct hash<Identifier> }; } - - - -// Constructors -//----------------------------------------------- -inline Identifier::Identifier () - : m_id(max_value) -{} - -//----------------------------------------------- -inline Identifier::Identifier (const Identifier& other) - : m_id(other.m_id) -{} - -/// Constructor from Identifier32 -//----------------------------------------------- -inline Identifier::Identifier (const Identifier32& other) - : m_id(max_value) -{ - //std::cout << "Identifier(Identifier32) " << other.get_compact() << std::endl; - if (other.is_valid()) { - m_id = (static_cast<value_type>(other.get_compact()) << 32); - } -} - -/// Constructor from Identifier32 value_type (unsigned int) -/// (only use in id64 case since otherwise redundant) -//----------------------------------------------- -inline Identifier::Identifier (Identifier32::value_type value) - : m_id(max_value) -{ - //std::cout << "Identifier(Identifier32::value_type) " << value << std::endl; - if (value == ~static_cast<Identifier32::value_type>(0)) { - m_id = max_value; - } - else { - m_id = (static_cast<value_type>(value) << 32); - } -} -inline Identifier::Identifier (int value) - : m_id(max_value) -{ - //std::cout << "Identifier(int) " << value << std::endl; - m_id = (static_cast<value_type>(value) << 32); -} - -//----------------------------------------------- -inline Identifier::Identifier (value_type value) - : m_id(value) -{ - //std::cout << "Identifier(value_type) " << value << std::endl; - - // Print out warning for potential call with value for a 32-bit id - // I.e. if lower bits are set and no upper bit set - const value_type upper = 0XFFFFFFFF00000000LL; - const value_type lower = 0X00000000FFFFFFFFLL; - const value_type testUpper = value & upper; - const value_type testLower = value & lower; - if ( testUpper == 0 && testLower > 0) { - boost::io::ios_flags_saver ifs(std::cout); - std::cout << "Identifier::Identifier - WARNING Constructing 64-bit id with empty upper and non-empty lower: " << std::hex << testUpper << " " << testLower << std::endl; - m_id = (value << 32); - } -} - -// Modifications -//----------------------------------------------- - -inline Identifier& -Identifier::operator = (const Identifier& old) { - if (&old != this) { - //std::cout << "operator=(Identifier) " << old.get_compact() << std::endl; - m_id = old.m_id; - } - return (*this); -} - -inline Identifier& -Identifier::operator = (const Identifier32& old) { - //std::cout << "operator=(Identifier32) " << old.get_compact() << std::endl; - m_id = (static_cast<value_type>(old.get_compact()) << 32); - return (*this); -} - -inline Identifier& -Identifier::operator = (value_type value) -{ - //std::cout << "operator=(value_type) " << value << std::endl; - - // Print out warning for potential call with value for a 32-bit id - // I.e. if lower bits are set and no upper bit set - const value_type upper = 0XFFFFFFFF00000000LL; - const value_type lower = 0X00000000FFFFFFFFLL; - const value_type testUpper = value & upper; - const value_type testLower = value & lower; - if ( testUpper == 0 && testLower > 0) { - boost::io::ios_flags_saver ifs(std::cout); - std::cout << "Identifier::opertor = - WARNING Constructing 64-bit id with empty upper and non-empty lower: " << std::hex << testUpper << " " << testLower << std::endl; - m_id = (value << 32); - return (*this); - } - - m_id = value; - return (*this); -} - -inline Identifier& -Identifier::operator = (Identifier32::value_type value) -{ - //std::cout << "operator=(Identifier32::value_type) " << value << std::endl; - if (value == ~static_cast<Identifier32::value_type>(0)) { - m_id = max_value; - } - else { - m_id = static_cast<value_type>(value) << 32; - } - return (*this); -} -inline Identifier& -Identifier::operator = (int value) -{ - //std::cout << "operator=(int) " << value << std::endl; - m_id = static_cast<value_type>(value) << 32; - return (*this); -} - -inline Identifier& -Identifier::operator |= (value_type value) -{ - m_id |= value; - return (*this); -} - -inline Identifier& -Identifier::operator &= (value_type value) -{ - m_id &= value; - return (*this); -} - -inline Identifier& -Identifier::set_literal (value_type value) -{ - m_id = value; - return (*this); -} - -inline void -Identifier::clear () -{ - m_id = max_value; -} - -inline Identifier::value_type Identifier::extract( - Identifier::size_type shift, Identifier::size_type mask) const { - return (m_id >> shift) & static_cast<Identifier::value_type>(mask); -} - -inline Identifier::value_type Identifier::mask_shift( - Identifier::value_type mask, Identifier::size_type shift) const { - return (m_id & mask) >> shift; -} - -inline Identifier::value_type Identifier::extract( - Identifier::size_type shift) const { - return (m_id >> shift); -} - -inline Identifier32 Identifier::get_identifier32 (void) const -{ - // test for bit set in lower 32 - if (extract(0,0xFFFFFFFF)) return (Identifier32()); - return (Identifier32(extract(32))); -} - - -inline Identifier::value_type Identifier::get_compact (void) const -{ - return (m_id); -} - -// Comparison operators -//---------------------------------------------------------------- -inline bool -Identifier::operator == (const Identifier& other) const -{ - return (m_id == other.m_id); -} - -//---------------------------------------------------------------- -inline bool -Identifier::operator != (const Identifier& other) const -{ - return (m_id != other.m_id); -} - -//----------------------------------------------- -inline bool -Identifier::operator < (const Identifier& other) const -{ - return (m_id < other.m_id); -} - -//----------------------------------------------- -inline bool -Identifier::operator > (const Identifier& other) const -{ - return (m_id > other.m_id); -} - -//----------------------------------------------- -inline bool -Identifier::operator <= (const Identifier& other) const -{ - return (m_id <= other.m_id); -} - -//----------------------------------------------- -inline bool -Identifier::operator >= (const Identifier& other) const -{ - return (m_id >= other.m_id); -} - -//---------------------------------------------------------------- -//inline bool -//Identifier::operator == (const Identifier32& other) const -//{ -// return (this == Identifier(other)); -//} -// -//---------------------------------------------------------------- -//inline bool -//Identifier::operator != (const Identifier32& other) const -//{ -// return (this != Identifier(other)); -//} -// -//----------------------------------------------- -//inline bool -//Identifier::operator < (const Identifier32& other) const -//{ -// return (this < Identifier(other)); -//} -// -//----------------------------------------------- -//inline bool -//Identifier::operator > (const Identifier32& other) const -//{ -// return (this > Identifier(other)); -//} -// -//----------------------------------------------- -//inline bool -//Identifier::operator <= (const Identifier32& other) const -//{ -// return (this <= Identifier(other)); -//} -// -//----------------------------------------------- -//inline bool -//Identifier::operator >= (const Identifier32& other) const -//{ -// return (this >= Identifier(other)); -//} - -//---------------------------------------------------------------- -inline bool -Identifier::operator == (Identifier::value_type other) const -{ - return (m_id == other); -} - -inline bool -Identifier::operator != (Identifier::value_type other) const -{ - return (m_id != other); -} - -inline bool -Identifier::operator == (Identifier32::value_type other) const -{ - return ((*this) == Identifier(other)); -} - -inline bool -Identifier::operator == (int other) const -{ - return ((*this) == Identifier(other)); -} - -inline bool -Identifier::operator != (Identifier32::value_type other) const -{ - return ((*this) != Identifier(other)); -} - -inline bool -Identifier::operator != (int other) const -{ - return ((*this) != Identifier(other)); -} - -/// This is for logging - -inline MsgStream& operator << (MsgStream& f, const Identifier& id) -{ - f << id.getString(); - return f; -} - -inline std::ostream& operator << (std::ostream& os, const Identifier& id) -{ - os << id.getString(); - return os; -} - - -inline bool -Identifier::is_valid () const -{ - return (!(max_value == m_id)); -} +#include "Identifier/Identifier.icc" #endif diff --git a/DetectorDescription/Identifier/Identifier/Identifier.icc b/DetectorDescription/Identifier/Identifier/Identifier.icc new file mode 100644 index 00000000000..6c1b3359d65 --- /dev/null +++ b/DetectorDescription/Identifier/Identifier/Identifier.icc @@ -0,0 +1,266 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + +/// Constructor from Identifier32 +//----------------------------------------------- +inline Identifier::Identifier(const Identifier32& other) + : m_id(max_value) +{ + if (other.is_valid()) { + m_id = (static_cast<value_type>(other.get_compact()) << 32); + } +} + +/// Constructor from Identifier32 value_type (unsigned int) +/// (only use in id64 case since otherwise redundant) +//----------------------------------------------- +inline Identifier::Identifier(Identifier32::value_type value) + : m_id(max_value) +{ + if (value == ~static_cast<Identifier32::value_type>(0)) { + m_id = max_value; + } else { + m_id = (static_cast<value_type>(value) << 32); + } +} +inline Identifier::Identifier(int value) + : m_id(max_value) +{ + m_id = (static_cast<value_type>(value) << 32); +} + +//----------------------------------------------- +inline Identifier::Identifier(value_type value) + : m_id(value) +{ + + // Print out warning for potential call with value for a 32-bit id + // I.e. if lower bits are set and no upper bit set + const value_type upper = 0XFFFFFFFF00000000LL; + const value_type lower = 0X00000000FFFFFFFFLL; + const value_type testUpper = value & upper; + const value_type testLower = value & lower; + if (testUpper == 0 && testLower > 0) { + boost::io::ios_flags_saver ifs(std::cout); + std::cout << "Identifier::Identifier - WARNING Constructing 64-bit id " + "with empty upper and non-empty lower: " + << std::hex << testUpper << " " << testLower << std::endl; + m_id = (value << 32); + } +} + +// Modifications +//----------------------------------------------- + +inline Identifier& +Identifier::operator=(const Identifier32& old) +{ + m_id = (static_cast<value_type>(old.get_compact()) << 32); + return (*this); +} + +inline Identifier& +Identifier::operator=(value_type value) +{ + + // Print out warning for potential call with value for a 32-bit id + // I.e. if lower bits are set and no upper bit set + const value_type upper = 0XFFFFFFFF00000000LL; + const value_type lower = 0X00000000FFFFFFFFLL; + const value_type testUpper = value & upper; + const value_type testLower = value & lower; + if (testUpper == 0 && testLower > 0) { + boost::io::ios_flags_saver ifs(std::cout); + std::cout << "Identifier::opertor = - WARNING Constructing 64-bit id " + "with empty upper and non-empty lower: " + << std::hex << testUpper << " " << testLower << std::endl; + m_id = (value << 32); + return (*this); + } + + m_id = value; + return (*this); +} + +inline Identifier& +Identifier::operator=(Identifier32::value_type value) +{ + if (value == ~static_cast<Identifier32::value_type>(0)) { + m_id = max_value; + } else { + m_id = static_cast<value_type>(value) << 32; + } + return (*this); +} +inline Identifier& +Identifier::operator=(int value) +{ + m_id = static_cast<value_type>(value) << 32; + return (*this); +} + +inline Identifier& +Identifier::operator|=(value_type value) +{ + m_id |= value; + return (*this); +} + +inline Identifier& +Identifier::operator&=(value_type value) +{ + m_id &= value; + return (*this); +} + +inline Identifier& +Identifier::set_literal(value_type value) +{ + m_id = value; + return (*this); +} + +inline void +Identifier::clear() +{ + m_id = max_value; +} + +inline Identifier::value_type +Identifier::extract(Identifier::size_type shift, + Identifier::size_type mask) const +{ + return (m_id >> shift) & static_cast<Identifier::value_type>(mask); +} + +inline Identifier::value_type +Identifier::mask_shift(Identifier::value_type mask, + Identifier::size_type shift) const +{ + return (m_id & mask) >> shift; +} + +inline Identifier::value_type +Identifier::extract(Identifier::size_type shift) const +{ + return (m_id >> shift); +} + +inline Identifier32 +Identifier::get_identifier32(void) const +{ + // test for bit set in lower 32 + if (extract(0, 0xFFFFFFFF)) + return (Identifier32()); + return (Identifier32(extract(32))); +} + +inline Identifier::value_type +Identifier::get_compact(void) const +{ + return (m_id); +} + +// Comparison operators +//---------------------------------------------------------------- +inline bool +Identifier::operator==(const Identifier& other) const +{ + return (m_id == other.m_id); +} + +//---------------------------------------------------------------- +inline bool +Identifier::operator!=(const Identifier& other) const +{ + return (m_id != other.m_id); +} + +//----------------------------------------------- +inline bool +Identifier::operator<(const Identifier& other) const +{ + return (m_id < other.m_id); +} + +//----------------------------------------------- +inline bool +Identifier::operator>(const Identifier& other) const +{ + return (m_id > other.m_id); +} + +//----------------------------------------------- +inline bool +Identifier::operator<=(const Identifier& other) const +{ + return (m_id <= other.m_id); +} + +//----------------------------------------------- +inline bool +Identifier::operator>=(const Identifier& other) const +{ + return (m_id >= other.m_id); +} + +//---------------------------------------------------------------- +inline bool +Identifier::operator==(Identifier::value_type other) const +{ + return (m_id == other); +} + +inline bool +Identifier::operator!=(Identifier::value_type other) const +{ + return (m_id != other); +} + +inline bool +Identifier::operator==(Identifier32::value_type other) const +{ + return ((*this) == Identifier(other)); +} + +inline bool +Identifier::operator==(int other) const +{ + return ((*this) == Identifier(other)); +} + +inline bool +Identifier::operator!=(Identifier32::value_type other) const +{ + return ((*this) != Identifier(other)); +} + +inline bool +Identifier::operator!=(int other) const +{ + return ((*this) != Identifier(other)); +} + +/// This is for logging + +inline MsgStream& +operator<<(MsgStream& f, const Identifier& id) +{ + f << id.getString(); + return f; +} + +inline std::ostream& +operator<<(std::ostream& os, const Identifier& id) +{ + os << id.getString(); + return os; +} + +inline bool +Identifier::is_valid() const +{ + return (!(max_value == m_id)); +} + diff --git a/DetectorDescription/Identifier/Identifier/IdentifierHash.h b/DetectorDescription/Identifier/Identifier/IdentifierHash.h index 22086b42f66..e2df71f1c22 100644 --- a/DetectorDescription/Identifier/Identifier/IdentifierHash.h +++ b/DetectorDescription/Identifier/Identifier/IdentifierHash.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /*************************************************************************** @@ -48,14 +48,13 @@ public: /// Constructors ///---------------------------------------------------------------- - /// Default constructor - IdentifierHash (); - - /// Copy constructor - IdentifierHash (const IdentifierHash& other); - - /// Assignment - IdentifierHash& operator= (const IdentifierHash& other); + /// Default methods + IdentifierHash () = default; + IdentifierHash (const IdentifierHash& other) =default; + IdentifierHash (IdentifierHash&& other) =default; + IdentifierHash& operator=(const IdentifierHash& other) = default; + IdentifierHash& operator=(IdentifierHash&& other) = default; + ~IdentifierHash () = default; /// Initialization with value IdentifierHash (value_type value); @@ -93,95 +92,12 @@ private: //---------------------------------------------------------------- // The actual identifier data. //---------------------------------------------------------------- - value_type m_value; + value_type m_value = max_value; }; //----------------------------------------------- -//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> -//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> - - -//----------------------------------------------- -inline IdentifierHash::IdentifierHash () - : m_value(max_value) -{} - -//----------------------------------------------- -inline IdentifierHash::IdentifierHash (const IdentifierHash& other) - : m_value(other.m_value) -{} - -//----------------------------------------------- -inline IdentifierHash& IdentifierHash::operator= (const IdentifierHash& other) -{ - if (this != &other) - m_value = other.m_value; - return *this; -} - -//----------------------------------------------- -inline IdentifierHash::IdentifierHash (value_type value) - : m_value(value) -{} - -//----------------------------------------------- -inline IdentifierHash& -IdentifierHash::operator = (value_type value) -{ - m_value = value; - return (*this); -} - -//----------------------------------------------- -inline IdentifierHash& -IdentifierHash::operator += (unsigned int value) -{ - m_value += value; - return (*this); -} - -//----------------------------------------------- -inline IdentifierHash& -IdentifierHash::operator -= (unsigned int value) -{ - m_value = (m_value > value) ? m_value - value : 0; - return (*this); -} - -//----------------------------------------------- -inline IdentifierHash::operator unsigned int (void) const -{ - return (m_value); -} - -//----------------------------------------------- -inline unsigned int IdentifierHash::value (void) const -{ - return (m_value); -} - -//----------------------------------------------- -inline bool -IdentifierHash::is_valid () const -{ - return (!(max_value == m_value)); -} - -inline MsgStream& operator << (MsgStream& f, const IdentifierHash& id) -{ - f << id.value(); - return f; -} - -inline std::ostream& operator << (std::ostream& os, const IdentifierHash& id) -{ - os << id.value(); - return os; -} - - // Define a hash functional namespace std { @@ -195,5 +111,5 @@ struct hash<IdentifierHash> }; } - +#include "Identifier/IdentifierHash.icc" #endif // IDENTIFIER_IDENTIFIERHASH_H diff --git a/DetectorDescription/Identifier/Identifier/IdentifierHash.icc b/DetectorDescription/Identifier/Identifier/IdentifierHash.icc new file mode 100644 index 00000000000..1cfb111c64a --- /dev/null +++ b/DetectorDescription/Identifier/Identifier/IdentifierHash.icc @@ -0,0 +1,67 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ + + +//----------------------------------------------- +inline IdentifierHash::IdentifierHash (value_type value) + : m_value(value) +{} + +//----------------------------------------------- +inline IdentifierHash& +IdentifierHash::operator = (value_type value) +{ + m_value = value; + return (*this); +} + +//----------------------------------------------- +inline IdentifierHash& +IdentifierHash::operator += (unsigned int value) +{ + m_value += value; + return (*this); +} + +//----------------------------------------------- +inline IdentifierHash& +IdentifierHash::operator -= (unsigned int value) +{ + m_value = (m_value > value) ? m_value - value : 0; + return (*this); +} + +//----------------------------------------------- +inline IdentifierHash::operator unsigned int (void) const +{ + return (m_value); +} + +//----------------------------------------------- +inline unsigned int IdentifierHash::value (void) const +{ + return (m_value); +} + +//----------------------------------------------- +inline bool +IdentifierHash::is_valid () const +{ + return (!(max_value == m_value)); +} + +inline MsgStream& operator << (MsgStream& f, const IdentifierHash& id) +{ + f << id.value(); + return f; +} + +inline std::ostream& operator << (std::ostream& os, const IdentifierHash& id) +{ + os << id.value(); + return os; +} + + + diff --git a/DetectorDescription/Identifier/src/ExpandedIdentifier.cxx b/DetectorDescription/Identifier/src/ExpandedIdentifier.cxx index 86387b11b35..83d8dce1df2 100644 --- a/DetectorDescription/Identifier/src/ExpandedIdentifier.cxx +++ b/DetectorDescription/Identifier/src/ExpandedIdentifier.cxx @@ -1,15 +1,15 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "Identifier/ExpandedIdentifier.h" -#include <stdarg.h> -#include <stdio.h> #include <algorithm> +#include <cstdarg> +#include <cstdio> #include <cstring> -#include <iostream> #include <iomanip> +#include <iostream> //----------------------------------------------- static void show_vector (const ExpandedIdentifier::element_vector& v) @@ -44,7 +44,7 @@ ExpandedIdentifier::ExpandedIdentifier (const std::string& text) void ExpandedIdentifier::set (const std::string& text) { clear (); - if (text.size () == 0) return; + if (text.empty()) return; const char* ctext = text.c_str (); for (;;) @@ -59,7 +59,7 @@ void ExpandedIdentifier::set (const std::string& text) add ((element_type) value); - if (sep == 0) break; + if (sep == nullptr) break; ctext = sep + 1; } diff --git a/DetectorDescription/Identifier/src/Identifiable.cxx b/DetectorDescription/Identifier/src/Identifiable.cxx index 70ed5e5d8bf..0bafd474107 100644 --- a/DetectorDescription/Identifier/src/Identifiable.cxx +++ b/DetectorDescription/Identifier/src/Identifiable.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /*************************************************************************** @@ -27,6 +27,6 @@ IdentifierHash Identifiable::identifyHash() const const IdHelper* Identifiable::getHelper() const { - return (0); + return (nullptr); } diff --git a/DetectorDescription/Identifier/src/Identifier.cxx b/DetectorDescription/Identifier/src/Identifier.cxx index 94739525e5b..307bbf06bcd 100644 --- a/DetectorDescription/Identifier/src/Identifier.cxx +++ b/DetectorDescription/Identifier/src/Identifier.cxx @@ -1,12 +1,12 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "Identifier/Identifier.h" -#include <stdarg.h> -#include <stdio.h> #include <algorithm> +#include <cstdarg> +#include <cstdio> #include <iostream> #include <iomanip> diff --git a/DetectorDescription/Identifier/src/Identifier32.cxx b/DetectorDescription/Identifier/src/Identifier32.cxx index ecebbbd4195..9f7200217d9 100644 --- a/DetectorDescription/Identifier/src/Identifier32.cxx +++ b/DetectorDescription/Identifier/src/Identifier32.cxx @@ -1,12 +1,12 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "Identifier/Identifier32.h" -#include <stdarg.h> -#include <stdio.h> #include <algorithm> +#include <cstdarg> +#include <cstdio> #include <iostream> #include <iomanip> diff --git a/DetectorDescription/Identifier/src/Range.cxx b/DetectorDescription/Identifier/src/Range.cxx index ffe38cb3ac3..e3fb06337e4 100644 --- a/DetectorDescription/Identifier/src/Range.cxx +++ b/DetectorDescription/Identifier/src/Range.cxx @@ -6,17 +6,17 @@ #include "Identifier/Range.h" -#include <stdio.h> +#include <algorithm> +#include <cstdio> #include <string> #include <vector> -#include <algorithm> #include <limits> #include <iostream> #include <iomanip> #include <set> -#include <assert.h> +#include <cassert> #ifdef WIN32 namespace std @@ -433,7 +433,7 @@ Range::field::get_previous (element_type current, element_type& previous) const previous = m_maximum; return (true); } - else if (has_previous == m_continuation_mode) { + if (has_previous == m_continuation_mode) { previous = m_previous; return (true); } @@ -446,12 +446,12 @@ Range::field::get_previous (element_type current, element_type& previous) const case enumerated: size_type index = get_value_index(current); if (index == 0) { - if (has_wrap_around == m_continuation_mode && m_values.size() > 0) { + if (has_wrap_around == m_continuation_mode && !m_values.empty()) { index = m_values.size() - 1; previous = m_values[index]; return (true); } - else if (has_previous == m_continuation_mode) { + if (has_previous == m_continuation_mode) { previous = m_previous; return (true); } @@ -498,7 +498,7 @@ Range::field::get_next (element_type current, element_type& next) const next = m_minimum; return (true); } - else if (has_next == m_continuation_mode) { + if (has_next == m_continuation_mode) { next = m_next; return (true); } @@ -516,7 +516,7 @@ Range::field::get_next (element_type current, element_type& next) const next = m_values[0]; return (true); } - else if (has_next == m_continuation_mode) { + if (has_next == m_continuation_mode) { next = m_next; return (true); } @@ -752,7 +752,7 @@ void Range::field::add_value (element_type value) //----------------------------------------------- void Range::field::set (const std::vector <element_type>& values) { - if (values.size () == 0) + if (values.empty()) { clear (); return; @@ -1112,7 +1112,7 @@ void Range::field::set_indices() //----------------------------------------------- void Range::field::check_for_both_bounded() { - if (m_mode == enumerated && m_values.size() > 0) { + if (m_mode == enumerated && !m_values.empty()) { element_type last = m_values[0]; for (size_type i = 1; i < m_values.size (); ++i) { if (m_values[i] > last + 1) return; @@ -1137,7 +1137,7 @@ void Range::field::check_for_both_bounded() void Range::field::create_index_table() { /// Create index table from value table - if (m_mode == enumerated && m_values.size() > 0) { + if (m_mode == enumerated && !m_values.empty()) { size_type size = m_maximum - m_minimum + 1; // return if we are over the maximum desired vector table size if (size > max_indexes) { @@ -1737,7 +1737,7 @@ Range::const_identifier_factory Range::factory_end () const } //----------------------------------------------- -Range::identifier_factory::identifier_factory () : m_range (0) +Range::identifier_factory::identifier_factory () : m_range (nullptr) { } @@ -1890,10 +1890,10 @@ void Range::identifier_factory::operator ++ () m_id.clear (); break; } - else - { + + --i; - } + } } @@ -1918,7 +1918,7 @@ bool Range::identifier_factory::operator != (const identifier_factory& other) co } //----------------------------------------------- -Range::const_identifier_factory::const_identifier_factory () : m_range (0) +Range::const_identifier_factory::const_identifier_factory () : m_range (nullptr) { } @@ -2072,10 +2072,10 @@ void Range::const_identifier_factory::operator ++ () m_id.clear (); break; } - else - { + + --i; - } + } } @@ -2108,7 +2108,7 @@ public: MultiRangeParser () { - m_multirange = 0; + m_multirange = nullptr; } bool run (const std::string& text, MultiRange& multirange) @@ -2201,27 +2201,39 @@ private: break; case ':': pos++; - if (true) - { + { + Range& r = m_multirange->back (); + + if (!parse_number (text, pos, maximum)) + { + result = false; + } + else + { + r.add_maximum ((MultiRange::element_type) maximum); + } + } break; case '*': pos++; - if (true) - { + { + Range& r = m_multirange->back (); + r.add (); + } break; @@ -2552,7 +2564,7 @@ MultiRange::const_identifier_factory MultiRange::factory_end () const //----------------------------------------------- MultiRange::identifier_factory::identifier_factory () : - m_multirange(0) + m_multirange(nullptr) { } @@ -2677,7 +2689,7 @@ bool MultiRange::identifier_factory::operator != (const identifier_factory& othe //----------------------------------------------- MultiRange::const_identifier_factory::const_identifier_factory () : - m_multirange(0) + m_multirange(nullptr) { } -- GitLab