SpECTRE Documentation Coverage Report
Current view: top level - IO/Observer - ArrayComponentId.hpp Hit Total Coverage
Commit: f1ddee3e40d81480e49140855d2b0e66fafaa908 Lines: 1 9 11.1 %
Date: 2020-12-02 17:35:08
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <boost/functional/hash.hpp>
       7             : #include <ckarrayindex.h>
       8             : #include <cstddef>
       9             : #include <functional>
      10             : #include <string>
      11             : 
      12             : #include "Utilities/PrettyType.hpp"
      13             : 
      14             : namespace PUP {
      15             : class er;
      16             : }  // namespace PUP
      17             : 
      18             : namespace observers {
      19             : /*!
      20             :  * \ingroup ObserversGroup
      21             :  * \brief An ID type that identifies both the parallel component and the index
      22             :  * in the parallel component.
      23             :  *
      24             :  * A specialization of `std::hash` is provided to allow using `ArrayComponentId`
      25             :  * as a key in associative containers.
      26             :  */
      27           1 : class ArrayComponentId {
      28             :  public:
      29           0 :   ArrayComponentId() = default;  // Needed for Charm++ serialization
      30             : 
      31             :   template <typename ParallelComponent>
      32           0 :   ArrayComponentId(const ParallelComponent* /*meta*/,
      33             :                    const CkArrayIndex& index) noexcept;
      34             : 
      35             :   // NOLINTNEXTLINE(google-runtime-references)
      36           0 :   void pup(PUP::er& p) noexcept;
      37             : 
      38           0 :   size_t component_id() const noexcept { return component_id_; }
      39             : 
      40           0 :   const CkArrayIndex& array_index() const noexcept { return array_index_; }
      41             : 
      42             :  private:
      43           0 :   size_t component_id_{0};
      44           0 :   CkArrayIndex array_index_{};
      45             : };
      46             : 
      47             : template <typename ParallelComponent>
      48             : ArrayComponentId::ArrayComponentId(const ParallelComponent* const /*meta*/,
      49             :                                    const CkArrayIndex& index) noexcept
      50             :     : component_id_(
      51             :           std::hash<std::string>{}(pretty_type::get_name<ParallelComponent>())),
      52             :       array_index_(index) {}
      53             : 
      54             : bool operator==(const ArrayComponentId& lhs,
      55             :                 const ArrayComponentId& rhs) noexcept;
      56             : 
      57             : bool operator!=(const ArrayComponentId& lhs,
      58             :                 const ArrayComponentId& rhs) noexcept;
      59             : 
      60             : std::ostream& operator<<(std::ostream& os,
      61             :                          const ArrayComponentId& array_component_id) noexcept;
      62             : }  // namespace observers
      63             : 
      64             : namespace std {
      65             : template <>
      66             : struct hash<observers::ArrayComponentId> {
      67             :   size_t operator()(const observers::ArrayComponentId& t) const {
      68             :     size_t result = t.component_id();
      69             :     boost::hash_combine(result, t.array_index().hash());
      70             :     return result;
      71             :   }
      72             : };
      73             : }  // namespace std

Generated by: LCOV version 1.14