Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:43

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