SpECTRE Documentation Coverage Report
Current view: top level - Utilities/Serialization - PupBoost.hpp Hit Total Coverage
Commit: 817e13c5144619b701c7cd870655d8dbf94ab8ce Lines: 1 1 100.0 %
Date: 2024-07-19 22:17:05
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines helper functions for working with boost.
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <boost/container/static_vector.hpp>
      10             : #include <boost/math/quaternion.hpp>
      11             : #include <boost/rational.hpp>
      12             : #include <pup.h>
      13             : 
      14             : namespace PUP {
      15             : /// @{
      16             : /// \ingroup ParallelGroup
      17             : /// Serialization of boost::rational for Charm++
      18             : template <class T>
      19             : void pup(PUP::er& p, boost::rational<T>& var) {  // NOLINT
      20             :   if (p.isUnpacking()) {
      21             :     typename boost::rational<T>::int_type n, d;
      22             :     p | n;
      23             :     p | d;
      24             :     var.assign(n, d);
      25             :   } else {
      26             :     typename boost::rational<T>::int_type n = var.numerator();
      27             :     typename boost::rational<T>::int_type d = var.denominator();
      28             :     p | n;
      29             :     p | d;
      30             :   }
      31             : }
      32             : 
      33             : template <typename T>
      34             : inline void operator|(PUP::er& p, boost::rational<T>& var) {  // NOLINT
      35             :   pup(p, var);
      36             : }
      37             : /// @}
      38             : 
      39             : template <class T, size_t N>
      40             : void pup(PUP::er& p, boost::container::static_vector<T, N>& v) {
      41             :   auto size = v.size();
      42             :   p | size;
      43             :   v.resize(size);
      44             :   if (PUP::as_bytes<T>::value) {
      45             :     PUParray(p, v.data(), size);
      46             :   } else {
      47             :     for (auto& x : v) {
      48             :       p | x;
      49             :     }
      50             :   }
      51             : }
      52             : 
      53             : template <class T, size_t N>
      54             : void operator|(PUP::er& p, boost::container::static_vector<T, N>& v) {
      55             :   pup(p, v);
      56             : }
      57             : 
      58             : template <typename T>
      59             : void pup(PUP::er& p, boost::math::quaternion<T>& quaternion) {
      60             :   T component_1 = quaternion.R_component_1();
      61             :   T component_2 = quaternion.R_component_2();
      62             :   T component_3 = quaternion.R_component_3();
      63             :   T component_4 = quaternion.R_component_4();
      64             :   p | component_1;
      65             :   p | component_2;
      66             :   p | component_3;
      67             :   p | component_4;
      68             :   if (p.isUnpacking()) {
      69             :     quaternion = boost::math::quaternion<T>(component_1, component_2,
      70             :                                             component_3, component_4);
      71             :   }
      72             : }
      73             : 
      74             : template <typename T>
      75             : void operator|(PUP::er& p, boost::math::quaternion<T>& quaternion) {
      76             :   pup(p, quaternion);
      77             : }
      78             : }  // namespace PUP

Generated by: LCOV version 1.14