diff options
Diffstat (limited to 'modules/codec')
-rw-r--r-- | modules/codec/c++/data_raw.hpp | 12 | ||||
-rw-r--r-- | modules/codec/tests/data_raw.cpp | 22 |
2 files changed, 20 insertions, 14 deletions
diff --git a/modules/codec/c++/data_raw.hpp b/modules/codec/c++/data_raw.hpp index 92afc77..2236d05 100644 --- a/modules/codec/c++/data_raw.hpp +++ b/modules/codec/c++/data_raw.hpp @@ -140,7 +140,8 @@ public: SAW_FORBID_MOVE(data); constexpr void set(typename native_data_type<ReferencedSchema>::type val){ - value_() = val; + auto& v = value_(); + v = val; } constexpr typename native_data_type<ReferencedSchema>::type get() const { @@ -422,7 +423,6 @@ class data<schema::Array<T,Dim>, encode::NativeRaw> { s *= dims_[iter]; } - return s; } public: @@ -456,7 +456,7 @@ class data<schema::Array<T,Dim>, encode::NativeRaw> { // auto old_value = value_; // auto old_value_size = value_size_; value_size_ = get_full_size(); - value_ = new typename raw_native_array_type_helper<T>::Type (value_size_); + value_ = new typename raw_native_array_type_helper<T>::Type [value_size_]; } data(data<MetaSchema, encode::NativeRaw> init) @@ -465,12 +465,12 @@ class data<schema::Array<T,Dim>, encode::NativeRaw> { dims_[i] = init.at(i).get(); } value_size_ = get_full_size(); - value_ = new typename raw_native_array_type_helper<T>::Type (value_size_); + value_ = new typename raw_native_array_type_helper<T>::Type [value_size_]; } ~data(){ if(value_){ - delete value_; + delete[] value_; value_ = nullptr; value_size_ = 0u; } @@ -486,7 +486,7 @@ class data<schema::Array<T,Dim>, encode::NativeRaw> { template<std::integral... Dims> constexpr error_or<void> adopt(typename raw_native_array_type_helper<T>::Type* adoptee, Dims... adoptee_size){ if(value_ != nullptr){ - return make_error<err::invalid_state>("Can't adopt into existing state"); + return make_error<err::invalid_state>("Can't adopt into existing data"); } dims_ = {adoptee_size...}; value_size_ = get_full_size(); diff --git a/modules/codec/tests/data_raw.cpp b/modules/codec/tests/data_raw.cpp index 11e2c5e..26c2721 100644 --- a/modules/codec/tests/data_raw.cpp +++ b/modules/codec/tests/data_raw.cpp @@ -14,23 +14,29 @@ SAW_TEST("Data NativeRaw/Array of Primitives"){ using namespace saw; data<sch::Int32Array,encode::NativeRaw> prim{4u}; - prim.at(1u).set(0); + prim.at(0u).set(0); - auto a = prim.at(1u); + auto a = prim.at(0u); + auto b = prim.at(1u); + auto c = prim.at(2u); + auto d = prim.at(3u); a.set(5); + b.set(6); - auto b = prim.at(1u); // Check if it's a reference being manipulated SAW_EXPECT(a.get() == 5, "'a' has unexpected value."); - SAW_EXPECT(b.get() == 5, "'b' has unexpected value."); + SAW_EXPECT(b.get() == 6, "'b' has unexpected value."); - auto c = prim.at(1u); - c.set(10); + auto b1 = prim.at(1u); + b1.set(10); + c.set(-9); - SAW_EXPECT(a.get() == 10, "'a' has unexpected value."); + SAW_EXPECT(b1.get() == 10, "'b1' has unexpected value."); + SAW_EXPECT(a.get() == 5, "'a' has unexpected value."); SAW_EXPECT(b.get() == 10, "'b' has unexpected value."); - SAW_EXPECT(c.get() == 10, "'c' has unexpected value."); + SAW_EXPECT(c.get() == -9, "'c' has unexpected value."); + SAW_EXPECT(d.get() == 23, "'d' has unexpected value."); } } |