Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-06 10:11:57

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 orange/orangeinp/detail/NodeSimplifier.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/cont/VariantUtils.hh"
0010 
0011 #include "../CsgTree.hh"
0012 #include "../CsgTypes.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace orangeinp
0017 {
0018 namespace detail
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Simplify a node by visiting up to one level below.
0023  *
0024  * \return The simplified node, an alias, or no_simplification
0025  */
0026 class NodeSimplifier
0027 {
0028   public:
0029     //!@{
0030     //! \name Type aliases
0031     using size_type = NodeId::size_type;
0032     //!@}
0033 
0034   public:
0035     //! Sentinel for no simplification taking place
0036     static constexpr Aliased no_simplification() { return Aliased{NodeId{}}; }
0037 
0038     // Construct with the tree to visit
0039     explicit NodeSimplifier(CsgTree const& tree);
0040 
0041     // Replace an aliased node
0042     Node operator()(Aliased const& a) const;
0043 
0044     // Replace a negated node
0045     Node operator()(Negated const& n) const;
0046 
0047     // Replace joined node
0048     Node operator()(Joined& j) const;
0049 
0050     //! Other nodes don't simplify
0051     template<class T>
0052     Node operator()(T const&) const
0053     {
0054         return no_simplification();
0055     }
0056 
0057   private:
0058     ContainerVisitor<CsgTree const&, NodeId> visit_node_;
0059 };
0060 
0061 //---------------------------------------------------------------------------//
0062 }  // namespace detail
0063 }  // namespace orangeinp
0064 }  // namespace celeritas