Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:46

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/data/AuxParamsRegistry.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 
0012 #include "AuxInterface.hh"
0013 
0014 namespace celeritas
0015 {
0016 //---------------------------------------------------------------------------//
0017 /*!
0018  * Manage auxiliary-added parameter classes.
0019  *
0020  * An instance of this class can be added to shared problem data so that users
0021  * (and other parts of Celeritas) can share arbitrary information between parts
0022  * of the code and create independent state data for each stream.
0023  */
0024 class AuxParamsRegistry
0025 {
0026   public:
0027     //!@{
0028     //! \name Type aliases
0029     using SPParams = std::shared_ptr<AuxParamsInterface>;
0030     using SPConstParams = std::shared_ptr<AuxParamsInterface const>;
0031     //!@}
0032 
0033   public:
0034     // Default constructor
0035     AuxParamsRegistry() = default;
0036 
0037     //// CONSTRUCTION ////
0038 
0039     //! Get the next available ID
0040     AuxId next_id() const { return AuxId(params_.size()); }
0041 
0042     // Register auxiliary parameters
0043     void insert(SPParams params);
0044 
0045     //! Get the number of defined params
0046     AuxId::size_type size() const { return params_.size(); }
0047 
0048     // Access params at the given ID
0049     inline SPParams const& at(AuxId);
0050     inline SPConstParams at(AuxId) const;
0051 
0052     // Get the label corresponding to auxiliary params
0053     inline std::string const& id_to_label(AuxId id) const;
0054 
0055     // Find the ID corresponding to an label
0056     AuxId find(std::string const& label) const;
0057 
0058   private:
0059     std::vector<SPParams> params_;
0060     std::vector<std::string> labels_;
0061     std::unordered_map<std::string, AuxId> aux_ids_;
0062 };
0063 
0064 //---------------------------------------------------------------------------//
0065 // INLINE DEFINITIONS
0066 //---------------------------------------------------------------------------//
0067 /*!
0068  * Access mutable params at the given ID.
0069  */
0070 auto AuxParamsRegistry::at(AuxId id) -> SPParams const&
0071 {
0072     CELER_EXPECT(id < params_.size());
0073     return params_[id.unchecked_get()];
0074 }
0075 
0076 //---------------------------------------------------------------------------//
0077 /*!
0078  * Access params at the given ID.
0079  */
0080 auto AuxParamsRegistry::at(AuxId id) const -> SPConstParams
0081 {
0082     CELER_EXPECT(id < params_.size());
0083     return params_[id.unchecked_get()];
0084 }
0085 
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Get the label corresponding to auxiliary params.
0089  */
0090 std::string const& AuxParamsRegistry::id_to_label(AuxId id) const
0091 {
0092     CELER_EXPECT(id < params_.size());
0093     return labels_[id.unchecked_get()];
0094 }
0095 
0096 //---------------------------------------------------------------------------//
0097 }  // namespace celeritas