FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
xml_serializer.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7/**
8 * @file xml_serializer.cpp
9 * @brief Implementation for serializing the simulation world to XML.
10 *
11 * This file acts as a facade, reading the global simulation parameters
12 * and delegating the object-by-object XML reconstruction to the utils layer.
13 */
14
15#include "xml_serializer.h"
16
17#include <ranges>
18
19#include "core/parameters.h"
20#include "core/world.h"
23
24namespace serial
25{
26 std::string world_to_xml_string(const core::World& world)
27 {
28 XmlDocument doc;
29 xmlNodePtr sim_node = xmlNewNode(nullptr, reinterpret_cast<const xmlChar*>("simulation"));
30 XmlElement root(sim_node);
31 doc.setRootElement(root);
32
33 const auto& p = params::params;
34
35 if (!p.simulation_name.empty())
36 {
37 root.setAttribute("name", p.simulation_name);
38 }
39 else
40 {
41 root.setAttribute("name", "FERS Scenario");
42 }
43
44 const XmlElement params_elem = root.addChild("parameters");
46
47 for (const auto& waveform : world.getWaveforms() | std::views::values)
48 {
49 XmlElement waveform_elem = root.addChild("waveform");
50 xml_serializer_utils::serializeWaveform(*waveform, waveform_elem);
51 }
52 for (const auto& timing : world.getTimings() | std::views::values)
53 {
54 XmlElement timing_elem = root.addChild("timing");
56 }
57 for (const auto& antenna : world.getAntennas() | std::views::values)
58 {
59 XmlElement antenna_elem = root.addChild("antenna");
61 }
62 for (const auto& platform : world.getPlatforms())
63 {
64 XmlElement plat_elem = root.addChild("platform");
65 xml_serializer_utils::serializePlatform(*platform, world, plat_elem);
66 }
67
68 return doc.dumpToString();
69 }
70}
Class for managing XML documents.
void setRootElement(const XmlElement &root) const
Set the root element of the document.
std::string dumpToString() const
Dumps the document to a string.
Class representing a node in an XML document.
XmlElement addChild(const std::string_view name) const noexcept
Add a child element to the current node.
void setAttribute(const std::string_view name, const std::string_view value) const
Set an attribute on the XML element.
The World class manages the simulator environment.
Definition world.h:39
const std::unordered_map< SimId, std::unique_ptr< antenna::Antenna > > & getAntennas() const noexcept
Retrieves the map of antennas.
Definition world.h:239
const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms() const noexcept
Retrieves the map of radar signals (waveforms).
Definition world.h:230
const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & getTimings() const noexcept
Retrieves the map of timing prototypes.
Definition world.h:249
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms() const noexcept
Retrieves the list of platforms.
Definition world.h:190
Wrapper for managing XML documents and elements using libxml2.
Parameters params
Definition parameters.h:85
void serializeAntenna(const antenna::Antenna &antenna, const XmlElement &parent)
Serializes an antenna into a parent XML element.
void serializePlatform(const radar::Platform &platform, const core::World &world, const XmlElement &parent)
Serializes a platform and its attached components into a parent XML element.
void serializeTiming(const timing::PrototypeTiming &timing, const XmlElement &parent)
Serializes a timing object into a parent XML element.
void serializeWaveform(const fers_signal::RadarSignal &waveform, const XmlElement &parent)
Serializes a waveform into a parent XML element.
void serializeParameters(const XmlElement &parent, const params::Parameters &p)
Serializes a Parameters object into a parent XML element.
std::string world_to_xml_string(const core::World &world)
Serializes the entire simulation world into an XML formatted string.
Defines the Parameters struct and provides methods for managing simulation parameters.
Header file for the World class in the simulator.
Provides functions to serialize the simulation world back into the FERS XML format.
Core utility layer for serializing FERS XML scenario files.