1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-12 11:10:33 +00:00

Fixes for C++ standards older than 20. Avoid C++20-specific lambda templates

This commit is contained in:
Carles Fernandez 2024-08-19 09:27:29 +02:00
parent da21ff4fd9
commit e37855d43e
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
8 changed files with 132 additions and 82 deletions

View File

@ -8,7 +8,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -17,22 +17,14 @@
#include "ion_gsms.h"
#include "gnuradio/block.h"
#include <algorithm>
#include <memory>
#include <vector>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#include <utility>
#endif
#include <cmath>
using namespace std::string_literals;
IONGSMSFileSource::IONGSMSFileSource(
const ConfigurationInterface* configuration __attribute__((unused)),
const std::string& role __attribute__((unused)),
const std::filesystem::path& metadata_filepath,
const fs::path& metadata_filepath,
const GnssMetadata::File& file,
const GnssMetadata::Block& block,
const std::vector<std::string>& stream_ids)
@ -40,13 +32,11 @@ IONGSMSFileSource::IONGSMSFileSource(
"ion_gsms_file_source",
gr::io_signature::make(0, 0, 0),
make_output_signature(block, stream_ids)),
file_metadata_(file),
block_metadata_(block),
io_buffer_offset_(0),
maximum_item_rate_(0),
chunk_cycle_length_(0)
{
std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value();
fs::path data_filepath = metadata_filepath.parent_path() / file.Url().Value();
fd_ = std::fopen(data_filepath.c_str(), "rb");
std::size_t block_offset = file.Offset();
std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET);
@ -67,11 +57,13 @@ IONGSMSFileSource::IONGSMSFileSource(
output_stream_count_ = output_stream_offset;
}
IONGSMSFileSource::~IONGSMSFileSource()
{
std::fclose(fd_);
}
int IONGSMSFileSource::work(
int noutput_items,
gr_vector_const_void_star& input_items __attribute__((unused)),
@ -106,11 +98,13 @@ int IONGSMSFileSource::work(
return WORK_CALLED_PRODUCE;
}
std::size_t IONGSMSFileSource::output_stream_count() const
{
return output_stream_count_;
}
std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) const
{
return output_stream_item_sizes_[stream_index];

View File

@ -8,7 +8,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -19,14 +19,20 @@
#include "configuration_interface.h"
#include "gnss_block_interface.h"
#include "gnss_sdr_filesystem.h"
#include "ion_gsms_chunk_data.h"
#include <gnuradio/block.h>
#include <gnuradio/sync_block.h>
#include <filesystem>
#include <cstddef>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
/** \addtogroup Signal_Source
* \{ */
/** \addtogroup Signal_Source_libs
* \{ */
class IONGSMSFileSource : public gr::sync_block
{
@ -36,7 +42,7 @@ public:
IONGSMSFileSource(
const ConfigurationInterface* configuration,
const std::string& role,
const std::filesystem::path& metadata_filepath,
const fs::path& metadata_filepath,
const GnssMetadata::File& file,
const GnssMetadata::Block& block,
const std::vector<std::string>& stream_ids);
@ -54,9 +60,6 @@ public:
private:
static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector<std::string>& stream_ids);
private:
const GnssMetadata::File& file_metadata_;
const GnssMetadata::Block& block_metadata_;
FILE* fd_;
std::vector<uint8_t> io_buffer_;
std::size_t io_buffer_offset_;
@ -70,5 +73,6 @@ private:
#include "ion_gsms_metadata_handler.h"
/** \} */
/** \} */
#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H

View File

@ -8,31 +8,30 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
*/
#include "ion_gsms_chunk_data.h"
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#endif
IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::vector<std::string>& stream_ids, std::size_t output_stream_offset)
: chunk_(chunk),
sizeword_(chunk_.SizeWord()),
countwords_(chunk_.CountWords())
{
with_word_type(sizeword_, [&]<typename WordType> {
buffer_ = new WordType[countwords_];
});
// Instantiate the Allocator functor
Allocator allocator(countwords_, buffer_);
// Call with_word_type with the Allocator functor
with_word_type(sizeword_, allocator);
const std::size_t total_bitsize = sizeword_ * countwords_ * 8;
std::size_t used_bitsize = 0;
@ -81,11 +80,11 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::
IONGSMSChunkData::~IONGSMSChunkData()
{
with_word_type(sizeword_, [&]<typename WordType> {
delete[] static_cast<WordType*>(buffer_);
});
Deleter deleter(static_cast<void*>(buffer_));
with_word_type(sizeword_, deleter);
}
std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offset)
{
memset(buffer_, 0, sizeword_ * countwords_);
@ -93,6 +92,7 @@ std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offs
return sizeword_ * countwords_;
}
void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, std::vector<int>& output_items)
{
switch (sizeword_)
@ -121,11 +121,13 @@ std::size_t IONGSMSChunkData::output_stream_count() const
return output_stream_count_;
}
std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) const
{
return output_stream_item_size_[stream_index];
}
std::size_t IONGSMSChunkData::output_stream_item_rate(std::size_t stream_index) const
{
return output_stream_item_rate_[stream_index];
@ -165,6 +167,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector<in
}
}
template <typename WT>
std::size_t IONGSMSChunkData::write_stream_samples(
IONGSMSChunkUnpackingCtx<WT>& ctx,
@ -185,24 +188,25 @@ std::size_t IONGSMSChunkData::write_stream_samples(
if (sample_bitsize <= 8)
{
write_n_samples<WT, int8_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int8_t**)(out));
write_n_samples<WT, int8_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast<int8_t**>(out));
}
else if (sample_bitsize <= 16)
{
write_n_samples<WT, int16_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int16_t**)(out));
write_n_samples<WT, int16_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast<int16_t**>(out));
}
else if (sample_bitsize <= 32)
{
write_n_samples<WT, int32_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int32_t**)(out));
write_n_samples<WT, int32_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast<int32_t**>(out));
}
else if (sample_bitsize <= 64)
{
write_n_samples<WT, int64_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int64_t**)(out));
write_n_samples<WT, int64_t>(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast<int64_t**>(out));
}
return sample_count;
}
template <typename WT, typename OT>
void IONGSMSChunkData::write_n_samples(
IONGSMSChunkUnpackingCtx<WT>& ctx,
@ -241,22 +245,23 @@ void IONGSMSChunkData::write_n_samples(
// Static utilities
void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, auto* sample, const GnssMetadata::StreamEncoding encoding)
template <typename Sample>
void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, Sample* sample, const GnssMetadata::StreamEncoding encoding)
{
using SampleType = std::remove_pointer_t<decltype(sample)>;
// using SampleType = std::remove_pointer_t<decltype(sample)>;
switch (sample_bitsize)
{
case 2:
*sample = GnssMetadata::two_bit_look_up<SampleType>[encoding][*sample];
*sample = GnssMetadata::two_bit_look_up<Sample>[encoding][*sample];
break;
case 3:
*sample = GnssMetadata::three_bit_look_up<SampleType>[encoding][*sample];
*sample = GnssMetadata::three_bit_look_up<Sample>[encoding][*sample];
break;
case 4:
*sample = GnssMetadata::four_bit_look_up<SampleType>[encoding][*sample];
*sample = GnssMetadata::four_bit_look_up<Sample>[encoding][*sample];
break;
case 5:
*sample = GnssMetadata::five_bit_look_up<SampleType>[encoding][*sample];
*sample = GnssMetadata::five_bit_look_up<Sample>[encoding][*sample];
break;
default:
// TODO - Is this an error that can happen?

View File

@ -8,7 +8,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -21,16 +21,14 @@
#include "ion_gsms_chunk_unpacking_ctx.h"
#include "ion_gsms_stream_encodings.h"
#include <gnuradio/block.h>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#endif
inline std::size_t bits_to_item_size(const std::size_t bit_count)
inline std::size_t bits_to_item_size(std::size_t bit_count)
{
if (bit_count <= 8)
{
@ -50,11 +48,46 @@ inline std::size_t bits_to_item_size(const std::size_t bit_count)
}
// You are asking too much of this humble processor
LOG(ERROR) << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense.";
std::cerr << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense.\n";
return 1;
}
void with_word_type(const uint8_t word_size, auto&& callback)
// Define a functor that has a templated operator()
struct Allocator
{
size_t countwords_;
void*& buffer_; // Using void* to hold any type of pointer
Allocator(size_t countwords, void*& buffer)
: countwords_(countwords), buffer_(buffer) {}
template <typename WordType>
void operator()() const
{
buffer_ = new WordType[countwords_];
}
};
// Define a functor to delete the allocated memory
struct Deleter
{
void* buffer_;
explicit Deleter(void* buffer)
: buffer_(buffer) {}
template <typename WordType>
void operator()() const
{
delete[] static_cast<WordType*>(buffer_);
}
};
template <typename Callback>
void with_word_type(uint8_t word_size, Callback callback)
{
switch (word_size)
{
@ -71,7 +104,7 @@ void with_word_type(const uint8_t word_size, auto&& callback)
callback.template operator()<int64_t>();
break;
default:
LOG(ERROR) << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense.";
std::cerr << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense.\n";
break;
}
}
@ -118,9 +151,9 @@ private:
GnssMetadata::StreamEncoding stream_encoding,
OT** out);
static void decode_sample(uint8_t sample_bitsize, auto* sample, GnssMetadata::StreamEncoding encoding);
template <typename Sample>
static void decode_sample(uint8_t sample_bitsize, Sample* sample, GnssMetadata::StreamEncoding encoding);
private:
const GnssMetadata::Chunk& chunk_;
uint8_t sizeword_;
uint8_t countwords_;

View File

@ -10,7 +10,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -21,12 +21,12 @@
#include "GnssMetadata.h"
#include <gnuradio/block.h>
#include <cstdint>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#endif
/** \addtogroup Signal_Source
* \{ */
/** \addtogroup Signal_Source_libs
* \{ */
template <typename WT>
struct IONGSMSChunkUnpackingCtx
@ -118,7 +118,7 @@ struct IONGSMSChunkUnpackingCtx
}
template <typename OT>
void shift_sample(const uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0)
void shift_sample(uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0)
{
if (sample_bitsize % word_bitsize_ == 0)
{
@ -176,4 +176,6 @@ struct IONGSMSChunkUnpackingCtx
}
};
/** \} */
/** \} */
#endif // ION_GSM_CHUNK_UNPACKING_CTX_H

