17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-29 01:07:28 +01:00

refactor(sonar): use std::array for local fixed-size arrays (cpp:S5945)

Arrays that are class members or part of headers are left unchanged.
This commit is contained in:
jerrrrycho
2026-10-10 17:44:14 +02:00
parent 7a27af5a47
commit a322472632
12 changed files with 74 additions and 74 deletions

View File

@@ -8887,7 +8887,7 @@ std::string TMoverParameters::EngineDescription(int what) const
double TMoverParameters::GetTrainsetVoltage(int const Coupling) const
{ // ABu: funkcja zwracajaca napiecie dla calego skladu, przydatna dla EZT
// TBD, TODO: call once per vehicle update, return cached results?
double voltages[] = {0.0, 0.0};
std::array<double, 2> voltages{0.0, 0.0};
for (int end = end::front; end <= end::rear; ++end)
{
if (Couplers[end].Connected == nullptr)
@@ -12011,7 +12011,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
BrakeOpModeFlag = bom_PN;
// yB: jesli pojazdy nie maja zadeklarowanych czasow, to wsadz z przepisow +-16,(6)%
int DefBrakeTable[8] = {15, 4, 25, 25, 13, 3, 12, 2};
std::array<int, 8> const DefBrakeTable{15, 4, 25, 25, 13, 3, 12, 2};
for (int b = 1; b < 4; b++)
{

View File

@@ -195,17 +195,17 @@ void CSkyDome::RebuildColors() {
float zenithy = GetZenith( m_zenithymatrix, m_thetasun, m_turbidity );
// get perez function parametrs
float perezluminance[5];
float perezx[5];
float perezy[5];
GetPerez( perezluminance, m_distributionluminance, m_turbidity );
GetPerez( perezx, m_distributionxcomp, m_turbidity );
GetPerez( perezy, m_distributionycomp, m_turbidity );
std::array<float, 5> perezluminance{};
std::array<float, 5> perezx{};
std::array<float, 5> perezy{};
GetPerez( perezluminance.data(), m_distributionluminance, m_turbidity );
GetPerez( perezx.data(), m_distributionxcomp, m_turbidity );
GetPerez( perezy.data(), m_distributionycomp, m_turbidity );
// make some precalculation
zenithx = PerezFunctionO1( perezx, m_thetasun, zenithx );
zenithy = PerezFunctionO1( perezy, m_thetasun, zenithy );
zenithluminance = PerezFunctionO1( perezluminance, m_thetasun, zenithluminance );
zenithx = PerezFunctionO1( perezx.data(), m_thetasun, zenithx );
zenithy = PerezFunctionO1( perezy.data(), m_thetasun, zenithy );
zenithluminance = PerezFunctionO1( perezluminance.data(), m_thetasun, zenithluminance );
// start with fresh average for the new pass
glm::vec3 averagecolor;
@@ -241,11 +241,11 @@ void CSkyDome::RebuildColors() {
float const cosgamma2 = static_cast<float>(std::pow( std::cos( gamma ), 2 ));
// Compute x,y values
float const x = PerezFunctionO2( perezx, icostheta, gamma, cosgamma2, zenithx );
float const y = PerezFunctionO2( perezy, icostheta, gamma, cosgamma2, zenithy );
float const x = PerezFunctionO2( perezx.data(), icostheta, gamma, cosgamma2, zenithx );
float const y = PerezFunctionO2( perezy.data(), icostheta, gamma, cosgamma2, zenithy );
// luminance(Y) for clear & overcast sky
float const yclear = std::max( 0.01f, PerezFunctionO2( perezluminance, icostheta, gamma, cosgamma2, zenithluminance ) );
float const yclear = std::max( 0.01f, PerezFunctionO2( perezluminance.data(), icostheta, gamma, cosgamma2, zenithluminance ) );
float const yover = std::max( 0.01f, zenithluminance * ( 1.0f + 2.0f * vertex.y ) / 3.0f );
float const Y = std::lerp( yclear, yover, m_overcast );

View File

@@ -3,7 +3,7 @@
GLenum gl::buffer::glenum_target(gl::buffer::targets target)
{
static GLenum mapping[13] =
static std::array<GLenum, 13> const mapping =
{
GL_ARRAY_BUFFER,
GL_ATOMIC_COUNTER_BUFFER,

View File

@@ -90,17 +90,17 @@ void gl::framebuffer::blit(framebuffer const *src, framebuffer const *dst, int s
int attachment_n = attachment - GL_COLOR_ATTACHMENT0;
{
GLenum outputs[8] = { GL_NONE };
std::array<GLenum, 8> outputs{ GL_NONE };
outputs[attachment_n] = src != nullptr ? attachment : GL_BACK_LEFT;
glReadBuffer(attachment);
}
{
GLenum outputs[8] = { GL_NONE };
std::array<GLenum, 8> outputs{ GL_NONE };
outputs[attachment_n] = dst != nullptr ? attachment : GL_BACK_LEFT;
glDrawBuffers(attachment_n + 1, outputs);
glDrawBuffers(attachment_n + 1, outputs.data());
}
}

View File

@@ -51,7 +51,7 @@ std::optional<int64_t> gl::query::result()
GLenum gl::query::glenum_target(targets Target) const
{
static GLenum mapping[6] =
static std::array<GLenum, 6> const mapping =
{
GL_SAMPLES_PASSED,
GL_ANY_SAMPLES_PASSED,

View File

@@ -318,11 +318,11 @@ gl::shader::shader(const std::string &filename) : name(filename)
glGetShaderiv(*this, GL_COMPILE_STATUS, &status);
if (!status)
{
GLchar info[512];
glGetShaderInfoLog(*this, 512, nullptr, info);
log_error(std::string(info));
std::array<GLchar, 512> info{};
glGetShaderInfoLog(*this, static_cast<GLsizei>(info.size()), nullptr, info.data());
log_error(std::string(info.data()));
throw shader_exception("failed to compile " + filename + ": " + std::string(info));
throw shader_exception("failed to compile " + filename + ": " + std::string(info.data()));
}
}
@@ -392,9 +392,9 @@ void gl::program::link()
glGetProgramiv(*this, GL_LINK_STATUS, &status);
if (!status)
{
GLchar info[512];
glGetProgramInfoLog(*this, 512, nullptr, info);
throw shader_exception("failed to link program: " + std::string(info));
std::array<GLchar, 512> info{};
glGetProgramInfoLog(*this, static_cast<GLsizei>(info.size()), nullptr, info.data());
throw shader_exception("failed to link program: " + std::string(info.data()));
}
init();

View File

@@ -24,7 +24,7 @@ cFrustum::calculate( glm::mat4 const &Projection, glm::mat4 const &Modelview ) {
// multiply the matrices to retrieve clipping planes (column-major, same layout as the old float[16] form)
auto const clipmatrix { Projection * Modelview };
float clip[ 16 ];
std::array<float, 16> clip{};
for( int column = 0; column < 4; ++column ) {
for( int row = 0; row < 4; ++row ) {
clip[ column * 4 + row ] = clipmatrix[ column ][ row ];

View File

@@ -29,9 +29,9 @@ void screenshot_manager::screenshot_save_thread( char *img, int w, int h )
stride = -w * 3;
}
char datetime[64];
std::array<char, 64> datetime{};
std::tm const tm_info = local_tm(std::time(nullptr));
strftime(datetime, 64, "%Y-%m-%d_%H-%M-%S", &tm_info);
strftime(datetime.data(), datetime.size(), "%Y-%m-%d_%H-%M-%S", &tm_info);
uint64_t perf;
#ifdef _WIN32
@@ -42,7 +42,7 @@ void screenshot_manager::screenshot_save_thread( char *img, int w, int h )
perf = ts.tv_nsec;
#endif
std::string filename = Global.screenshot_dir + "/" + std::string(datetime) +
std::string filename = Global.screenshot_dir + "/" + std::string(datetime.data()) +
"_" + std::to_string(perf) + ".png";
if (png_image_write_to_file(&png, filename.c_str(), 0, img, stride, nullptr) == 1)

View File

@@ -16,8 +16,8 @@ static_assert(-1 == ~0, "Two's complement required");
// deserialize little endian uint16
uint16_t sn_utils::ld_uint16(std::istream &s)
{
uint8_t buf[2];
s.read((char*)buf, 2);
std::array<uint8_t, 2> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint16_t v = static_cast<uint16_t>(buf[1] << 8 | buf[0]);
return v;
}
@@ -25,8 +25,8 @@ uint16_t sn_utils::ld_uint16(std::istream &s)
// deserialize little endian uint32
uint32_t sn_utils::ld_uint32(std::istream &s)
{
uint8_t buf[4];
s.read((char*)buf, 4);
std::array<uint8_t, 4> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint32_t v = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
return v;
}
@@ -34,8 +34,8 @@ uint32_t sn_utils::ld_uint32(std::istream &s)
// deserialize little endian int32
int32_t sn_utils::ld_int32(std::istream &s)
{
uint8_t buf[4];
s.read((char*)buf, 4);
std::array<uint8_t, 4> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint32_t v = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
return static_cast<int32_t>(v);
}
@@ -43,8 +43,8 @@ int32_t sn_utils::ld_int32(std::istream &s)
// deserialize little endian uint64
uint64_t sn_utils::ld_uint64(std::istream &s)
{
uint8_t buf[8];
s.read((char*)buf, 8);
std::array<uint8_t, 8> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint64_t v = (uint64_t)buf[7] << 56 | (uint64_t)buf[6] << 48 |
(uint64_t)buf[5] << 40 | (uint64_t)buf[4] << 32 |
(uint64_t)buf[3] << 24 | (uint64_t)buf[2] << 16 |
@@ -55,8 +55,8 @@ uint64_t sn_utils::ld_uint64(std::istream &s)
// deserialize little endian int64
int64_t sn_utils::ld_int64(std::istream &s)
{
uint8_t buf[8];
s.read((char*)buf, 8);
std::array<uint8_t, 8> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint64_t v = (uint64_t)buf[7] << 56 | (uint64_t)buf[6] << 48 |
(uint64_t)buf[5] << 40 | (uint64_t)buf[4] << 32 |
(uint64_t)buf[3] << 24 | (uint64_t)buf[2] << 16 |
@@ -67,8 +67,8 @@ int64_t sn_utils::ld_int64(std::istream &s)
// deserialize little endian ieee754 float32
float sn_utils::ld_float32(std::istream &s)
{
uint8_t buf[4];
s.read((char*)buf, 4);
std::array<uint8_t, 4> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint32_t v = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
return std::bit_cast<float>(v);
}
@@ -76,8 +76,8 @@ float sn_utils::ld_float32(std::istream &s)
// deserialize little endian ieee754 float64
double sn_utils::ld_float64(std::istream &s)
{
uint8_t buf[8];
s.read((char*)buf, 8);
std::array<uint8_t, 8> buf{};
s.read(reinterpret_cast<char *>(buf.data()), buf.size());
uint64_t v = (uint64_t)buf[7] << 56 | (uint64_t)buf[6] << 48 |
(uint64_t)buf[5] << 40 | (uint64_t)buf[4] << 32 |
(uint64_t)buf[3] << 24 | (uint64_t)buf[2] << 16 |
@@ -90,13 +90,13 @@ std::string sn_utils::d_str(std::istream &s)
{
std::string r;
r.reserve(32);
char buf[1];
char c{};
while (true)
{
s.read(buf, 1);
if (buf[0] == 0)
s.read(&c, 1);
if (c == 0)
break;
r.push_back(buf[0]);
r.push_back(c);
}
return r;
}
@@ -141,35 +141,35 @@ uint8_t sn_utils::d_uint8( std::istream& s ) {
void sn_utils::ls_uint16(std::ostream &s, uint16_t v)
{
uint8_t buf[2];
std::array<uint8_t, 2> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = v >> 8;
s.write((char*)buf, 2);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_uint32(std::ostream &s, uint32_t v)
{
uint8_t buf[4];
std::array<uint8_t, 4> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
buf[3] = v >> 24;
s.write((char*)buf, 4);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_int32(std::ostream &s, int32_t v)
{
uint8_t buf[4];
std::array<uint8_t, 4> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
buf[3] = v >> 24;
s.write((char*)buf, 4);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_uint64(std::ostream &s, uint64_t v)
{
uint8_t buf[8];
std::array<uint8_t, 8> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
@@ -178,12 +178,12 @@ void sn_utils::ls_uint64(std::ostream &s, uint64_t v)
buf[5] = static_cast<uint8_t>(v >> 40);
buf[6] = static_cast<uint8_t>(v >> 48);
buf[7] = v >> 56;
s.write((char*)buf, 8);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_int64(std::ostream &s, int64_t v)
{
uint8_t buf[8];
std::array<uint8_t, 8> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
@@ -192,24 +192,24 @@ void sn_utils::ls_int64(std::ostream &s, int64_t v)
buf[5] = static_cast<uint8_t>(v >> 40);
buf[6] = static_cast<uint8_t>(v >> 48);
buf[7] = v >> 56;
s.write((char*)buf, 8);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_float32(std::ostream &s, float t)
{
auto v = std::bit_cast<uint32_t>(t);
uint8_t buf[4];
std::array<uint8_t, 4> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
buf[3] = v >> 24;
s.write((char*)buf, 4);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::ls_float64(std::ostream &s, double t)
{
auto v = std::bit_cast<uint64_t>(t);
uint8_t buf[8];
std::array<uint8_t, 8> buf{};
buf[0] = static_cast<uint8_t>(v);
buf[1] = static_cast<uint8_t>(v >> 8);
buf[2] = static_cast<uint8_t>(v >> 16);
@@ -218,7 +218,7 @@ void sn_utils::ls_float64(std::ostream &s, double t)
buf[5] = static_cast<uint8_t>(v >> 40);
buf[6] = static_cast<uint8_t>(v >> 48);
buf[7] = v >> 56;
s.write((char*)buf, 8);
s.write(reinterpret_cast<char const *>(buf.data()), buf.size());
}
void sn_utils::s_uint8(std::ostream &s, uint8_t v)

View File

@@ -134,10 +134,10 @@ scenario_time::update( double const Deltatime ) {
int
scenario_time::year_day( int Day, const int Month, const int Year ) const {
char const daytab[ 2 ][ 13 ] = {
std::array<std::array<char, 13>, 2> const daytab = {{
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
}};
int const leap { is_leap( Year ) };
for( int i = 1; i < Month; ++i )
@@ -149,10 +149,10 @@ scenario_time::year_day( int Day, const int Month, const int Year ) const {
void
scenario_time::daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yearday ) const {
WORD daytab[ 2 ][ 13 ] = {
std::array<std::array<WORD, 13>, 2> const daytab = {{
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
}};
int const leap { is_leap( Year ) };
WORD idx = 1;
@@ -219,10 +219,10 @@ scenario_time::day_of_month( int const Week, int const Weekday, int const Month,
if( Week == 5 ) {
// 5th week potentially indicates last week in the month, not necessarily actual 5th
char const daytab[ 2 ][ 13 ] = {
std::array<std::array<char, 13>, 2> const daytab = {{
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
}};
int const leap { is_leap( Year ) };
while( day > daytab[ leap ][ Month ] ) {

View File

@@ -145,7 +145,7 @@ void motiontelemetry::update()
rot *= -1;
}
float buffer[12] = { 0 };
std::array<float, 12> buffer{};
buffer[0] = static_cast<float>(Timer::GetTime());
buffer[1] = static_cast<float>(velocity);
buffer[2] = static_cast<float>(local_acc.y);
@@ -157,6 +157,6 @@ void motiontelemetry::update()
buffer[8] = static_cast<float>(yaw_vel);
buffer[9] = 1.0f;
if (send(sock, (char*)buffer, sizeof(buffer), 0) == -1)
if (send(sock, reinterpret_cast<char const *>(buffer.data()), sizeof(buffer), 0) == -1)
WriteLog("motiontelemetry: socket send failed");
}

View File

@@ -806,10 +806,10 @@ std::shared_ptr<dictionary_source> TTrain::GetTrainState(dictionary_source const
dict->insert("traction_voltage", std::abs(mvPantographUnit->PantographVoltage));
dict->insert("voltage", std::abs(mvControlled->EngineVoltage));
dict->insert("im", std::abs(mvControlled->Im));
dict->insert("fuse", mvControlled->FuseFlag);
dict->insert("epfuse", mvOccupied->EpFuse);
dict->insert("power_drawn", mvOccupied->EnergyMeter.first);
dict->insert("power_returned", mvOccupied->EnergyMeter.second);
dict->insert("fuse", mvControlled->FuseFlag);
dict->insert("epfuse", mvOccupied->EpFuse);
dict->insert("power_drawn", mvOccupied->EnergyMeter.first);
dict->insert("power_returned", mvOccupied->EnergyMeter.second);
// induction motor state data
std::array<char const *, 10> const TXTT{"fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3"};