|
||||
File indexing completed on 2025-01-18 10:05:56
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 orange/orangeinp/detail/TransformInserter.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <unordered_set> 0011 #include <vector> 0012 0013 #include "orange/transform/VariantTransform.hh" 0014 0015 namespace celeritas 0016 { 0017 namespace orangeinp 0018 { 0019 namespace detail 0020 { 0021 //---------------------------------------------------------------------------// 0022 /*! 0023 * Deduplicate transforms as they're being built. 0024 * 0025 * This currently only works for *exact* transforms rather than *almost exact* 0026 * transforms. We may eventually want to add a "transform simplifier" and 0027 * "transform soft equal". 0028 */ 0029 class TransformInserter 0030 { 0031 public: 0032 //!@{ 0033 //! \name Type aliases 0034 using VecTransform = std::vector<VariantTransform>; 0035 //!@} 0036 0037 public: 0038 // Construct with a pointer to the transform vector 0039 explicit TransformInserter(VecTransform* transforms); 0040 0041 // Construct a transform with deduplication 0042 TransformId operator()(VariantTransform&& vt); 0043 0044 private: 0045 //// TYPES //// 0046 0047 struct HashTransform 0048 { 0049 VecTransform* storage{nullptr}; 0050 std::size_t operator()(TransformId) const; 0051 }; 0052 struct EqualTransform 0053 { 0054 VecTransform* storage{nullptr}; 0055 bool operator()(TransformId, TransformId) const; 0056 }; 0057 0058 //// DATA //// 0059 0060 VecTransform* transform_; 0061 std::unordered_set<TransformId, HashTransform, EqualTransform> cache_; 0062 0063 //// HELPER FUNCTIONS //// 0064 0065 //! Get the ID of the next transform to be inserted 0066 TransformId size_id() const { return TransformId(transform_->size()); } 0067 }; 0068 0069 //---------------------------------------------------------------------------// 0070 } // namespace detail 0071 } // namespace orangeinp 0072 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |