FERS 0.1.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 const doc;
29 XmlElement const root = XmlElement::create("simulation");
30 doc.setRootElement(root);
31
32 const auto& p = params::params;
33
34 if (!p.simulation_name.empty())
35 {
36 root.setAttribute("name", p.simulation_name);
37 }
38 else
39 {
40 root.setAttribute("name", "FERS Scenario");
41 }
42
43 const XmlElement params_elem = root.addChild("parameters");
45
46 for (const auto& waveform : world.getWaveforms() | std::views::values)
47 {
48 XmlElement const waveform_elem = root.addChild("waveform");
50 }
51 for (const auto& timing : world.getTimings() | std::views::values)
52 {
53 XmlElement const timing_elem = root.addChild("timing");
55 }
56 for (const auto& antenna : world.getAntennas() | std::views::values)
57 {
58 XmlElement const antenna_elem = root.addChild("antenna");
60 }
61 for (const auto& platform : world.getPlatforms())
62 {
63 XmlElement const plat_elem = root.addChild("platform");
65 }
66
67 return doc.dumpToString();
68 }
69}
Class for managing XML documents.
Class representing a node in an XML document.
static XmlElement create(const std::string_view name)
Create a new XML element by name.
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:265
const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms() const noexcept
Retrieves the map of radar signals (waveforms).
Definition world.h:256
const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & getTimings() const noexcept
Retrieves the map of timing prototypes.
Definition world.h:275
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms() const noexcept
Retrieves the list of platforms.
Definition world.h:216
Wrapper for managing XML documents and elements using libxml2.
Parameters params
Global simulation parameter state.
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.
math::Vec3 max
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.