DigitalCurling3  1.0.0
A curling simulation system for curling AIs
JSONサポート

デジタルカーリングライブラリのほとんどの構造体/クラスついてはnlohmann/jsonを用いたJSON変換をサポートしています.

構造体/クラスの変換

一部を除きほぼすべての構造体/クラスは下記の手順でJSONに変換できます.

namespace dc = digitalcurling3;
dc::GameSetting game_setting; // 変換元のインスタンス
// to json
nlohmann::json j_out = game_setting; // JSONオブジェクトに変換
std::string str = j_out.dump(); // 文字列に変換
// from json
dc::GameSetting game_setting_from_json; // JSONからの復元先
nlohmann::json j_in = nlohmann::json::parse(str); // 文字列からJSONオブジェクトへ
j_in.get_to(game_setting_from_json); // JSONオブジェクトから復元

インターフェースの変換

いくつかのインターフェースは下記の手順でJSONに変換することができます.

namespace dc = digitalcurling3;
// 変換元のインスタンス
std::unique_ptr<dc::ISimulatorFactory> simulator_factory = std::make_unique<dc::SimulatorFCV1Factory>();
// to json
nlohmann::json j_out = simulator_factory; // JSONオブジェクトに変換
std::string str = j_out.dump(); // 文字列に変換
// from json
nlohmann::json j_in = nlohmann::json::parse(str); // 文字列からJSONオブジェクトへ
std::unique_ptr<dc::ISimulatorFactory> simulator_factory_from_json = j_in.get<std::unique_ptr<dc::ISimulatorFactory>>(); // JSONオブジェクトから復元
// 構造体/クラスの変換で使用していた get_to はインターフェースの変換の場合は使えません

上記方法で変換可能なインターフェースの一覧

ユーザー実装のインターフェースの変換

ユーザー実装のインターフェースも上記方法で変換可能です. ライブラリの拡張の方法に従ってください.

digitalcurling3
Digital Curling ライブラリはこの名前空間の中に定義されます
Definition: polymorphic_json.hpp:37