GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
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 
30 template <class T>
32 {
33 public:
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 
47 private:
48  std::vector<boost::circular_buffer<T>> d_data;
49 };
50 
51 
52 template <class T>
54 {
55  reset();
56 }
57 
58 
59 template <class T>
60 Gnss_circular_deque<T>::Gnss_circular_deque(unsigned int max_size, unsigned int nchann)
61 {
62  reset(max_size, nchann);
63 }
64 
65 
66 template <class T>
67 unsigned int Gnss_circular_deque<T>::size(unsigned int ch) const
68 {
69  return d_data[ch].size();
70 }
71 
72 
73 template <class T>
74 T& Gnss_circular_deque<T>::back(unsigned int ch)
75 {
76  return d_data[ch].back();
77 }
78 
79 
80 template <class T>
81 T& Gnss_circular_deque<T>::front(unsigned int ch)
82 {
83  return d_data[ch].front();
84 }
85 
86 
87 template <class T>
88 T& Gnss_circular_deque<T>::at(unsigned int ch, unsigned int pos)
89 {
90  return d_data.at(ch).at(pos);
91 }
92 
93 
94 template <class T>
95 const T& Gnss_circular_deque<T>::get(unsigned int ch, unsigned int pos) const
96 {
97  return d_data[ch][pos];
98 }
99 
100 
101 template <class T>
102 void Gnss_circular_deque<T>::clear(unsigned int ch)
103 {
104  d_data[ch].clear();
105 }
106 
107 
108 template <class T>
109 void 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 
122 template <class T>
124 {
125  d_data.clear();
126 }
127 
128 
129 template <class T>
131 {
132  d_data[ch].pop_front();
133 }
134 
135 
136 template <class T>
137 void 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
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. ...
T & at(unsigned int ch, unsigned int pos)
Returns a reference to an element with bound checking.
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.
Gnss_circular_deque()
Default constructor.
void reset()
Removes all the channels (Sets nchann to 0)
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.
const T & get(unsigned int ch, unsigned int pos) const
Returns a const reference to an element without bound checking.