|
libGDF
|
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 __MAINHEADER_H_INCLUDED__ 00020 #define __MAINHEADER_H_INCLUDED__ 00021 00022 #include "HeaderItem.h" 00023 #include <boost/smart_ptr/scoped_ptr.hpp> 00024 #include <boost/numeric/conversion/cast.hpp> 00025 00026 namespace gdf 00027 { 00028 class GDFHeaderAccess; 00029 00031 class MainHeader 00032 { 00033 GDF_DECLARE_HEADERSTRING( version_id, 0, 8 ) 00034 GDF_DECLARE_HEADERSTRING( patient_id, 8, 66 ) 00035 GDF_DECLARE_RESERVED( reserved_1, 74, 10 ) 00036 GDF_DECLARE_HEADERITEM( patient_drugs, uint8, 84 ) 00037 GDF_DECLARE_HEADERITEM( patient_weight, uint8, 85 ) 00038 GDF_DECLARE_HEADERITEM( patient_height, uint8, 86 ) 00039 GDF_DECLARE_HEADERITEM( patient_flags, uint8, 87 ) 00040 GDF_DECLARE_HEADERSTRING( recording_id, 88, 64 ) 00041 GDF_DECLARE_HEADERARRAY( recording_location, uint32, 152, 4 ) 00042 GDF_DECLARE_HEADERITEM( recording_start, uint64, 168 ) // defined as uint32[2] in the spec 00043 GDF_DECLARE_HEADERITEM( patient_birthday, uint64, 176 ) // defined as uint32[2] in the spec 00044 GDF_DECLARE_HEADERITEM( header_length, uint16, 184 ) 00045 GDF_DECLARE_HEADERSTRING( patient_ICD, 186, 6 ) // defined as byte[6] in the spec 00046 GDF_DECLARE_HEADERITEM( equipment_provider_classification, uint64, 192 ) 00047 GDF_DECLARE_RESERVED( reserved_2, 200, 6 ) 00048 GDF_DECLARE_HEADERARRAY( patient_headsize, uint16, 206, 3 ) 00049 GDF_DECLARE_HEADERARRAY( pos_reference, float32, 212, 3 ) 00050 GDF_DECLARE_HEADERARRAY( pos_ground, float32, 224, 3 ) 00051 GDF_DECLARE_HEADERITEM( num_datarecords, int64, 236 ) 00052 GDF_DECLARE_HEADERARRAY( datarecord_duration, uint32, 244, 2 ) 00053 GDF_DECLARE_HEADERITEM_PRIVATE( num_signals, uint16, 252 ) 00054 GDF_DECLARE_RESERVED( reserved_3, 254, 2 ) 00055 00056 /*GDF_BEGIN_HEADERMAP( ) 00057 GDF_ASSIGN_HEADERARRAY( version_id ) 00058 GDF_ASSIGN_HEADERARRAY( patient_id ) 00059 GDF_ASSIGN_RESERVED( reserved_1 ) 00060 GDF_ASSIGN_HEADERITEM( patient_drugs ) 00061 GDF_ASSIGN_HEADERITEM( patient_weight ) 00062 GDF_ASSIGN_HEADERITEM( patient_height ) 00063 GDF_ASSIGN_HEADERITEM( patient_flags ) 00064 GDF_ASSIGN_HEADERARRAY( recording_id ) 00065 GDF_ASSIGN_HEADERARRAY( recording_location ) 00066 GDF_ASSIGN_HEADERITEM( recording_start ) 00067 GDF_ASSIGN_HEADERITEM( patient_birthday ) 00068 GDF_ASSIGN_HEADERITEM( header_length ) 00069 GDF_ASSIGN_HEADERARRAY( patient_ICD ) 00070 GDF_ASSIGN_HEADERITEM( equipment_provider_classification ) 00071 GDF_ASSIGN_RESERVED( reserved_2 ) 00072 GDF_ASSIGN_HEADERARRAY( patient_headsize ) 00073 GDF_ASSIGN_HEADERARRAY( pos_reference ) 00074 GDF_ASSIGN_HEADERARRAY( pos_ground ) 00075 GDF_ASSIGN_HEADERITEM( num_datarecords ) 00076 GDF_ASSIGN_HEADERARRAY( datarecord_duration ) 00077 GDF_ASSIGN_HEADERITEM( num_signals ) 00078 GDF_ASSIGN_RESERVED( reserved_3 ) 00079 GDF_END_HEADERMAP( )*/ 00080 00081 public: 00082 00084 MainHeader( ); 00085 00087 void setDefaultValues( ); 00088 00090 void copyFrom( const MainHeader &other ); 00091 00093 void setString( std::string item, std::string value ) 00094 { 00095 if( item == "version_id" ) set_version_id( value ); 00096 else if( item == "patient_id" ) set_patient_id( value ); 00097 else if( item == "recording_id" ) set_recording_id( value ); 00098 else if( item == "patient_ICD" ) set_patient_ICD( value ); 00099 else throw exception::general( "Bad assignment of a string to " + item ); 00100 } 00101 00103 std::string getString( std::string item ) 00104 { 00105 if( item == "version_id" ) return get_version_id( ); 00106 else if( item == "patient_id" ) return get_patient_id( ); 00107 else if( item == "recording_id" ) return get_recording_id( ); 00108 else if( item == "patient_ICD" ) return get_patient_ICD( ); 00109 else throw exception::general( "Bad attempt to read "+item+" as string" ); 00110 } 00111 00113 template<typename T> void setNumeric( std::string item, T value ) 00114 { 00115 using boost::numeric_cast; 00116 if( item == "patient_drugs" ) set_patient_drugs( numeric_cast<uint8>(value) ); 00117 else if( item == "patient_weight" ) set_patient_weight( numeric_cast<uint8>(value) ); 00118 else if( item == "patient_height" ) set_patient_height( numeric_cast<uint8>(value) ); 00119 else if( item == "patient_flags" ) set_patient_flags( numeric_cast<uint8>(value) ); 00120 else if( item == "recording_start" ) set_recording_start( numeric_cast<uint64>(value) ); 00121 else if( item == "patient_birthday" ) set_patient_birthday( numeric_cast<uint64>(value) ); 00122 else if( item == "header_length" ) set_header_length( numeric_cast<uint16>(value) ); 00123 else if( item == "equipment_provider_classification" ) set_equipment_provider_classification( numeric_cast<uint64>(value) ); 00124 else if( item == "num_datarecords" ) set_num_datarecords( numeric_cast<int64>(value) ); 00125 else throw exception::general( "Bad assignment to " + item ); 00126 } 00127 00129 template<typename T> T getNumeric( std::string item, T ) 00130 { 00131 using boost::numeric_cast; 00132 if( item == "patient_drugs" ) return numeric_cast<T>(get_patient_drugs( )); 00133 else if( item == "patient_weight" ) return numeric_cast<T>(get_patient_weight( )); 00134 else if( item == "patient_height" ) return numeric_cast<T>(get_patient_height( )); 00135 else if( item == "patient_flags" ) return numeric_cast<T>(get_patient_flags( )); 00136 else if( item == "recording_start" ) return numeric_cast<T>(get_recording_start( )); 00137 else if( item == "patient_birthday" ) return numeric_cast<T>(get_patient_birthday( )); 00138 else if( item == "header_length" ) return numeric_cast<T>(get_header_length( )); 00139 else if( item == "equipment_provider_classification" ) return numeric_cast<T>(get_equipment_provider_classification( )); 00140 else if( item == "num_datarecords" ) return numeric_cast<T>(get_num_datarecords( )); 00141 else throw exception::general( item + " is not known as a numeric item" ); 00142 } 00143 00145 template<typename T> void setArray( std::string item, size_t array_index, T value ) 00146 { 00147 using boost::numeric_cast; 00148 if( item == "recording_location" ) recording_location[array_index] = numeric_cast<uint32>(value); 00149 else if( item == "patient_headsize" ) patient_headsize[array_index] = numeric_cast<uint16>(value); 00150 else if( item == "pos_reference" ) pos_reference[array_index] = numeric_cast<float32>(value); 00151 else if( item == "pos_ground" ) pos_ground[array_index] = numeric_cast<float32>(value); 00152 else if( item == "datarecord_duration" ) datarecord_duration[array_index] = numeric_cast<uint32>(value); 00153 else throw exception::general( "Bad array access to " + item ); 00154 } 00155 00157 template<typename T> T getArray( std::string item, size_t array_index, T ) 00158 { 00159 using boost::numeric_cast; 00160 if( item == "recording_location" ) return numeric_cast<T>(recording_location[array_index]); 00161 else if( item == "patient_headsize" ) return numeric_cast<T>(patient_headsize[array_index]); 00162 else if( item == "pos_reference" ) return numeric_cast<T>(pos_reference[array_index]); 00163 else if( item == "pos_ground" ) return numeric_cast<T>(pos_ground[array_index]); 00164 else if( item == "datarecord_duration" ) return numeric_cast<T>(datarecord_duration[array_index]); 00165 else throw exception::general( "Bad array access to " + item ); 00166 } 00167 00168 friend class GDFHeaderAccess; 00169 friend class Writer; 00170 friend class Reader; 00171 friend std::ostream& operator<< (std::ostream& out, const GDFHeaderAccess& hdr); 00172 friend std::istream& operator>> (std::istream& in, GDFHeaderAccess& hdr); 00173 }; 00174 } 00175 00176 #endif