/usr/include/GDF/Reader.h is in libgdf-dev 0.1.2-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | //
// This file is part of libGDF.
//
// libGDF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// libGDF 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with libGDF. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2010 Martin Billinger
#ifndef __READER_H_INCLUDED__
#define __READER_H_INCLUDED__
#include "GDF/Record.h"
#include "GDF/EventHeader.h"
#include "GDF/GDFHeaderAccess.h"
#include "GDF/Types.h"
#include "GDF/tools.h"
#include <vector>
#include <string>
#include <fstream>
namespace gdf
{
/// Class for reading GDF files to disc.
/** Data Records are only read on demand and stay in memory until another file is opened or the Reader object is destroyed.
This cache can be disabled. Then each data record is loaded from disk everytime it is accessed. This saves memory, but may
severly decrease performance.
*/
class Reader
{
public:
/// Constructor
Reader( );
/// Destructor
virtual ~Reader( );
/// Opens file for reading
void open( const std::string filename );
/// Close file
void close( );
/// Enable or disable cache
void enableCache( bool b );
/// Set cache to the correct size
virtual void initCache( );
/// Reset cache to empty state
virtual void resetCache( );
/// Find Record index to which a sample belongs
size_t findRecord( uint16 channel_idx, size_t sample_idx );
/// Read Signals from file into buffer (physical units)
/** Sample values are converted to physical units.
@param[out] buffer vector; each element is a channel.
@param[in] start_time samples with n >= start_time*fs are loaded.
@param[in] end_time samples with n < end_time*fs are loaded. end_time = -1 loads the complete signal.
@param[in] signal_indices vector with signal indices that should be loaded. If empty, all signals are loaded.
*/
void getSignals( std::vector< std::vector<double> > &buffer, double start_time = 0, double end_time = -1, std::vector<uint16> signal_indices = std::vector<uint16>() );
/// Read a single channel from file into buffer.
/** The buffer must be allocated by the user, who is also responsible that enough memory is allocated.
@param[in] channel_idx index of channel to read
@param[out] buffer pointer to double array
@param[in] start_time samples with n >= start are loaded.
@param[in] end_time samples with n < end are loaded. end <= start loads the complete signal.
*/
void getSignal( uint16 channel_idx, double *buffer, size_t start = 0, size_t end = 0 );
/// Read a single Sample (physical units)
/** @param[in] channel_idx channel index
@param[in] sample_idx sample index
*/
double getSample( uint16 channel_idx, size_t sample_idx );
/// Returns a reference to Record
Record *getRecordPtr( size_t index );
/// Read directly into Record rec
void readRecord( size_t index, Record *rec );
/// Precache a range of Records
void precacheRecords( size_t start, size_t end );
/// get reference to event header
EventHeader *getEventHeader( );
/// get Constant reference to header access
const GDFHeaderAccess &getHeaderAccess_readonly( ) const { return m_header; }
/// get Constant reference to main header
const MainHeader &getMainHeader_readonly( ) const { return m_header.getMainHeader_readonly( ); }
/// get constant reference to a signal's header
const SignalHeader &getSignalHeader_readonly( size_t idx ) const { return m_header.getSignalHeader_readonly(idx); }
protected:
void readEvents( );
std::string m_filename;
GDFHeaderAccess m_header;
EventHeader *m_events;
std::vector< Record* > m_record_cache;
Record* m_record_nocache;
std::list<size_t> m_cache_entries;
std::ifstream m_file;
bool m_cache_enabled;
size_t m_record_length; /// Record length in bytes
size_t m_record_offset; /// Where data records start in the file
size_t m_event_offset; /// Where the event table starts in the file
};
}
#endif // __READER_H_INCLUDED__
|