libGDF
Reader.h
00001 //
00002 // This file is part of libGDF.
00003 //
00004 // libGDF is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation, either version 3 of
00007 // the License, or (at your option) any later version.
00008 //
00009 // libGDF is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with libGDF.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // Copyright 2010 Martin Billinger
00018 
00019 #ifndef __READER_H_INCLUDED__
00020 #define __READER_H_INCLUDED__
00021 
00022 #include "GDF/Record.h"
00023 #include "GDF/EventHeader.h"
00024 #include "GDF/GDFHeaderAccess.h"
00025 #include "GDF/Types.h"
00026 #include "GDF/tools.h"
00027 #include <vector>
00028 #include <string>
00029 #include <fstream>
00030 
00031 namespace gdf
00032 {
00034 
00038     class Reader
00039     {
00040     public:
00042         Reader( );
00043 
00045         virtual ~Reader( );
00046 
00048         void open( const std::string filename );
00049 
00051         void close( );
00052 
00054         void enableCache( bool b );
00055 
00057         virtual void initCache( );
00058 
00060         virtual void resetCache( );
00061 
00063         size_t findRecord( uint16 channel_idx, size_t sample_idx );
00064 
00066 
00072         void getSignals( std::vector< std::vector<double> > &buffer, double start_time = 0, double end_time = -1, std::vector<uint16> signal_indices = std::vector<uint16>() );
00073 
00075 
00081         void getSignal( uint16 channel_idx, double *buffer, size_t start = 0, size_t end = 0 );
00082 
00084 
00087         double getSample( uint16 channel_idx, size_t sample_idx );
00088 
00090         Record *getRecordPtr( size_t index );
00091 
00093         void readRecord( size_t index, Record *rec );
00094 
00096         void precacheRecords( size_t start, size_t end );
00097 
00099         EventHeader *getEventHeader( );
00100 
00102         const GDFHeaderAccess &getHeaderAccess_readonly( ) const { return m_header; }
00103 
00105         const MainHeader &getMainHeader_readonly( ) const { return m_header.getMainHeader_readonly( ); }
00106 
00108         const SignalHeader &getSignalHeader_readonly( size_t idx ) const { return m_header.getSignalHeader_readonly(idx); }
00109 
00110     protected:
00111         void readEvents( );
00112 
00113         std::string m_filename;
00114         GDFHeaderAccess m_header;
00115         EventHeader *m_events;
00116         std::vector< Record* > m_record_cache;
00117         Record* m_record_nocache;
00118         std::list<size_t> m_cache_entries;
00119         std::ifstream m_file;
00120         bool m_cache_enabled;
00121 
00122         size_t m_record_length; 
00123         size_t m_record_offset; 
00124         size_t m_event_offset;  
00125     };
00126 }
00127 
00128 #endif // __READER_H_INCLUDED__
 All Data Structures Functions Variables Friends