Houston, we have a trunk.
[debian/gnuradio] / gr-radar / src / lib / time_series.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 #ifndef INCLUDED_TIME_SERIES_H
23 #define INCLUDED_TIME_SERIES_H
24
25 #include <string>
26
27 /*!
28  * \brief Memory mapped input for complex time series data
29  *
30  * Inspired by "iqts" by John Sahr, Univ of Washington
31  */
32
33 class time_series {
34   size_t                d_itemsize;         // user specified item size
35   std::string           d_filename;
36   int                   d_fd;               // file descriptor
37   unsigned long long    d_filesize;         // in bytes
38   unsigned long long    d_start;            // in items
39   unsigned long long    d_limit;            // in items
40   void                 *d_buffer;           // points to base of file
41
42 public:
43   /*!
44    * \brief Create read-only mapped file accessor.
45    * \param item_size            size of item in bytes
46    * \param filename             name of file to open
47    * \param starting_offset      offset in file in item_size units at which to start
48    * \param nsamples_to_process  maximum number of samples to map in starting at \p start.  -1 implies no limit.
49    *
50    * \throws string on error opening file, etc.
51    */
52   time_series(size_t item_size, const std::string filename,
53               unsigned long long starting_offset=0,
54               long long nsamples_to_process=-1);
55   ~time_series();
56
57   /*!
58    * \brief Return a pointer to a buffer of data at file offset pos.
59    *
60    * \param pos         offset from beginning of file in itemsize units.
61    * \param blocksize   minimum size of returned buffer in itemsize units.
62    *
63    * "Seek" to pos in file and return a pointer to the data at that
64    * location.  The returned pointer will have at least blocksize valid 
65    * elements.  Return 0 if pos is out of bounds, or if there isn't
66    * at least blocksize units available in the file.
67    */
68   const void *seek(unsigned long long pos, unsigned long long blocksize) const;
69
70   long long nsamples_available(unsigned long long pos) const;
71 };
72
73 #endif /* INCLUDED_TIME_SERIES_H */