View File

@ -8,14 +8,14 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
*/
#include "ion_gsms.h"
#include <cstdlib>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
@ -40,16 +40,25 @@ void IONGSMSMetadataHandler::load_metadata()
GnssMetadata::XmlProcessor xml_proc;
if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_))
{
LOG(ERROR) << "Could not load XML metadata file:";
LOG(WARNING) << "Could not load XML metadata file " << metadata_filepath_;
std::cerr << "Could not load XML metadata file " << metadata_filepath_ << std::endl;
std::cout << "GNSS-SDR program ended.\n";
exit(1);
}
}
catch (GnssMetadata::ApiException& e)
{
LOG(ERROR) << "API Exception while loading XML metadata file: " << std::to_string(e.Error());
LOG(WARNING) << "API Exception while loading XML metadata file: " << std::to_string(e.Error());
std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << std::to_string(e.Error()) << std::endl;
std::cout << "GNSS-SDR program ended.\n";
exit(1);
}
catch (std::exception& e)
{
LOG(ERROR) << "Exception while loading XML metadata file: " << e.what();
LOG(WARNING) << "Exception while loading XML metadata file: " << e.what();
std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << e.what() << std::endl;
std::cout << "GNSS-SDR program ended.\n";
exit(1);
}
}

View File

@ -8,7 +8,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -23,11 +23,11 @@
#include <string>
#include <vector>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#endif
/** \addtogroup Signal_Source
* \{ */
/** \addtogroup Signal_Source_libs
* \{ */
class IONGSMSMetadataHandler
{
@ -35,16 +35,17 @@ public:
explicit IONGSMSMetadataHandler(const std::string& metadata_filepath);
std::vector<IONGSMSFileSource::sptr> make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector<std::string>& stream_ids) const;
public: // Getters
const std::string& metadata_filepath() const;
private: // Private methods
private:
void load_metadata();
private: // State
// State
std::string metadata_filepath_;
GnssMetadata::Metadata metadata_;
};
/** \} */
/** \} */
#endif // ION_GSMS_METADATA_HANDLER_H

View File

@ -10,7 +10,7 @@
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@ -21,11 +21,10 @@
#include <string>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#endif
/** \addtogroup Signal_Source
* \{ */
/** \addtogroup Signal_Source_libs
* \{ */
namespace GnssMetadata
{
@ -165,4 +164,7 @@ inline T five_bit_look_up[11][32]{
} // namespace GnssMetadata
/** \} */
/** \} */
#endif // ION_GSM_STREAM_ENCODINGS_H