Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:52:40

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/data/AuxInterface.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <string_view>
0011 
0012 #include "corecel/Macros.hh"
0013 #include "corecel/OpaqueId.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/sys/ThreadId.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 // TYPES
0021 //---------------------------------------------------------------------------//
0022 
0023 //! Index for auxiliary data
0024 using AuxId = OpaqueId<struct Aux_>;
0025 
0026 class AuxStateInterface;
0027 
0028 //---------------------------------------------------------------------------//
0029 // INTERFACES
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Base class for extensible shared data that has associated state.
0033  *
0034  * Auxiliary data can be added to a \c AuxParamsInterface at runtime to be
0035  * passed among multiple classes, and then \c dynamic_cast to the expected
0036  * type. It needs to supply a factory function for creating the a state
0037  * instance for multithreaded data on a particular stream and a given memory
0038  * space. Classes can inherit both from \c AuxParamsInterface and other \c
0039  * ActionInterface classes.
0040  */
0041 class AuxParamsInterface
0042 {
0043   public:
0044     //@{
0045     //! \name Type aliases
0046     using UPState = std::unique_ptr<AuxStateInterface>;
0047     //@}
0048 
0049   public:
0050     // Anchored virtual destructor for polymorphism
0051     virtual ~AuxParamsInterface();
0052 
0053     //! Index of this class instance in its registry
0054     virtual AuxId aux_id() const = 0;
0055 
0056     //! Label for the auxiliary data
0057     virtual std::string_view label() const = 0;
0058 
0059     //! Factory function for building multithread state for a stream
0060     virtual UPState create_state(MemSpace, StreamId, size_type size) const = 0;
0061 
0062   protected:
0063     //!@{
0064     //! Allow construction and assignment only through daughter classes
0065     AuxParamsInterface() = default;
0066     CELER_DEFAULT_COPY_MOVE(AuxParamsInterface);
0067     //!@}
0068 };
0069 
0070 //---------------------------------------------------------------------------//
0071 /*!
0072  * Auxiliary state data owned by a single stream.
0073  *
0074  * This interface class is strictly to allow polymorphism and dynamic casting.
0075  */
0076 class AuxStateInterface
0077 {
0078   public:
0079     //@{
0080     //! \name Type aliases
0081     using SPState = std::shared_ptr<AuxStateInterface>;
0082     //@}
0083 
0084   public:
0085     // Anchored virtual destructor for polymorphism
0086     virtual ~AuxStateInterface();
0087 
0088   protected:
0089     //!@{
0090     //! Allow construction and assignment only through daughter classes
0091     AuxStateInterface() = default;
0092     CELER_DEFAULT_COPY_MOVE(AuxStateInterface);
0093     //!@}
0094 };
0095 
0096 //---------------------------------------------------------------------------//
0097 }  // namespace celeritas