• Main Page
  • Packages
  • Classes
  • Files
  • File List
  • File Members

unlock/bci/acquire-c++/SampleBuffer.hpp

Go to the documentation of this file.
00001 
00002 // Copyright (c) James Percent and Unlock contributors.
00003 // All rights reserved.
00004 // Redistribution and use in source and binary forms, with or without modification,
00005 // are permitted provided that the following conditions are met:
00006 //
00007 //    1. Redistributions of source code must retain the above copyright notice,
00008 //       this list of conditions and the following disclaimer.
00009 //    
00010 //    2. Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //
00014 //    3. Neither the name of Unlock nor the names of its contributors may be used
00015 //       to endorse or promote products derived from this software without
00016 //       specific prior written permission.
00017 
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 
00029 #ifndef SAMPLE_BUFFER_HPP
00030 #define SAMPLE_BUFFER_HPP
00031 
00032 #include <boost/assert.hpp>
00033 #include "Portability.hpp"
00034 
00035 template<class T>
00036 class DllExport SampleBuffer
00037 {
00038  public:
00039   SampleBuffer() : mpBuffer(0), mPosition(0) {
00040     mpBuffer = new T[RING_SIZE];
00041   }
00042     
00043   SampleBuffer(const SampleBuffer& copy) :mpBuffer(copy.mpBuffer), mPosition(copy.mPosition) {
00044   }
00045     
00046   SampleBuffer& operator=(const SampleBuffer& other) {
00047     mpBuffer = other.mpBuffer;
00048     mPosition = other.mPosition;
00049   }
00050     
00051   ~SampleBuffer() {
00052     BOOST_VERIFY(mpBuffer != 0);
00053     delete[] mpBuffer;
00054   }
00055 
00056   size_t maximumReservation() {
00057     return RING_SIZE;
00058   }
00059     
00060   T* reserve(size_t samples) {
00061     BOOST_VERIFY(mpBuffer != 0);
00062         
00063     if (samples > maximumReservation()) {
00064       cerr << "SampleBuffer.reserve: ERROR: a reservation larger than the maximum reservation; returning 0 " << endl;
00065       return 0;
00066     }
00067         
00068     if ((mPosition + samples) >= maximumReservation()) {
00069       mPosition = 0;
00070     }
00071         
00072     T* ret = mpBuffer+mPosition;
00073     mPosition += samples;
00074     return ret;
00075   }
00076     
00077  private:
00078   static const size_t RING_SIZE=1048576;
00079   T* mpBuffer;
00080   size_t mPosition;
00081 };
00082 
00083 #endif

Generated on Mon Nov 10 2014 11:09:08 for The Unlock Project by  doxygen 1.7.1