#include <math.h>
#include <string.h>
#include "OneSample.h"
#include "RawIR.h"

OneSample::OneSample(const std::vector<unsigned short> & init_data)
 : sample_ok(true), total_time(0), log_total_time(0.0) {
   len = init_data.size();
   data = new unsigned short [len];
   for (unsigned int i = 0; i < len; ++i) {
      unsigned short one_data = init_data[i];
      data[i] = one_data;
      unsigned long time_inc = (unsigned long)(BGIR_DURATION(one_data));
      total_time += time_inc;
      log_total_time += log((double)time_inc);
   }
}

OneSample::OneSample(const OneSample & cpy) {
   len = cpy.len;
   data = new unsigned short [len];
   memcpy((void *)data, (void *)cpy.data, len * sizeof(unsigned short));
   sample_ok = cpy.sample_ok;
   reason = cpy.reason;
   total_time = cpy.total_time;
   log_total_time = cpy.log_total_time;
}

OneSample::~OneSample() {
   delete [] data;
}

unsigned int
OneSample::Length() const {
   return len;
}

unsigned short
OneSample::operator[](unsigned int ndx) const {
   if (ndx < len) {
      return data[ndx];
   } else {
      return 0;
   }
}
