Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:37

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/AuxParamsRegistry.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 
0011 #include "AuxInterface.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Manage auxiliary parameter classes.
0018  *
0019  * This class keeps track of \c AuxParamsInterface classes.
0020  */
0021 class AuxParamsRegistry
0022 {
0023   public:
0024     //!@{
0025     //! \name Type aliases
0026     using SPParams = std::shared_ptr<AuxParamsInterface>;
0027     using SPConstParams = std::shared_ptr<AuxParamsInterface const>;
0028     //!@}
0029 
0030   public:
0031     // Default constructor
0032     AuxParamsRegistry() = default;
0033 
0034     //// CONSTRUCTION ////
0035 
0036     //! Get the next available ID
0037     AuxId next_id() const { return AuxId(params_.size()); }
0038 
0039     // Register auxiliary parameters
0040     void insert(SPParams params);
0041 
0042     //! Get the number of defined params
0043     AuxId::size_type size() const { return params_.size(); }
0044 
0045     // Access params at the given ID
0046     inline SPParams const& at(AuxId);
0047     inline SPConstParams at(AuxId) const;
0048 
0049     // Get the label corresponding to auxiliary params
0050     inline std::string const& id_to_label(AuxId id) const;
0051 
0052     // Find the ID corresponding to an label
0053     AuxId find(std::string const& label) const;
0054 
0055   private:
0056     std::vector<SPParams> params_;
0057     std::vector<std::string> labels_;
0058     std::unordered_map<std::string, AuxId> aux_ids_;
0059 };
0060 
0061 //---------------------------------------------------------------------------//
0062 // INLINE DEFINITIONS
0063 //---------------------------------------------------------------------------//
0064 /*!
0065  * Access mutable params at the given ID.
0066  */
0067 auto AuxParamsRegistry::at(AuxId id) -> SPParams const&
0068 {
0069     CELER_EXPECT(id < params_.size());
0070     return params_[id.unchecked_get()];
0071 }
0072 
0073 //---------------------------------------------------------------------------//
0074 /*!
0075  * Access params at the given ID.
0076  */
0077 auto AuxParamsRegistry::at(AuxId id) const -> SPConstParams
0078 {
0079     CELER_EXPECT(id < params_.size());
0080     return params_[id.unchecked_get()];
0081 }
0082 
0083 //---------------------------------------------------------------------------//
0084 /*!
0085  * Get the label corresponding to auxiliary params.
0086  */
0087 std::string const& AuxParamsRegistry::id_to_label(AuxId id) const
0088 {
0089     CELER_EXPECT(id < params_.size());
0090     return labels_[id.unchecked_get()];
0091 }
0092 
0093 //---------------------------------------------------------------------------//
0094 }  // namespace celeritas