デジタルカーリングライブラリのほとんどの構造体/クラスついてはnlohmann/jsonを用いたJSON変換をサポートしています.
構造体/クラスの変換
一部を除きほぼすべての構造体/クラスは下記の手順でJSONに変換できます.
dc::GameSetting game_setting;
nlohmann::json j_out = game_setting;
std::string str = j_out.dump();
dc::GameSetting game_setting_from_json;
nlohmann::json j_in = nlohmann::json::parse(str);
j_in.get_to(game_setting_from_json);
インターフェースの変換
いくつかのインターフェースは下記の手順でJSONに変換することができます.
std::unique_ptr<dc::ISimulatorFactory> simulator_factory = std::make_unique<dc::SimulatorFCV1Factory>();
nlohmann::json j_out = simulator_factory;
std::string str = j_out.dump();
nlohmann::json j_in = nlohmann::json::parse(str);
std::unique_ptr<dc::ISimulatorFactory> simulator_factory_from_json = j_in.get<std::unique_ptr<dc::ISimulatorFactory>>();
上記方法で変換可能なインターフェースの一覧
ユーザー実装のインターフェースの変換
ユーザー実装のインターフェースも上記方法で変換可能です. ライブラリの拡張の方法に従ってください.