#include "Voie.h" #include "TypeInfrastructure.h" namespace modellib { //std::unordered_set Voie::ids; nlohmann::json Voie::to_json(bool withinfo) { nlohmann::json voie = nlohmann::json::object(); voie["id"] = m_idVoie; if (withinfo) { voie["periodeDisponible"] = nlohmann::json::array(); for (auto & i : m_periodesDisponibilite) { voie["periodeDisponible"].push_back(i.to_json()); } voie["infrastructures"] = nlohmann::json::array(); for (auto & m_infrastructure : m_infrastructures) { voie["infrastructures"].push_back(m_infrastructure.to_json()); } } return voie; } Voie Voie::from_json(nlohmann::json &json) { Voie voie; if(json["id"].is_number()) voie.setId(std::to_string(json["id"].get())); else voie.setId(json["id"].get()); for (nlohmann::json &infra: json["infrastructures"]) { voie.m_infrastructures.push_back(TypeInfrastructure::from_json(infra)); } for (nlohmann::json &dispo: json["periodesDisponible"]) { voie.m_periodesDisponibilite.push_back(EmplacementVoie::from_json(dispo)); } for (nlohmann::json &dispo: json["periodeDisponible"]) { voie.m_periodesDisponibilite.push_back(EmplacementVoie::from_json(dispo)); } return voie; } }