GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
gnss_circular_deque.h
Go to the documentation of this file.
1/*!
2 * \file gnss_circular_deque.h
3 * \brief This class implements a circular deque for Gnss_Synchro
4 * \author Antonio Ramos, 2018. antonio.ramosdet(at)gmail.com
5 *
6 *
7 * -----------------------------------------------------------------------------
8 *
9 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
10 * This file is part of GNSS-SDR.
11 *
12 * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
13 * SPDX-License-Identifier: GPL-3.0-or-later
14 *
15 * -----------------------------------------------------------------------------
16 */
17
18#ifndef GNSS_SDR_CIRCULAR_DEQUE_H
19#define GNSS_SDR_CIRCULAR_DEQUE_H
20
21#include <boost/circular_buffer.hpp>
22#include <vector>
23
24/** \addtogroup Algorithms_Library
25 * \{ */
26/** \addtogroup Algorithm_libs algorithms_libs
27 * \{ */
28
29
30template <class T>
32{
33public:
34 Gnss_circular_deque(); //!< Default constructor
35 Gnss_circular_deque(unsigned int max_size, unsigned int nchann); //!< nchann = number of channels; max_size = channel capacity
36 unsigned int size(unsigned int ch) const; //!< Returns the number of available elements in a channel
37 T& at(unsigned int ch, unsigned int pos); //!< Returns a reference to an element with bound checking
38 const T& get(unsigned int ch, unsigned int pos) const; //!< Returns a const reference to an element without bound checking
39 T& front(unsigned int ch); //!< Returns a reference to the first element in the deque
40 T& back(unsigned int ch); //!< Returns a reference to the last element in the deque
41 void push_back(unsigned int ch, const T& new_data); //!< Inserts an element at the end of the deque
42 void pop_front(unsigned int ch); //!< Removes the first element of the deque
43 void clear(unsigned int ch); //!< Removes all the elements of the deque (Sets size to 0). Capacity is not modified
44 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
45 void reset(); //!< Removes all the channels (Sets nchann to 0)
46
47private:
48 std::vector<boost::circular_buffer<T>> d_data;
49};
50
51
52template <class T>
57
58
59template <class T>
60Gnss_circular_deque<T>::Gnss_circular_deque(unsigned int max_size, unsigned int nchann)
61{
62 reset(max_size, nchann);
63}
64
65
66template <class T>
67unsigned int Gnss_circular_deque<T>::size(unsigned int ch) const
68{
69 return d_data[ch].size();
70}
71
72
73template <class T>
75{
76 return d_data[ch].back();
77}
78
79
80template <class T>
82{
83 return d_data[ch].front();
84}
85
86
87template <class T>
88T& Gnss_circular_deque<T>::at(unsigned int ch, unsigned int pos)
89{
90 return d_data.at(ch).at(pos);
91}
92
93
94template <class T>
95const T& Gnss_circular_deque<T>::get(unsigned int ch, unsigned int pos) const
96{
97 return d_data[ch][pos];
98}
99
100
101template <class T>
102void Gnss_circular_deque<T>::clear(unsigned int ch)
103{
104 d_data[ch].clear();
105}
106
107
108template <class T>
109void Gnss_circular_deque<T>::reset(unsigned int max_size, unsigned int nchann)
110{
111 d_data.clear();
112 if (max_size > 0 and nchann > 0)
113 {
114 for (unsigned int i = 0; i < nchann; i++)
115 {
116 d_data.push_back(boost::circular_buffer<T>(max_size));
117 }
118 }
119}
120
121
122template <class T>
124{
125 d_data.clear();
126}
127
128
129template <class T>
131{
132 d_data[ch].pop_front();
133}
134
135
136template <class T>
137void Gnss_circular_deque<T>::push_back(unsigned int ch, const T& new_data)
138{
139 d_data[ch].push_back(new_data);
140}
141
142
143/** \} */
144/** \} */
145#endif // GNSS_SDR_CIRCULAR_DEQUE_H
void reset()
Removes all the channels (Sets nchann to 0).
void push_back(unsigned int ch, const T &new_data)
Inserts an element at the end of the deque.
T & back(unsigned int ch)
Returns a reference to the last element in the deque.
unsigned int size(unsigned int ch) const
Returns the number of available elements in a channel.
void pop_front(unsigned int ch)
Removes the first element of the deque.
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.
T & at(unsigned int ch, unsigned int pos)
Returns a reference to an element with bound checking.
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.
void clear(unsigned int ch)
Removes all the elements of the deque (Sets size to 0). Capacity is not modified.
Gnss_circular_deque()
Default constructor.