OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WEEG2Segment.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <cstddef>
26 
27 #include <sstream>
28 #include <string>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "../common/exceptions/WOutOfBounds.h"
33 #include "WEEG2Segment.h"
34 #include "WEEGValueMatrix.h"
35 #include "WRecording.h"
36 #include "exceptions/WDHException.h"
37 #include "io/WPagerEEG.h"
38 
39 WEEG2Segment::WEEG2Segment( std::size_t segmentID, boost::shared_ptr< WPagerEEG > pager )
40  : m_segmentID( segmentID ),
41  m_pager( pager )
42 {
43  if( !m_pager )
44  {
45  throw WDHException( std::string( "Couldn't construct new EEG segment: pager invalid" ) );
46  }
47 
48  if( m_segmentID >= m_pager->getNumberOfSegments() )
49  {
50  std::ostringstream stream;
51  stream << "The EEG has no segment number " << m_segmentID;
52  throw WOutOfBounds( stream.str() );
53  }
54 
55  m_nbSamples = m_pager->getNumberOfSamples( m_segmentID );
57  {
58  throw WDHException( std::string( "Couldn't construct new EEG segment: invalid number of samples" ) );
59  }
60 }
61 
63 {
64  return m_nbSamples;
65 }
66 
67 boost::shared_ptr< WEEGValueMatrix > WEEG2Segment::getValues( std::size_t start, std::size_t length ) const
68 {
69  // No test whether start and length are valid - this should be done only
70  // one time by the pager.
71  return m_pager->getValues( m_segmentID, start, length );
72 }