From bfdefc641a20b9b23f8064570e22dfe1d3bc9445 Mon Sep 17 00:00:00 2001 From: Randy Jones Date: Wed, 10 Jul 2024 15:21:05 -0700 Subject: [PATCH] breaking change: renamed getBlobValue() to getBlobData(). getBlobValue() now does actual value semantics. --- Tests/treeTest.cpp | 5 +---- source/app/MLValue.cpp | 6 ++++++ source/app/MLValue.h | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Tests/treeTest.cpp b/Tests/treeTest.cpp index 015f3d51..aeb71465 100644 --- a/Tests/treeTest.cpp +++ b/Tests/treeTest.cpp @@ -449,10 +449,7 @@ TEST_CASE("madronalib/core/serialization", "[serialization]") v["a"] = 0.4f; v["b"] = "hello"; v["a/b/c"] = "hello again"; - - std::array testArray{1, 3, 5, 7, 9}; - auto testBytes = testArray.size() * sizeof(uint8_t); - v["blobtest"] = Value(testArray.data(), testBytes); + v["blobtest"] = std::vector {1, 3, 5, 7, 9}; Tree< Value > v2 = JSONToValueTree(valueTreeToJSON(v)); diff --git a/source/app/MLValue.cpp b/source/app/MLValue.cpp index a3593858..72cb5c59 100644 --- a/source/app/MLValue.cpp +++ b/source/app/MLValue.cpp @@ -132,6 +132,12 @@ Value::Value(const void* pData, size_t n) : mType(kBlobValue) copyBlob(pData, n); } +Value::Value(const std::vector& dataVec) : mType(kBlobValue) +{ + copyBlob(dataVec.data(), dataVec.size()); +} + + Value::~Value() { // if we have external data, free it diff --git a/source/app/MLValue.h b/source/app/MLValue.h index ec062a73..71b218a1 100644 --- a/source/app/MLValue.h +++ b/source/app/MLValue.h @@ -62,6 +62,7 @@ class Value // Blob constructors. // if data size > kBlobSizeBytes, blob values will allocate heap. explicit Value(const void* pData, size_t n); + Value(const std::vector& dataVec); // TODO make array-like ctor using gsl::span // matrix type constructor via initializer_list @@ -165,6 +166,18 @@ class Value return 0; } } + + inline std::vector getBlobValue() const + { + if (mType == kBlobValue) + { + return std::vector(pBlobData, pBlobData + _blobSizeInBytes); + } + else + { + return std::vector(); + } + } // For each type of property, a setValue method must exist // to set the value of the property to that of the argument.