|
|
|||
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/UnitLength.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <ostream> 0010 0011 #include "corecel/math/Constant.hh" 0012 0013 #include "detail/LengthUnits.hh" 0014 0015 namespace celeritas 0016 { 0017 //---------------------------------------------------------------------------// 0018 /*! 0019 * Unit system used for reference output or test results. 0020 */ 0021 struct UnitLength 0022 { 0023 Constant value{lengthunits::centimeter}; 0024 char const* label{"cm"}; 0025 0026 template<class T> 0027 constexpr T from_native(T const& v) const 0028 { 0029 return v / value; 0030 } 0031 }; 0032 0033 //! Native unit length 0034 inline constexpr UnitLength native_unit_length{Constant{1}, 0035 lengthunits::native_label}; 0036 0037 //---------------------------------------------------------------------------// 0038 /*! 0039 * Print a length/position as a quantity with units. 0040 */ 0041 template<class T> 0042 struct StreamableLength 0043 { 0044 T const& native_value; 0045 UnitLength const& units; 0046 0047 friend std::ostream& operator<<(std::ostream& os, 0048 StreamableLength const& sl) 0049 { 0050 os << sl.units.from_native(sl.native_value) << " [" << sl.units.label 0051 << ']'; 0052 return os; 0053 } 0054 }; 0055 0056 //---------------------------------------------------------------------------// 0057 // DEDUCTION GUIDES (C++17) 0058 //---------------------------------------------------------------------------// 0059 0060 template<class T> 0061 StreamableLength(T const&, UnitLength) -> StreamableLength<T>; 0062 0063 //---------------------------------------------------------------------------// 0064 } // 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 |
|