1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-10-31 07:06:23 +00:00
gnss-sdr/src/algorithms/libs/gnss_circular_deque.h

146 lines
4.0 KiB
C
Raw Normal View History

/*!
* \file gnss_circular_deque.h
* \brief This class implements a circular deque for Gnss_Synchro
2018-04-12 15:14:57 +00:00
* \author Antonio Ramos, 2018. antonio.ramosdet(at)gmail.com
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*
* 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)
* SPDX-License-Identifier: GPL-3.0-or-later
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_CIRCULAR_DEQUE_H
#define GNSS_SDR_CIRCULAR_DEQUE_H
2018-04-10 14:05:22 +00:00
#include <boost/circular_buffer.hpp>
#include <vector>
/** \addtogroup Algorithms_Library
* \{ */
/** \addtogroup Algorithm_libs algorithms_libs
* \{ */
template <class T>
class Gnss_circular_deque
{
public:
2019-09-09 21:31:20 +00:00
Gnss_circular_deque(); //!< Default constructor
Gnss_circular_deque(unsigned int max_size, unsigned int nchann); //!< nchann = number of channels; max_size = channel capacity
2020-08-20 22:31:46 +00:00
unsigned int size(unsigned int ch) const; //!< Returns the number of available elements in a channel
T& at(unsigned int ch, unsigned int pos); //!< Returns a reference to an element with bound checking
2019-09-09 21:31:20 +00:00
const T& get(unsigned int ch, unsigned int pos) const; //!< Returns a const reference to an element without bound checking
T& front(unsigned int ch); //!< Returns a reference to the first element in the deque
T& back(unsigned int ch); //!< Returns a reference to the last element in the deque
void push_back(unsigned int ch, const T& new_data); //!< Inserts an element at the end of the deque
void pop_front(unsigned int ch); //!< Removes the first element of the deque
void clear(unsigned int ch); //!< Removes all the elements of the deque (Sets size to 0). Capacity is not modified
void reset(unsigned int max_size, unsigned int nchann); //!< Removes all the elements in all the channels. Re-sets the number of channels and their capacity
void reset(); //!< Removes all the channels (Sets nchann to 0)
private:
2018-04-10 14:05:22 +00:00
std::vector<boost::circular_buffer<T>> d_data;
};
template <class T>
Gnss_circular_deque<T>::Gnss_circular_deque()
{
2018-04-10 14:05:22 +00:00
reset();
}
2019-07-28 10:01:11 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
Gnss_circular_deque<T>::Gnss_circular_deque(unsigned int max_size, unsigned int nchann)
{
2018-04-10 14:05:22 +00:00
reset(max_size, nchann);
}
2019-07-28 10:01:11 +00:00
template <class T>
2020-08-20 22:31:46 +00:00
unsigned int Gnss_circular_deque<T>::size(unsigned int ch) const
{
2019-09-09 21:31:20 +00:00
return d_data[ch].size();
}
2019-07-28 10:01:11 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
T& Gnss_circular_deque<T>::back(unsigned int ch)
{
2019-09-09 21:31:20 +00:00
return d_data[ch].back();
}
2018-04-10 14:05:22 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
T& Gnss_circular_deque<T>::front(unsigned int ch)
{
2019-09-09 21:31:20 +00:00
return d_data[ch].front();
}
2018-04-10 14:05:22 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
T& Gnss_circular_deque<T>::at(unsigned int ch, unsigned int pos)
{
2018-04-10 14:05:22 +00:00
return d_data.at(ch).at(pos);
}
2019-07-28 10:01:11 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
const T& Gnss_circular_deque<T>::get(unsigned int ch, unsigned int pos) const
{
return d_data[ch][pos];
}
template <class T>
2019-09-09 21:31:20 +00:00
void Gnss_circular_deque<T>::clear(unsigned int ch)
{
2019-09-09 21:31:20 +00:00
d_data[ch].clear();
}
2019-07-28 10:01:11 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
void Gnss_circular_deque<T>::reset(unsigned int max_size, unsigned int nchann)
{
2018-04-10 14:05:22 +00:00
d_data.clear();
if (max_size > 0 and nchann > 0)
{
2018-04-10 14:05:22 +00:00
for (unsigned int i = 0; i < nchann; i++)
2018-04-10 13:37:07 +00:00
{
2018-04-10 14:05:22 +00:00
d_data.push_back(boost::circular_buffer<T>(max_size));
2018-04-10 13:37:07 +00:00
}
}
}
2019-07-28 10:01:11 +00:00
template <class T>
2018-04-10 14:05:22 +00:00
void Gnss_circular_deque<T>::reset()
{
2018-04-10 14:05:22 +00:00
d_data.clear();
}
2019-07-28 10:01:11 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
void Gnss_circular_deque<T>::pop_front(unsigned int ch)
{
2019-09-09 21:31:20 +00:00
d_data[ch].pop_front();
}
2019-07-28 10:01:11 +00:00
2018-04-10 14:05:22 +00:00
template <class T>
2019-09-09 21:31:20 +00:00
void Gnss_circular_deque<T>::push_back(unsigned int ch, const T& new_data)
2018-04-10 14:05:22 +00:00
{
2019-09-09 21:31:20 +00:00
d_data[ch].push_back(new_data);
2018-04-10 14:05:22 +00:00
}
/** \} */
/** \} */
#endif // GNSS_SDR_CIRCULAR_DEQUE_H