FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
xml_parser.cpp File Reference

Implementation file for parsing XML configuration files for simulation. More...

#include "xml_parser.h"
#include <GeographicLib/UTMUPS.hpp>
#include <cmath>
#include <filesystem>
#include <functional>
#include <memory>
#include <random>
#include <span>
#include <string_view>
#include <utility>
#include <vector>
#include "antenna/antenna_factory.h"
#include "core/config.h"
#include "core/logging.h"
#include "core/parameters.h"
#include "core/world.h"
#include "fers_xml_dtd.h"
#include "fers_xml_xsd.h"
#include "libxml_wrapper.h"
#include "math/coord.h"
#include "math/geometry_ops.h"
#include "math/path.h"
#include "math/rotation_path.h"
#include "radar/platform.h"
#include "radar/radar_obj.h"
#include "radar/receiver.h"
#include "radar/target.h"
#include "radar/transmitter.h"
#include "timing/prototype_timing.h"
#include "timing/timing.h"
#include "waveform_factory.h"
+ Include dependency graph for xml_parser.cpp:

Go to the source code of this file.

Namespaces

namespace  serial
 

Functions

template<typename T >
void parseElements (const XmlElement &root, const std::string &elementName, World *world, T parseFunction)
 Parses elements with child iteration (e.g., waveforms, timings, antennas).
 
void serial::parseSimulation (const std::string &filename, core::World *world, bool validate, std::mt19937 &masterSeeder)
 Parses a simulation configuration from an XML file.
 
void serial::parseSimulationFromString (const std::string &xmlContent, World *world, const bool validate, std::mt19937 &masterSeeder)
 

Variables

auto get_child_real_type
 Helper function to extract a RealType value from an element.
 
auto get_attribute_bool
 Helper function to extract a boolean value from an attribute.
 

Detailed Description

Implementation file for parsing XML configuration files for simulation.

Definition in file xml_parser.cpp.

Function Documentation

◆ parseElements()

template<typename T >
void parseElements ( const XmlElement root,
const std::string &  elementName,
World world,
parseFunction 
)

Parses elements with child iteration (e.g., waveforms, timings, antennas).

Template Parameters
TThe type of the parsing function.
Parameters
rootThe root XmlElement to parse.
elementNameThe name of the child elements to iterate over.
worldA pointer to the World object where parsed data is added.
parseFunctionThe parsing function to call for each child element.

Definition at line 74 of file xml_parser.cpp.

75{
76 unsigned index = 0;
77 while (true)
78 {
79 XmlElement element = root.childElement(elementName, index++);
80 if (!element.isValid())
81 {
82 break;
83 }
84 parseFunction(element, world);
85 }
86}
Class representing a node in an XML document.
XmlElement childElement(const std::string_view name="", const unsigned index=0) const noexcept
Retrieve a child element by name and index.
bool isValid() const noexcept
Check if the XML element is valid.

References XmlElement::childElement(), and XmlElement::isValid().

+ Here is the call graph for this function:

Variable Documentation

◆ get_attribute_bool

auto get_attribute_bool
Initial value:
= [](const XmlElement& element, const std::string& attributeName, const bool defaultVal) -> bool
{
try
{
return XmlElement::getSafeAttribute(element, attributeName) == "true";
}
catch (const XmlException&)
{
LOG(Level::WARNING, "Failed to get boolean value for attribute '{}'. Defaulting to {}.", attributeName,
defaultVal);
return defaultVal;
}
}
static std::string getSafeAttribute(const XmlElement &element, const std::string_view name)
Get the value of an attribute safely.
Exception class for handling XML-related errors.
#define LOG(level,...)
Definition logging.h:19

Helper function to extract a boolean value from an attribute.

Parameters
elementThe XmlElement to extract the value from.
attributeNameThe name of the attribute to extract the value from.
defaultValThe default value to return if the attribute is empty or cannot be parsed.
Returns
The extracted boolean value or the default value.

Definition at line 114 of file xml_parser.cpp.

115{
116 try
117 {
118 return XmlElement::getSafeAttribute(element, attributeName) == "true";
119 }
120 catch (const XmlException&)
121 {
122 LOG(Level::WARNING, "Failed to get boolean value for attribute '{}'. Defaulting to {}.", attributeName,
123 defaultVal);
124 return defaultVal;
125 }
126};

◆ get_child_real_type

auto get_child_real_type
Initial value:
= [](const XmlElement& element, const std::string& elementName) -> RealType
{
const std::string text = element.childElement(elementName, 0).getText();
if (text.empty())
{
throw XmlException("Element " + elementName + " is empty!");
}
return std::stod(text);
}
std::string getText() const
Get the text content of the XML element.
double RealType
Type for real numbers.
Definition config.h:27

Helper function to extract a RealType value from an element.

Parameters
elementThe XmlElement to extract the value from.
elementNameThe name of the child element to extract the value from.
Returns
The extracted RealType value.
Exceptions
XmlExceptionif the element is empty or cannot be parsed.

Definition at line 96 of file xml_parser.cpp.

97{
98 const std::string text = element.childElement(elementName, 0).getText();
99 if (text.empty())
100 {
101 throw XmlException("Element " + elementName + " is empty!");
102 }
103 return std::stod(text);
104};