]> sigrok.org Git - pulseview.git/blobdiff - datasnapshot.cpp
Add initial NSIS file for building a win installer.
[pulseview.git] / datasnapshot.cpp
index 1a6376882286760b36a9be7acb8827312ef74a3e..6933ea12b9440623884e8b9dc18edada1aac7d35 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the PulseView project.
  *
  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
  *
 
 #include "datasnapshot.h"
 
-DataSnapshot::DataSnapshot() :
-       _sample_count(0)
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+DataSnapshot::DataSnapshot(int unit_size) :
+       _data(NULL),
+       _sample_count(0),
+       _unit_size(unit_size)
+{
+       assert(_unit_size > 0);
+}
+
+DataSnapshot::~DataSnapshot()
 {
+       free(_data);
 }
 
 uint64_t DataSnapshot::get_sample_count()
 {
        return _sample_count;
 }
+
+void DataSnapshot::append_data(void *data, uint64_t samples)
+{
+       _data = realloc(_data, (_sample_count + samples) * _unit_size);
+       memcpy((uint8_t*)_data + _sample_count * _unit_size,
+               data, samples * _unit_size);
+       _sample_count += samples;
+}