FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
fers_context.h
Go to the documentation of this file.
1/**
2 * @file fers_context.h
3 * @brief Internal C++ class that encapsulates the state of a simulation instance.
4 */
5
6#pragma once
7
8#include <memory>
9#include <random>
10
11#include "world.h"
12
13/**
14 * @class FersContext
15 * @brief Manages the lifetime and state of a single FERS simulation scenario.
16 *
17 * This class serves as the C++ backend for the opaque `fers_context_t`
18 * handle exposed by the C-API. The primary reason for its existence is to
19 * apply the "Pimpl" (Pointer to Implementation) idiom at the ABI boundary. By
20 * hiding the C++ standard library types (`std::unique_ptr`, `std::mt19937`) and
21 * the full definition of `core::World` from the C header, we create a stable
22 * ABI that does not break when the internal C++ implementation changes. This
23 * encapsulation ensures that clients of the C-API (like Rust) do not need to be
24 * recompiled if only the library's internals are modified.
25 *
26 * Its secondary role is to own the `core::World` object, which represents the
27 * entire scenario, and the master random number generator. This guarantees that
28 * the simulation state persists in memory between API calls and that randomness
29 * can be controlled deterministically from a single source.
30 */
32{
33public:
34 /**
35 * @brief Constructs a new simulation context, initializing an empty world.
36 *
37 * The master random number generator is default-constructed. This is a
38 * deliberate choice to allow the seed to be configured later, typically
39 * after parsing a scenario file. This ensures that the scenario itself can
40 * define its own seed for reproducible simulations. If no seed is provided,
41 * a random one is generated at load time.
42 */
43 // NOLINTNEXTLINE(cert-msc51-cpp)
44 FersContext() : _world(std::make_unique<core::World>()) {}
45
46 /**
47 * @brief Retrieves a pointer to the simulation world.
48 * This provides direct, mutable access to the in-memory representation of the
49 * scenario, allowing API functions to modify it.
50 * @return A non-owning pointer to the `core::World` object.
51 */
52 [[nodiscard]] core::World* getWorld() const noexcept { return _world.get(); }
53
54 /**
55 * @brief Retrieves a mutable reference to the master random number seeder.
56 *
57 * A single master generator is used to seed all other random number
58 * generators within the simulation (e.g., for noise models, RCS
59 * fluctuations). This design is crucial for ensuring that a simulation can
60 * be made fully deterministic and reproducible by controlling a single seed
61 * value at the top level.
62 * @return A reference to the `std::mt19937` engine.
63 */
64 [[nodiscard]] std::mt19937& getMasterSeeder() noexcept { return _master_seeder; }
65
66private:
67 /// Owns the `core::World` object, which contains all simulation entities.
68 /// Using `std::unique_ptr` ensures that the world's complex state is
69 /// automatically cleaned up when the FersContext is destroyed.
70 std::unique_ptr<core::World> _world;
71
72 /// Master random engine used to seed all other random generators in the simulation.
73 std::mt19937 _master_seeder;
74};
Manages the lifetime and state of a single FERS simulation scenario.
FersContext()
Constructs a new simulation context, initializing an empty world.
std::mt19937 & getMasterSeeder() noexcept
Retrieves a mutable reference to the master random number seeder.
core::World * getWorld() const noexcept
Retrieves a pointer to the simulation world.
The World class manages the simulator environment.
Definition world.h:38
Header file for the World class in the simulator.