![]() |
|
|||
File indexing completed on 2025-09-17 08:54:06
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/io/JsonPimpl.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <nlohmann/json.hpp> 0010 0011 #include "corecel/Config.hh" 0012 0013 #include "corecel/Assert.hh" 0014 0015 namespace celeritas 0016 { 0017 //---------------------------------------------------------------------------// 0018 /*! 0019 * Wrapper class for exporting JSON output. 0020 * 0021 * The caller is expected to use the value directly, so replace \c obj with the 0022 * JSON object. 0023 * 0024 * \code 0025 void output(JsonPimpl* json) const 0026 { 0027 json->obj = value_; 0028 } 0029 * \endcode 0030 */ 0031 struct JsonPimpl 0032 { 0033 nlohmann::json obj; 0034 }; 0035 0036 //---------------------------------------------------------------------------// 0037 /*! 0038 * Helper function to write an object to JSON. 0039 * 0040 * This hides the "not configured" boilerplate. 0041 */ 0042 template<class T> 0043 void to_json_pimpl(JsonPimpl* jp, T const& self) 0044 { 0045 CELER_EXPECT(jp); 0046 to_json(jp->obj, self); 0047 } 0048 0049 template<class T> 0050 nlohmann::json json_pimpl_output(T const& self) 0051 { 0052 JsonPimpl jp; 0053 self.output(&jp); 0054 return std::move(jp.obj); 0055 } 0056 0057 //---------------------------------------------------------------------------// 0058 } // 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 |
![]() ![]() |