libGDF
Record.cpp
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 #include "GDF/Record.h"
00020 #include "GDF/GDFHeaderAccess.h"
00021 #include "GDF/SignalHeader.h"
00022 #include <limits>
00023 //#include <iostream>
00024 
00025 namespace gdf
00026 {
00027     Record::Record( const GDFHeaderAccess *hdr )
00028     {
00029         size_t M = hdr->getMainHeader_readonly( ).get_num_signals( );
00030         for( size_t i=0; i<M; i++ )
00031         {
00032             channels.push_back( new Channel( &hdr->getSignalHeader_readonly(i) ) );
00033         }
00034     }
00035 
00036     //===================================================================================================
00037     //===================================================================================================
00038 
00039     Record::Record( const Record &other )
00040     {
00041         size_t M = other.channels.size( );
00042         for( size_t i=0; i<M; i++ )
00043         {
00044             channels.push_back( new Channel( *other.channels[i] ) );
00045         }
00046     }
00047 
00048     //===================================================================================================
00049     //===================================================================================================
00050 
00051     Record::~Record( )
00052     {
00053         size_t M = channels.size();
00054         for( size_t i=0; i<M; i++ )
00055         {
00056             delete channels[i];
00057         }
00058     }
00059 
00060     //===================================================================================================
00061     //===================================================================================================
00062 
00063     void Record::clear( )
00064     {
00065         size_t M = channels.size();
00066         for( size_t i=0; i<M; i++ )
00067         {
00068             channels[i]->clear( );
00069         }
00070     }
00071 
00072     //===================================================================================================
00073     //===================================================================================================
00074 
00075     void Record::operator=( const Record &other )
00076     {
00077         size_t M = channels.size();
00078         for( size_t i=0; i<M; i++ )
00079         {
00080             delete channels[i];
00081         }
00082         channels.clear( );
00083 
00084         M = other.channels.size( );
00085         for( size_t i=0; i<M; i++ )
00086         {
00087             channels.push_back( new Channel( *other.channels[i] ) );
00088         }
00089     }
00090 
00091     //===================================================================================================
00092     //===================================================================================================
00093 
00094     void Record::fill( )
00095     {
00096         for( size_t i=0; i<channels.size(); i++ )
00097         {
00098             switch( channels[i]->getTypeID() )
00099             {
00100             default:
00101                 channels[i]->fillPhys( 0.0, channels[i]->getFree() ); break;
00102             case FLOAT32:
00103                 channels[i]->fillPhys( std::numeric_limits<float>::quiet_NaN(), channels[i]->getFree() ); break;
00104             case FLOAT64:
00105                 channels[i]->fillPhys( std::numeric_limits<double>::quiet_NaN(), channels[i]->getFree() ); break;
00106             }
00107         }
00108     }
00109 
00110     //===================================================================================================
00111     //===================================================================================================
00112 
00113     bool Record::isFull( ) const
00114     {
00115         for( size_t i=0; i<channels.size(); i++ )
00116         {
00117             if( channels[i]->getFree( ) > 0 )
00118                 return false;
00119         }
00120         return true;
00121     }
00122 
00123     //===================================================================================================
00124     //===================================================================================================
00125 
00126     bool Record::isEmpty( ) const
00127     {
00128         for( size_t i=0; i<channels.size(); i++ )
00129         {
00130             if( channels[i]->getWritten( ) > 0 )
00131                 return false;
00132         }
00133         return true;
00134     }
00135 
00136     //===================================================================================================
00137     //===================================================================================================
00138 
00139     Channel *Record::getChannel( const size_t chan_idx )
00140     {
00141         return channels[chan_idx];
00142     }
00143 
00144     //===================================================================================================
00145     //===================================================================================================
00146 
00147     std::ostream &operator<<( std::ostream &out, const Record &r )
00148     {
00149         size_t M = r.channels.size();
00150         for( size_t i=0; i<M; i++ )
00151         {
00152             out << *r.channels[i];
00153         }
00154         return out;
00155     }
00156 
00157     //===================================================================================================
00158     //===================================================================================================
00159 
00160     std::istream &operator>>( std::istream &in, Record &r )
00161     {
00162         size_t M = r.channels.size();
00163         for( size_t i=0; i<M; i++ )
00164             in >> *r.channels[i];
00165         return in;
00166     }
00167 }
 All Data Structures Functions Variables Friends