2018-04-09 14:16:50 +00:00
/*!
* \ 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
2018-04-09 14:16:50 +00:00
*
* Detailed description of the file here if needed .
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Copyright ( C ) 2010 - 2018 ( see AUTHORS file for a list of contributors )
*
* GNSS - SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS - SDR .
*
* GNSS - SDR is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* GNSS - SDR is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2018-05-13 20:49:11 +00:00
* along with GNSS - SDR . If not , see < https : //www.gnu.org/licenses/>.
2018-04-09 14:16:50 +00:00
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
# ifndef GNSS_SDR_CIRCULAR_DEQUE_H_
# define GNSS_SDR_CIRCULAR_DEQUE_H_
2018-12-09 21:00:09 +00:00
2018-04-10 14:05:22 +00:00
# include <boost/circular_buffer.hpp>
2018-12-09 21:00:09 +00:00
# include <vector>
2018-04-09 14:16:50 +00:00
template < class T >
class Gnss_circular_deque
{
public :
2018-04-10 14:05:22 +00:00
Gnss_circular_deque ( ) ; // Default constructor
Gnss_circular_deque ( const unsigned int max_size , const unsigned int nchann ) ; // nchann = number of channels; max_size = channel capacity
unsigned int size ( const unsigned int ch ) ; // Returns the number of available elements in a channel
T & at ( const unsigned int ch , const unsigned int pos ) ; // Returns a reference to an element
T & front ( const unsigned int ch ) ; // Returns a reference to the first element in the deque
T & back ( const unsigned int ch ) ; // Returns a reference to the last element in the deque
void push_back ( const unsigned int ch , const T & new_data ) ; // Inserts an element at the end of the deque
void pop_front ( const unsigned int ch ) ; // Removes the first element of the deque
void clear ( const unsigned int ch ) ; // Removes all the elements of the deque (Sets size to 0). Capacity is not modified
void reset ( const unsigned int max_size , const 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)
2018-04-09 14:16:50 +00:00
private :
2018-04-10 14:05:22 +00:00
std : : vector < boost : : circular_buffer < T > > d_data ;
2018-04-09 14:16:50 +00:00
} ;
template < class T >
Gnss_circular_deque < T > : : Gnss_circular_deque ( )
{
2018-04-10 14:05:22 +00:00
reset ( ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
Gnss_circular_deque < T > : : Gnss_circular_deque ( const unsigned int max_size , const unsigned int nchann )
{
2018-04-10 14:05:22 +00:00
reset ( max_size , nchann ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
unsigned int Gnss_circular_deque < T > : : size ( const unsigned int ch )
{
2018-04-10 14:05:22 +00:00
return d_data . at ( ch ) . size ( ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
T & Gnss_circular_deque < T > : : back ( const unsigned int ch )
{
2018-04-10 14:05:22 +00:00
return d_data . at ( ch ) . back ( ) ;
2018-04-09 14:16:50 +00:00
}
2018-04-10 14:05:22 +00:00
2018-04-09 14:16:50 +00:00
template < class T >
T & Gnss_circular_deque < T > : : front ( const unsigned int ch )
{
2018-04-10 14:05:22 +00:00
return d_data . at ( ch ) . front ( ) ;
2018-04-09 14:16:50 +00:00
}
2018-04-10 14:05:22 +00:00
2018-04-09 14:16:50 +00:00
template < class T >
T & Gnss_circular_deque < T > : : at ( const unsigned int ch , const unsigned int pos )
{
2018-04-10 14:05:22 +00:00
return d_data . at ( ch ) . at ( pos ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
void Gnss_circular_deque < T > : : clear ( const unsigned int ch )
{
2018-04-10 14:05:22 +00:00
d_data . at ( ch ) . clear ( ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
2018-04-10 14:05:22 +00:00
void Gnss_circular_deque < T > : : reset ( const unsigned int max_size , const unsigned int nchann )
2018-04-09 14:16:50 +00:00
{
2018-04-10 14:05:22 +00:00
d_data . clear ( ) ;
if ( max_size > 0 and nchann > 0 )
2018-04-09 14:16:50 +00:00
{
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
}
2018-04-09 14:16:50 +00:00
}
}
template < class T >
2018-04-10 14:05:22 +00:00
void Gnss_circular_deque < T > : : reset ( )
2018-04-09 14:16:50 +00:00
{
2018-04-10 14:05:22 +00:00
d_data . clear ( ) ;
2018-04-09 14:16:50 +00:00
}
template < class T >
2018-04-10 14:05:22 +00:00
void Gnss_circular_deque < T > : : pop_front ( const unsigned int ch )
2018-04-09 14:16:50 +00:00
{
2018-04-10 14:05:22 +00:00
d_data . at ( ch ) . pop_front ( ) ;
2018-04-09 14:16:50 +00:00
}
2018-04-10 14:05:22 +00:00
template < class T >
void Gnss_circular_deque < T > : : push_back ( const unsigned int ch , const T & new_data )
{
d_data . at ( ch ) . push_back ( new_data ) ;
}
2018-04-09 14:16:50 +00:00
# endif /* GNSS_SDR_CIRCULAR_DEQUE_H_ */