Skip to content

Commit

Permalink
breaking change: renamed getBlobValue() to getBlobData(). getBlobValu…
Browse files Browse the repository at this point in the history
…e() now does actual value semantics.
  • Loading branch information
madronalabs committed Jul 10, 2024
1 parent bcb7ee0 commit bfdefc6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 1 addition & 4 deletions Tests/treeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 5> testArray{1, 3, 5, 7, 9};
auto testBytes = testArray.size() * sizeof(uint8_t);
v["blobtest"] = Value(testArray.data(), testBytes);
v["blobtest"] = std::vector<uint8_t> {1, 3, 5, 7, 9};

Tree< Value > v2 = JSONToValueTree(valueTreeToJSON(v));

Expand Down
6 changes: 6 additions & 0 deletions source/app/MLValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ Value::Value(const void* pData, size_t n) : mType(kBlobValue)
copyBlob(pData, n);
}

Value::Value(const std::vector<uint8_t>& dataVec) : mType(kBlobValue)
{
copyBlob(dataVec.data(), dataVec.size());
}


Value::~Value()
{
// if we have external data, free it
Expand Down
13 changes: 13 additions & 0 deletions source/app/MLValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>& dataVec);
// TODO make array-like ctor using gsl::span

// matrix type constructor via initializer_list
Expand Down Expand Up @@ -165,6 +166,18 @@ class Value
return 0;
}
}

inline std::vector<uint8_t> getBlobValue() const
{
if (mType == kBlobValue)
{
return std::vector<uint8_t>(pBlobData, pBlobData + _blobSizeInBytes);
}
else
{
return std::vector<uint8_t>();
}
}

// For each type of property, a setValue method must exist
// to set the value of the property to that of the argument.
Expand Down

0 comments on commit bfdefc6

Please sign in to comment.