LCOV - code coverage report
Current view: top level - ext/amrex/3d-coverage-g++-24.08/include - AMReX_FabFactory.H (source / functions) Hit Total Coverage
Test: coverage_merged.info Lines: 20 23 87.0 %
Date: 2024-11-18 05:28:54 Functions: 46 183 25.1 %

          Line data    Source code
       1             : 
       2             : #ifndef BL_FABFACTORY_H_
       3             : #define BL_FABFACTORY_H_
       4             : #include <AMReX_Config.H>
       5             : 
       6             : #include <AMReX_Box.H>
       7             : #include <AMReX_Print.H>
       8             : #include <AMReX_MakeType.H>
       9             : #include <AMReX_Vector.H>
      10             : #include <AMReX_Arena.H>
      11             : #include <AMReX_TypeTraits.H>
      12             : 
      13             : namespace amrex
      14             : {
      15             : 
      16             : class FArrayBox;
      17             : 
      18             : enum class FabType : int {
      19             :     covered = -1,
      20             :     regular = 0,
      21             :     singlevalued = 1,
      22             :     multivalued = 2,
      23             :     undefined = 100
      24             : };
      25             : 
      26             : struct FabInfo
      27             : {
      28             :     bool alloc = true;
      29             :     bool shared = false;
      30             :     Arena* arena = nullptr;
      31             : 
      32      403246 :     FabInfo& SetAlloc (bool a) noexcept {
      33      403246 :         alloc = a;
      34      403246 :         return *this;
      35             :     }
      36             : 
      37      403246 :     FabInfo& SetShared (bool s) noexcept {
      38      403246 :         shared = s;
      39      403246 :         return *this;
      40             :     }
      41             : 
      42      403246 :     FabInfo& SetArena (Arena* ar) noexcept {
      43      403246 :         arena = ar;
      44      403246 :         return *this;
      45             :     }
      46             : };
      47             : 
      48             : template <class FAB>
      49             : class FabFactory
      50             : {
      51             : public:
      52      870417 :     FabFactory () noexcept = default;
      53             :     FabFactory (FabFactory const&) noexcept = default;
      54             :     FabFactory (FabFactory &&) noexcept = default;
      55             :     FabFactory& operator= (FabFactory const&) noexcept = default;
      56             :     FabFactory& operator= (FabFactory &&) noexcept = default;
      57      876204 :     virtual ~FabFactory () noexcept = default;
      58             :     AMREX_NODISCARD
      59             :     virtual FAB* create (const Box& box, int ncomps, const FabInfo& info, int box_index) const = 0;
      60             :     AMREX_NODISCARD
      61           0 :     virtual FAB* create_alias (FAB const& /*rhs*/, int /*scomp*/, int /*ncomp*/) const { return nullptr; }
      62             :     virtual void destroy (FAB* fab) const = 0;
      63             :     AMREX_NODISCARD virtual FabFactory<FAB>* clone () const = 0;
      64           0 :     AMREX_NODISCARD virtual Long nBytes (const Box& box, int ncomps, int /*box_index*/) const {
      65             :         if constexpr (IsBaseFab_v<FAB>) {
      66           0 :             return box.numPts() * ncomps * Long(sizeof(typename FAB::value_type));
      67             :         } else {
      68             :             return -1;
      69             :         }
      70             :     }
      71             : };
      72             : 
      73             : template <class FAB>
      74             : class DefaultFabFactory
      75             :     : public FabFactory<FAB>
      76             : {
      77             : public:
      78             :     AMREX_NODISCARD
      79      404686 :     FAB* create (const Box& box, int ncomps, const FabInfo& info, int /*box_index*/) const override
      80             :     {
      81      404686 :         return new FAB(box, ncomps, info.alloc, info.shared, info.arena);
      82             :     }
      83             : 
      84             :     AMREX_NODISCARD
      85         300 :     FAB* create_alias (FAB const& rhs, int scomp, int ncomp) const override
      86             :     {
      87         300 :         return new FAB(rhs, amrex::make_alias, scomp, ncomp);
      88             :     }
      89             : 
      90      406826 :     void destroy (FAB* fab) const override
      91             :     {
      92      406826 :         delete fab;
      93      406826 :     }
      94             : 
      95             :     AMREX_NODISCARD
      96      806710 :     DefaultFabFactory<FAB>* clone () const override {
      97      806710 :         return new DefaultFabFactory<FAB>();
      98             :     }
      99             : };
     100             : 
     101             : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14