X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=datasnapshot.cpp;h=6933ea12b9440623884e8b9dc18edada1aac7d35;hp=1a6376882286760b36a9be7acb8827312ef74a3e;hb=8f94be14588c7a7ca0f483b649d7a7b5b5f45ae9;hpb=28a4c9c5eb20296199fc3496bb40b7733dffac75 diff --git a/datasnapshot.cpp b/datasnapshot.cpp index 1a637688..6933ea12 100644 --- a/datasnapshot.cpp +++ b/datasnapshot.cpp @@ -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 * @@ -20,12 +20,32 @@ #include "datasnapshot.h" -DataSnapshot::DataSnapshot() : - _sample_count(0) +#include +#include +#include + +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; +}