LCOV - code coverage report
Current view: top level - ext/amrex/2d-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: 62 183 33.9 %

          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      966153 :     FabInfo& SetAlloc (bool a) noexcept {
      33      966153 :         alloc = a;
      34      966153 :         return *this;
      35             :     }
      36             : 
      37      966153 :     FabInfo& SetShared (bool s) noexcept {
      38      966153 :         shared = s;
      39      966153 :         return *this;
      40             :     }
      41             : 
      42      966153 :     FabInfo& SetArena (Arena* ar) noexcept {
      43      966153 :         arena = ar;
      44      966153 :         return *this;
      45             :     }
      46             : };
      47             : 
      48             : template <class FAB>
      49             : class FabFactory
      50             : {
      51             : public:
      52     1867905 :     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     1962995 :     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     3415010 :     FAB* create (const Box& box, int ncomps, const FabInfo& info, int /*box_index*/) const override
      80             :     {
      81     3415010 :         return new FAB(box, ncomps, info.alloc, info.shared, info.arena);
      82             :     }
      83             : 
      84             :     AMREX_NODISCARD
      85        1289 :     FAB* create_alias (FAB const& rhs, int scomp, int ncomp) const override
      86             :     {
      87        1289 :         return new FAB(rhs, amrex::make_alias, scomp, ncomp);
      88             :     }
      89             : 
      90     3433501 :     void destroy (FAB* fab) const override
      91             :     {
      92     3433501 :         delete fab;
      93     3433501 :     }
      94             : 
      95             :     AMREX_NODISCARD
      96     1772162 :     DefaultFabFactory<FAB>* clone () const override {
      97     1772162 :         return new DefaultFabFactory<FAB>();
      98             :     }
      99             : };
     100             : 
     101             : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14