Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-29 09:13:54

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 geocel/VolumeToString.hh
0006 //! \sa geocel/Volume.test.cc
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <variant>
0012 
0013 #include "corecel/io/Label.hh"
0014 
0015 #include "Types.hh"
0016 
0017 namespace celeritas
0018 {
0019 class VolumeParams;
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Visitor class that converts volume-related types to string representations.
0023  *
0024  * This class can be used with std::visit to convert variant types to strings.
0025  * When constructed with VolumeParams reference, it will look up labels for
0026  * IDs; otherwise it will print just the ID value or a null indicator.
0027  */
0028 class VolumeToString
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using VariantLabel
0034         = std::variant<Label, VolumeId, VolumeInstanceId, std::string>;
0035     //!@}
0036 
0037   public:
0038     // Construct without any labels
0039     VolumeToString() = default;
0040 
0041     // Construct with volume params reference
0042     inline explicit VolumeToString(VolumeParams const& params);
0043 
0044     // Overloaded operators for different types
0045     std::string operator()(Label const& label) const;
0046     std::string operator()(VolumeId const& id) const;
0047     std::string operator()(VolumeInstanceId const& id) const;
0048 
0049   private:
0050     VolumeParams const* params_{nullptr};
0051 };
0052 
0053 //---------------------------------------------------------------------------//
0054 // INLINE DEFINITIONS
0055 //---------------------------------------------------------------------------//
0056 /*!
0057  * Construct with volume params reference.
0058  */
0059 VolumeToString::VolumeToString(VolumeParams const& params) : params_(&params)
0060 {
0061 }
0062 
0063 //---------------------------------------------------------------------------//
0064 }  // namespace celeritas