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