libGDF
SignalHeader.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 __SIGNALHEADER_H_INCLUDED__
00020 #define __SIGNALHEADER_H_INCLUDED__
00021 
00022 #include "HeaderItem.h"
00023 #include <boost/numeric/conversion/cast.hpp>
00024 
00025 namespace gdf
00026 {
00027     class GDFHeaderAccess;
00028 
00030     class SignalHeader
00031     {
00032         GDF_DECLARE_HEADERSTRING( label, 0, 16 )
00033         GDF_DECLARE_HEADERSTRING( transducer_type, 16, 80)
00034         GDF_DECLARE_HEADERSTRING( physical_dimension, 96, 6)  // the spec defines this as a 6 byte long char[8]
00035         GDF_DECLARE_HEADERITEM( physical_dimension_code, uint16, 102 )
00036         GDF_DECLARE_HEADERITEM( physmin, float64, 104 )
00037         GDF_DECLARE_HEADERITEM( physmax, float64, 112 )
00038         GDF_DECLARE_HEADERITEM( digmin, float64, 120 )
00039         GDF_DECLARE_HEADERITEM( digmax, float64, 128 )
00040         GDF_DECLARE_RESERVED( reserved_1, 136, 68 )
00041         GDF_DECLARE_HEADERITEM( lowpass, float32, 204 )
00042         GDF_DECLARE_HEADERITEM( highpass, float32, 208 )
00043         GDF_DECLARE_HEADERITEM( notch, float32, 212 )
00044         GDF_DECLARE_HEADERITEM_PRIVATE( samples_per_record, uint32, 216 )
00045         GDF_DECLARE_HEADERITEM( datatype, uint32, 220 )
00046         GDF_DECLARE_HEADERARRAY( sensor_pos, float32, 224, 3 )
00047         GDF_DECLARE_HEADERITEM( sensor_info, float32, 236 )
00048         GDF_DECLARE_RESERVED( reserved_2, 240, 16 )
00049 
00050 /*        GDF_BEGIN_HEADERMAP( )
00051             GDF_ASSIGN_HEADERARRAY( label )
00052             GDF_ASSIGN_HEADERARRAY( transducer_type )
00053             GDF_ASSIGN_HEADERARRAY( physical_dimension )
00054             GDF_ASSIGN_HEADERITEM( physical_dimension_code )
00055             GDF_ASSIGN_HEADERITEM( physmin )
00056             GDF_ASSIGN_HEADERITEM( physmax )
00057             GDF_ASSIGN_HEADERITEM( digmin )
00058             GDF_ASSIGN_HEADERITEM( digmax )
00059             GDF_ASSIGN_RESERVED( reserved_1 )
00060             GDF_ASSIGN_HEADERITEM( lowpass )
00061             GDF_ASSIGN_HEADERITEM( highpass )
00062             GDF_ASSIGN_HEADERITEM( notch )
00063             GDF_ASSIGN_HEADERITEM( samples_per_record )
00064             GDF_ASSIGN_HEADERITEM( datatype )
00065             GDF_ASSIGN_HEADERARRAY( sensor_pos )
00066             GDF_ASSIGN_HEADERITEM( sensor_info )
00067         GDF_END_HEADERMAP( )*/
00068 
00069     public:
00070 
00072         SignalHeader( );
00073 
00075         virtual ~SignalHeader( );
00076 
00078         void setString( std::string item, std::string value )
00079         {
00080             if( item == "label" ) set_label( value );
00081             else if( item == "transducer_type" ) set_transducer_type( value );
00082             else if( item == "physical_dimension" ) set_physical_dimension( value );
00083             else throw exception::general( "Bad assignment of a string to " + item );
00084         }
00085 
00087         std::string getString( std::string item )
00088         {
00089             if( item == "label" ) return get_label( );
00090             else if( item == "transducer_type" ) return get_transducer_type( );
00091             else if( item == "physical_dimension" ) return get_physical_dimension( );
00092             else throw exception::general( "Bad attempt to read "+item+" as string" );
00093         }
00094 
00096         template<typename T> void setNumeric( std::string item, T value )
00097         {
00098             using boost::numeric_cast;
00099             if( item == "physical_dimension_code" ) set_physical_dimension_code( numeric_cast<uint16>(value) );
00100             else if( item == "physmin" ) set_physmin( numeric_cast<float64>(value) );
00101             else if( item == "physmax" ) set_physmax( numeric_cast<float64>(value) );
00102             else if( item == "digmin" ) set_digmin( numeric_cast<float64>(value) );
00103             else if( item == "digmax" ) set_digmax( numeric_cast<float64>(value) );
00104             else if( item == "lowpass" ) set_lowpass( numeric_cast<float32>(value) );
00105             else if( item == "highpass" ) set_highpassh( numeric_cast<float32>(value) );
00106             else if( item == "notch" ) set_notch( numeric_cast<float32>(value) );
00107             else if( item == "datatype" ) set_datatype( numeric_cast<uint32>(value) );
00108             else if( item == "sensor_info" ) set_sensor_info( numeric_cast<float32>(value) );
00109             else throw exception::general( "Bad assignment to " + item );
00110         }
00111 
00113         template<typename T> T getNumeric( std::string item )
00114         {
00115             using boost::numeric_cast;
00116             if( item == "physical_dimension_code" ) return numeric_cast<T>(get_physical_dimension_code( ));
00117             else if( item == "physmin" ) return numeric_cast<T>(get_physmin( ));
00118             else if( item == "physmax" ) return numeric_cast<T>(get_physmax( ));
00119             else if( item == "digmin" ) return numeric_cast<T>(get_digmin( ));
00120             else if( item == "digmax" ) return numeric_cast<T>(get_digmax( ));
00121             else if( item == "lowpass" ) return numeric_cast<T>(get_lowpass( ));
00122             else if( item == "highpass" ) return numeric_cast<T>(get_highpass( ));
00123             else if( item == "notch" ) return numeric_cast<T>(get_notch( ));
00124             else if( item == "datatype" ) return numeric_cast<T>(get_datatype( ));
00125             else if( item == "sensor_info" ) return numeric_cast<T>(get_sensor_info( ));
00126             else throw exception::general( item + " is not known as a numeric item" );
00127         }
00128 
00130         template<typename T> void setArray( std::string item, size_t array_index, T value )
00131         {
00132             using boost::numeric_cast;
00133             if( item == "sensor_pos" ) sensor_pos[array_index] = numeric_cast<float32>(value);
00134             else throw exception::general( "Bad array access to " + item );
00135         }
00136 
00138         void setDefaultValues( );
00139 
00141         void copyFrom( const SignalHeader &other );
00142 
00144         double phys_to_raw( const double phy ) const;
00145 
00147         double raw_to_phys( const double raw ) const;
00148 
00149         void set_samplerate( uint32 fs ) { samplerate = fs; }
00150         uint32 get_samplerate( ) const { return samplerate; }
00151 
00152     private:
00153         uint32 samplerate;
00154 
00155         friend class GDFHeaderAccess;
00156         friend std::ostream& operator<< (std::ostream& out, const GDFHeaderAccess& hdr);
00157         friend std::istream& operator>> (std::istream& in, GDFHeaderAccess& hdr);
00158     };
00159 }
00160 
00161 #endif
 All Data Structures Functions Variables Friends