GNSS-SDR  0.0.13
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  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
10  *
11  * GNSS-SDR is a software defined Global Navigation
12  * Satellite Systems receiver
13  *
14  * This file is part of GNSS-SDR.
15  *
16  * SPDX-License-Identifier: GPL-3.0-or-later
17  *
18  * -----------------------------------------------------------------------------
19  */
20 
21 #ifndef GNSS_SDR_CIRCULAR_DEQUE_H
22 #define GNSS_SDR_CIRCULAR_DEQUE_H
23 
24 #include <boost/circular_buffer.hpp>
25 #include <vector>
26 
27 template <class T>
29 {
30 public:
31  Gnss_circular_deque(); //!< Default constructor
32  Gnss_circular_deque(unsigned int max_size, unsigned int nchann); //!< nchann = number of channels; max_size = channel capacity
33  unsigned int size(unsigned int ch); //!< Returns the number of available elements in a channel
34  T& at(unsigned int ch, unsigned int pos); //!< Returns a reference to an element with bount checking
35  const T& get(unsigned int ch, unsigned int pos) const; //!< Returns a const reference to an element without bound checking
36  T& front(unsigned int ch); //!< Returns a reference to the first element in the deque
37  T& back(unsigned int ch); //!< Returns a reference to the last element in the deque
38  void push_back(unsigned int ch, const T& new_data); //!< Inserts an element at the end of the deque
39  void pop_front(unsigned int ch); //!< Removes the first element of the deque
40  void clear(unsigned int ch); //!< Removes all the elements of the deque (Sets size to 0). Capacity is not modified
41  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
42  void reset(); //!< Removes all the channels (Sets nchann to 0)
43 
44 private:
45  std::vector<boost::circular_buffer<T>> d_data;
46 };
47 
48 
49 template <class T>
51 {
52  reset();
53 }
54 
55 
56 template <class T>
57 Gnss_circular_deque<T>::Gnss_circular_deque(unsigned int max_size, unsigned int nchann)
58 {
59  reset(max_size, nchann);
60 }
61 
62 
63 template <class T>
64 unsigned int Gnss_circular_deque<T>::size(unsigned int ch)
65 {
66  return d_data[ch].size();
67 }
68 
69 
70 template <class T>
71 T& Gnss_circular_deque<T>::back(unsigned int ch)
72 {
73  return d_data[ch].back();
74 }
75 
76 
77 template <class T>
78 T& Gnss_circular_deque<T>::front(unsigned int ch)
79 {
80  return d_data[ch].front();
81 }
82 
83 
84 template <class T>
85 T& Gnss_circular_deque<T>::at(unsigned int ch, unsigned int pos)
86 {
87  return d_data.at(ch).at(pos);
88 }
89 
90 
91 template <class T>
92 const T& Gnss_circular_deque<T>::get(unsigned int ch, unsigned int pos) const
93 {
94  return d_data[ch][pos];
95 }
96 
97 
98 template <class T>
99 void Gnss_circular_deque<T>::clear(unsigned int ch)
100 {
101  d_data[ch].clear();
102 }
103 
104 
105 template <class T>
106 void Gnss_circular_deque<T>::reset(unsigned int max_size, unsigned int nchann)
107 {
108  d_data.clear();
109  if (max_size > 0 and nchann > 0)
110  {
111  for (unsigned int i = 0; i < nchann; i++)
112  {
113  d_data.push_back(boost::circular_buffer<T>(max_size));
114  }
115  }
116 }
117 
118 
119 template <class T>
121 {
122  d_data.clear();
123 }
124 
125 
126 template <class T>
128 {
129  d_data[ch].pop_front();
130 }
131 
132 
133 template <class T>
134 void Gnss_circular_deque<T>::push_back(unsigned int ch, const T& new_data)
135 {
136  d_data[ch].push_back(new_data);
137 }
138 
139 #endif // GNSS_SDR_CIRCULAR_DEQUE_H
const T & get(unsigned int ch, unsigned int pos) const
Returns a const reference to an element without bound checking.
T & at(unsigned int ch, unsigned int pos)
Returns a reference to an element with bount checking.
unsigned int size(unsigned int ch)
Returns the number of available elements in a channel.
void clear(unsigned int ch)
Removes all the elements of the deque (Sets size to 0). Capacity is not modified. ...
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.
T & front(unsigned int ch)
Returns a reference to the first element in the deque.
void pop_front(unsigned int ch)
Removes the first element of the deque.
Gnss_circular_deque()
Default constructor.