Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse scenariofile in constructor and adding helper function to deserialize std::variant-like types. #100

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions daisi/src/cpps/common/cpps_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ CppsManager::CppsManager(const std::string &scenario_config_file)
: Manager<CppsApplication>(scenario_config_file), scenario_(scenario_config_file) {
Manager::initLogger();

scenario_.parse();

amr_descriptions_ = scenario_.getAmrDescriptions();
material_flow_descriptions_ = scenario_.getMaterialFlowDescriptions();

Expand Down
32 changes: 14 additions & 18 deletions daisi/src/cpps/common/scenariofile/cpps_scenariofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,7 @@ struct AlgorithmScenario {
};

struct CppsScenariofile : public GeneralScenariofile {
explicit CppsScenariofile(const std::string &path_to_file) : GeneralScenariofile(path_to_file) {}

uint16_t initial_number_of_amrs = 0;
uint16_t number_of_material_flows = 0;
uint16_t number_of_material_flow_agents = 0;

bool do_material_flow_agents_leave_after_finish = false;

AlgorithmScenario algorithm;
TopologyScenario topology;

std::vector<AmrDescriptionScenario> autonomous_mobile_robots;
std::vector<MaterialFlowDescriptionScenario> material_flows;
std::vector<SpawnInfoScenario> scenario_sequence;

void parse() override {
GeneralScenariofile::parse();

explicit CppsScenariofile(const std::string &path_to_file) : GeneralScenariofile(path_to_file) {
SERIALIZE_VAR(initial_number_of_amrs);
SERIALIZE_VAR(number_of_material_flows);
SERIALIZE_VAR(number_of_material_flow_agents);
Expand All @@ -115,6 +98,19 @@ struct CppsScenariofile : public GeneralScenariofile {
calcNumbersOfRelativeAmrDistribution();
}

uint16_t initial_number_of_amrs = 0;
uint16_t number_of_material_flows = 0;
uint16_t number_of_material_flow_agents = 0;

bool do_material_flow_agents_leave_after_finish = false;

AlgorithmScenario algorithm;
TopologyScenario topology;

std::vector<AmrDescriptionScenario> autonomous_mobile_robots;
std::vector<MaterialFlowDescriptionScenario> material_flows;
std::vector<SpawnInfoScenario> scenario_sequence;

std::unordered_map<std::string, AmrDescription> getAmrDescriptions() const;
std::unordered_map<std::string, MaterialFlowDescriptionScenario> getMaterialFlowDescriptions()
const;
Expand Down
2 changes: 0 additions & 2 deletions daisi/src/manager/general_scenariofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ struct GeneralScenariofile {
: file_path_(std::move(path_to_file)) {
loadFileContent();
node = YAML::Load(file_content_);
}

virtual void parse() {
SERIALIZE_VAR(title);
SERIALIZE_VAR(version);

Expand Down
20 changes: 20 additions & 0 deletions daisi/src/manager/scenariofile_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ void serializeType(std::optional<T> &t, const std::string &key, YAML::Node node)
}
}

/// @brief Deserialize data from node into variant with type T, if \p type matches
/// T.typeName()
/// @tparam T The type to parse if \p type matches \p req_type
/// @param node the YAML node to read data from
/// @param var variant to which the deserialized object is put
/// @param type the actual type
/// @return true if data was deserialzied
template <typename T, typename... U>
bool deserializeIf(YAML::Node node, std::variant<U...> &var, const std::string &type) {
if (type == T::typeName()) {
janagoe marked this conversation as resolved.
Show resolved Hide resolved
var.template emplace<T>();

// Do parsing of the actual object
std::get<T>(var).parse(node);

return true;
}
return false;
}

} // namespace daisi

#endif