|
||||
File indexing completed on 2025-01-30 10:03:44
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/sys/EnvironmentIO.json.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <nlohmann/json.hpp> 0011 0012 #include "corecel/Assert.hh" 0013 0014 #include "Environment.hh" 0015 0016 namespace celeritas 0017 { 0018 //---------------------------------------------------------------------------// 0019 /*! 0020 * Read environment variables from a JSON file. 0021 */ 0022 inline void from_json(nlohmann::json const& j, Environment& value) 0023 { 0024 CELER_ASSERT(j.is_object()); 0025 value.clear(); 0026 for (auto const& el : j.items()) 0027 { 0028 value.insert({el.key(), el.value().get<std::string>()}); 0029 } 0030 } 0031 0032 //---------------------------------------------------------------------------// 0033 /*! 0034 * Write environment variables to a JSON file. 0035 */ 0036 inline void to_json(nlohmann::json& j, Environment const& value) 0037 { 0038 j = nlohmann::json::object(); 0039 for (auto const& kvref : value.ordered_environment()) 0040 { 0041 Environment::value_type const& kv = kvref; 0042 j[kv.first] = kv.second; 0043 } 0044 } 0045 0046 //---------------------------------------------------------------------------// 0047 } // 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 |