diff --git a/src/data.cpp b/src/data.cpp index a7a7cc4..187c6fd 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -256,7 +256,7 @@ void Value::copyIn(const void *ptr, StoreType type) } else if(src.original_type()==ArrayType::Value && desc->code.kind()==Kind::Compound) { // assign array of Struct/Union/Any - auto tsrc = shared_array_static_cast(src); + auto tsrc = src.castTo(); if(desc->code!=TypeCode::AnyA) { // enforce member type for Struct[] and Union[] @@ -384,7 +384,7 @@ void Value::traverse(const std::string &expr, bool modify) auto& varr = store->as>(); shared_array arr; if((varr.original_type()==ArrayType::Value) - && index < (arr = shared_array_static_cast(varr)).size()) + && index < (arr = varr.castTo()).size()) { *this = arr[index]; pos = sep+1; @@ -480,7 +480,7 @@ void show_Value(std::ostream& strm, if(varr.original_type()!=ArrayType::Value) { strm<<" = "<(varr); + auto arr = varr.castTo(); strm<<" [\n"; for(auto& val : arr) { show_Value(strm, std::string(), val._desc(), val._store(), level+1); diff --git a/src/dataencode.cpp b/src/dataencode.cpp index 642ddcb..962be5f 100644 --- a/src/dataencode.cpp +++ b/src/dataencode.cpp @@ -209,7 +209,7 @@ namespace { template void to_wire(Buffer& buf, const shared_array& varr) { - auto arr = shared_array_static_cast(varr); + auto arr = varr.castTo(); to_wire(buf, Size{arr.size()}); for(auto i : range(arr.size())) { to_wire(buf, C(arr[i])); @@ -354,7 +354,7 @@ void to_wire_field(Buffer& buf, const FieldDesc* desc, const FieldStorage* store to_wire(buf, fld); return; case TypeCode::StructA:{ - auto arr = shared_array_static_cast(fld); + auto arr = fld.castTo(); to_wire(buf, Size{arr.size()}); for(auto& elem : arr) { if(!elem) { @@ -368,7 +368,7 @@ void to_wire_field(Buffer& buf, const FieldDesc* desc, const FieldStorage* store } return; case TypeCode::UnionA: { - auto arr = shared_array_static_cast(fld); + auto arr = fld.castTo(); to_wire(buf, Size{arr.size()}); for(auto& elem : arr) { if(!elem) { @@ -382,7 +382,7 @@ void to_wire_field(Buffer& buf, const FieldDesc* desc, const FieldStorage* store } return; case TypeCode::AnyA:{ - auto arr = shared_array_static_cast(fld); + auto arr = fld.castTo(); to_wire(buf, Size{arr.size()}); for(auto& elem : arr) { if(!elem) { @@ -588,7 +588,7 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, Field } } - fld = shared_array_static_cast(freeze(std::move(arr))); + fld = arr.freeze().castTo(); } return; case TypeCode::UnionA: { @@ -621,7 +621,7 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, Field } } - fld = shared_array_static_cast(freeze(std::move(arr))); + fld = arr.freeze().castTo(); } return; case TypeCode::AnyA:{ @@ -644,7 +644,7 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, Field } } - fld = shared_array_static_cast(freeze(std::move(arr))); + fld = arr.freeze().castTo(); } return; default: break; diff --git a/src/util.cpp b/src/util.cpp index 60d2272..544274f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -67,7 +67,7 @@ std::ostream& operator<<(std::ostream& strm, const shared_array& arr { switch(arr.original_type()) { case ArrayType::Null: strm<<"[null]"; break; -#define CASE(CODE, Type) case ArrayType::CODE: strm<(arr); break +#define CASE(CODE, Type) case ArrayType::CODE: strm<(); break CASE(Bool, bool); CASE(UInt8, uint8_t); CASE(UInt16, uint16_t); @@ -90,7 +90,7 @@ std::ostream& operator<<(std::ostream& strm, const shared_array& arr) { switch(arr.original_type()) { case ArrayType::Null: strm<<"[null]"; break; -#define CASE(CODE, Type) case ArrayType::CODE: strm<(arr); break +#define CASE(CODE, Type) case ArrayType::CODE: strm<(); break CASE(Bool, bool); CASE(UInt8, uint8_t); CASE(UInt16, uint16_t); diff --git a/test/testdata.cpp b/test/testdata.cpp index c36824b..b24864d 100644 --- a/test/testdata.cpp +++ b/test/testdata.cpp @@ -114,7 +114,7 @@ void testSerialize2() arr[0]["value"] = 0xdeadbeef; arr[1]["value"] = 0x1badface; - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testToBytes(true, [&val](Buffer& buf) { to_wire_valid(buf, val); @@ -143,7 +143,7 @@ void testSerialize2() arr[0]["->x"] = "theX"; arr[1]["->y"] = "theY"; - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testToBytes(true, [&val](Buffer& buf) { to_wire_valid(buf, val); @@ -187,7 +187,7 @@ void testSerialize2() arr[0] = 0x7b; arr[1]["q"] = "theq"; - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testToBytes(true, [&val](Buffer& buf) { to_wire_valid(buf, val); diff --git a/test/testtype.cpp b/test/testtype.cpp index 636d120..0d41626 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -190,7 +190,7 @@ void testTypeDef() { shared_array arr({1.0, 2.0}); - val["value"].from(shared_array_static_cast(freeze(std::move(arr)))); + val["value"] = arr.freeze().castTo(); } // Struct[] { @@ -202,10 +202,7 @@ void testTypeDef() arr[0]["value"] = 1.0; arr[1]["value"] = 2.0; -// auto frozen = freeze(std::move(arr)); -// auto varr = shared_array_static_cast(frozen); -// fld.from(varr); - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testEq(val["arbitrary.sarr[1]value"].as(), 2.0); } @@ -222,7 +219,7 @@ void testTypeDef() arr[0]["->x"] = 4.0; arr[1]["->y"] = 5.0; - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testEq(fld["[1]"].as(), 5.0); testEq(val["achoice[1]"].as(), 5.0); @@ -250,7 +247,7 @@ void testTypeDef() arr[0] = 123; arr[1]["q"] = "theq"; - fld.from(shared_array_static_cast(freeze(std::move(arr)))); + fld = arr.freeze().castTo(); testEq(fld["[0]"].as(), 123u); testEq(fld["[1]q"].as(), "theq");