diff --git a/crates/re_types_builder/src/codegen/cpp/mod.rs b/crates/re_types_builder/src/codegen/cpp/mod.rs index 67abbe3c0b78..56a4f2f89dab 100644 --- a/crates/re_types_builder/src/codegen/cpp/mod.rs +++ b/crates/re_types_builder/src/codegen/cpp/mod.rs @@ -416,7 +416,7 @@ impl QuotedObject { let method_ident = format_ident!("with_{}", obj_field.name); let field_type = quote_archetype_field_type(&mut hpp_includes, obj_field); - hpp_includes.insert_rerun("warning_macros.hpp"); + hpp_includes.insert_rerun("compiler_utils.hpp"); let gcc_ignore_comment = quote_comment("See: https://github.com/rerun-io/rerun/issues/4027"); @@ -433,7 +433,7 @@ impl QuotedObject { #field_ident = std::move(#parameter_ident); #NEWLINE_TOKEN #gcc_ignore_comment - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) }, inline: true, }); @@ -1343,41 +1343,60 @@ fn component_to_data_cell_method(type_ident: &Ident, hpp_includes: &mut Includes fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Includes) -> Method { hpp_includes.insert_rerun("data_cell.hpp"); hpp_includes.insert_rerun("collection.hpp"); + hpp_includes.insert_rerun("serialized_component_batch.hpp"); hpp_includes.insert_system("vector"); // std::vector let num_fields = quote_integer(obj.fields.len()); let push_batches = obj.fields.iter().map(|field| { let field_name = format_ident!("{}", field.name); let field_accessor = quote!(archetype.#field_name); + let field_type = quote_fqname_as_type_path( + hpp_includes, + field + .typ + .fqname() + .expect("Archetypes only have components and vectors of components."), + ); - // TODO(andreas): Introducing MonoCollection will remove the need for this. - let wrapping_type = if field.typ.is_plural() { - quote!() - } else { - let field_type = quote_fqname_as_type_path( - hpp_includes, - field - .typ - .fqname() - .expect("Archetypes only have components and vectors of components."), - ); - quote!(Collection<#field_type>) + let emplace_back = quote! { + RR_RETURN_NOT_OK(result.error); + cells.emplace_back(std::move(result.value), size); }; - if field.is_nullable { + + // TODO(andreas): Introducing MonoCollection will remove the need for distinguishing these two cases. + if field.typ.is_plural() { + if field.is_nullable { + quote! { + if (#field_accessor.has_value()) { + const size_t size = #field_accessor.value().size(); + auto result = #field_type::to_data_cell(#field_accessor.value().data(), size); + #emplace_back + } + } + } else { + quote! { + { + const size_t size = #field_accessor.size(); + auto result = #field_type::to_data_cell(#field_accessor.data(), #field_accessor.size()); + #emplace_back + } + } + } + } else if field.is_nullable { quote! { if (#field_accessor.has_value()) { - auto result = #wrapping_type(#field_accessor.value()).serialize(); - RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + const size_t size = 1; + auto result = #field_type::to_data_cell(&#field_accessor.value(), size); + #emplace_back } } } else { quote! { { - auto result = #wrapping_type(#field_accessor).serialize(); - RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + const size_t size = 1; + auto result = #field_type::to_data_cell(&#field_accessor, size); + #emplace_back } } } @@ -1399,9 +1418,10 @@ fn archetype_serialize(type_ident: &Ident, obj: &Object, hpp_includes: &mut Incl #NEWLINE_TOKEN #(#push_batches)* { - auto result = Collection<#type_ident::IndicatorComponent>(#type_ident::IndicatorComponent()).serialize(); + auto indicator = #type_ident::IndicatorComponent(); + auto result = #type_ident::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } #NEWLINE_TOKEN #NEWLINE_TOKEN @@ -1983,8 +2003,8 @@ fn quote_field_type(includes: &mut Includes, obj_field: &ObjectField) -> TokenSt } Type::Vector { elem_type } => { let elem_type = quote_element_type(includes, elem_type); - includes.insert_system("vector"); - quote! { std::vector<#elem_type> } + includes.insert_rerun("collection.hpp"); + quote! { rerun::Collection<#elem_type> } } Type::Object(fqname) => { let type_name = quote_fqname_as_type_path(includes, fqname); diff --git a/docs/code-examples/line_strip2d_batch.cpp b/docs/code-examples/line_strip2d_batch.cpp index f0db55145764..45531e0ecb24 100644 --- a/docs/code-examples/line_strip2d_batch.cpp +++ b/docs/code-examples/line_strip2d_batch.cpp @@ -8,8 +8,8 @@ int main() { const auto rec = rerun::RecordingStream("rerun_example_line_strip2d"); rec.spawn().exit_on_failure(); - std::vector strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; - std::vector strip2 = + rerun::Collection strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; + rerun::Collection strip2 = {{0.f, 3.f}, {1.f, 4.f}, {2.f, 2.f}, {3.f, 4.f}, {4.f, 2.f}, {5.f, 4.f}, {6.f, 3.f}}; rec.log( "strips", diff --git a/docs/code-examples/line_strip3d_batch.cpp b/docs/code-examples/line_strip3d_batch.cpp index 52c240055934..5bfd40b757f7 100644 --- a/docs/code-examples/line_strip3d_batch.cpp +++ b/docs/code-examples/line_strip3d_batch.cpp @@ -8,13 +8,13 @@ int main() { const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); rec.spawn().exit_on_failure(); - std::vector strip1 = { + rerun::Collection strip1 = { {0.f, 0.f, 2.f}, {1.f, 0.f, 2.f}, {1.f, 1.f, 2.f}, {0.f, 1.f, 2.f}, }; - std::vector strip2 = { + rerun::Collection strip2 = { {0.f, 0.f, 0.f}, {0.f, 0.f, 1.f}, {1.f, 0.f, 0.f}, diff --git a/rerun_cpp/docs/writing_docs.md b/rerun_cpp/docs/writing_docs.md index 525b394d7023..1ee5abc607d9 100644 --- a/rerun_cpp/docs/writing_docs.md +++ b/rerun_cpp/docs/writing_docs.md @@ -34,3 +34,5 @@ We stick to the following styles: /// \endcond ``` * Avoid the use of groups when namespaces can be used instead +* Don't omit namespaces when referring to types in docs - instead of `Collection` use `rerun::Collection`. + Both works usually but the latter makes it easier to understand what is meant. diff --git a/rerun_cpp/src/rerun/archetypes/annotation_context.cpp b/rerun_cpp/src/rerun/archetypes/annotation_context.cpp index ba550ea4cf59..e32be6825978 100644 --- a/rerun_cpp/src/rerun/archetypes/annotation_context.cpp +++ b/rerun_cpp/src/rerun/archetypes/annotation_context.cpp @@ -19,18 +19,17 @@ namespace rerun { cells.reserve(1); { + const size_t size = 1; auto result = - Collection(archetype.context).serialize(); + rerun::components::AnnotationContext::to_data_cell(&archetype.context, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection( - AnnotationContext::IndicatorComponent() - ) - .serialize(); + auto indicator = AnnotationContext::IndicatorComponent(); + auto result = AnnotationContext::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp index 824300fa8a4b..75a8c677082c 100644 --- a/rerun_cpp/src/rerun/archetypes/annotation_context.hpp +++ b/rerun_cpp/src/rerun/archetypes/annotation_context.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include diff --git a/rerun_cpp/src/rerun/archetypes/arrows3d.cpp b/rerun_cpp/src/rerun/archetypes/arrows3d.cpp index 3c713e3db472..6bd9617114d1 100644 --- a/rerun_cpp/src/rerun/archetypes/arrows3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/arrows3d.cpp @@ -19,45 +19,63 @@ namespace rerun { cells.reserve(7); { - auto result = (archetype.vectors).serialize(); + const size_t size = archetype.vectors.size(); + auto result = rerun::components::Vector3D::to_data_cell( + archetype.vectors.data(), + archetype.vectors.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.origins.has_value()) { - auto result = (archetype.origins.value()).serialize(); + const size_t size = archetype.origins.value().size(); + auto result = + rerun::components::Position3D::to_data_cell(archetype.origins.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection(Arrows3D::IndicatorComponent()) - .serialize(); + auto indicator = Arrows3D::IndicatorComponent(); + auto result = Arrows3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/arrows3d.hpp b/rerun_cpp/src/rerun/archetypes/arrows3d.hpp index 45af4e199c96..01ae04cde8f7 100644 --- a/rerun_cpp/src/rerun/archetypes/arrows3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/arrows3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/instance_key.hpp" @@ -14,7 +15,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -117,7 +118,7 @@ namespace rerun::archetypes { Arrows3D with_origins(Collection _origins) && { origins = std::move(_origins); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional radii for the arrows. @@ -127,21 +128,21 @@ namespace rerun::archetypes { Arrows3D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the points. Arrows3D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the arrows. Arrows3D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional class Ids for the points. @@ -150,14 +151,14 @@ namespace rerun::archetypes { Arrows3D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual point in the batch. Arrows3D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/asset3d.cpp b/rerun_cpp/src/rerun/archetypes/asset3d.cpp index e9da562ede74..6003e162da37 100644 --- a/rerun_cpp/src/rerun/archetypes/asset3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/asset3d.cpp @@ -19,28 +19,32 @@ namespace rerun { cells.reserve(3); { - auto result = Collection(archetype.blob).serialize(); + const size_t size = 1; + auto result = rerun::components::Blob::to_data_cell(&archetype.blob, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.media_type.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.media_type.value()).serialize(); + rerun::components::MediaType::to_data_cell(&archetype.media_type.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.transform.has_value()) { - auto result = - Collection(archetype.transform.value()) - .serialize(); + const size_t size = 1; + auto result = rerun::components::OutOfTreeTransform3D::to_data_cell( + &archetype.transform.value(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Asset3D::IndicatorComponent()).serialize(); + auto indicator = Asset3D::IndicatorComponent(); + auto result = Asset3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/asset3d.hpp b/rerun_cpp/src/rerun/archetypes/asset3d.hpp index 9ec6f2de0c68..3a565a74bcbc 100644 --- a/rerun_cpp/src/rerun/archetypes/asset3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/asset3d.hpp @@ -4,13 +4,14 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/blob.hpp" #include "../components/media_type.hpp" #include "../components/out_of_tree_transform3d.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -92,10 +93,10 @@ namespace rerun::archetypes { /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data /// at render-time. If it can't, rendering will fail with an error. static Asset3D from_bytes( - const std::vector bytes, std::optional media_type + rerun::Collection bytes, std::optional media_type ) { // TODO(cmc): we could try and guess using magic bytes here, like rust does. - Asset3D asset = Asset3D(bytes); + Asset3D asset = Asset3D(std::move(bytes)); asset.media_type = media_type; return asset; } @@ -117,7 +118,7 @@ namespace rerun::archetypes { Asset3D with_media_type(rerun::components::MediaType _media_type) && { media_type = std::move(_media_type); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An out-of-tree transform. @@ -126,7 +127,7 @@ namespace rerun::archetypes { Asset3D with_transform(rerun::components::OutOfTreeTransform3D _transform) && { transform = std::move(_transform); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/asset3d_ext.cpp b/rerun_cpp/src/rerun/archetypes/asset3d_ext.cpp index 1be25c600334..d74f5eefeb9e 100644 --- a/rerun_cpp/src/rerun/archetypes/asset3d_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/asset3d_ext.cpp @@ -12,8 +12,7 @@ // -namespace rerun { - namespace archetypes { +namespace rerun::archetypes { #if 0 // @@ -35,10 +34,10 @@ namespace rerun { /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data /// at render-time. If it can't, rendering will fail with an error. static Asset3D from_bytes( - const std::vector bytes, std::optional media_type + rerun::Collection bytes, std::optional media_type ) { // TODO(cmc): we could try and guess using magic bytes here, like rust does. - Asset3D asset = Asset3D(bytes); + Asset3D asset = Asset3D(std::move(bytes)); asset.media_type = media_type; return asset; } @@ -46,39 +45,40 @@ namespace rerun { // #endif - Result Asset3D::from_file(const std::filesystem::path& path) { - std::ifstream file(path, std::ios::binary); - if (!file) { - return Error(ErrorCode::FileOpenFailure, "Failed to open file: " + path.string()); - } - - file.seekg(0, std::ios::end); - std::streampos length = file.tellg(); - file.seekg(0, std::ios::beg); + Result Asset3D::from_file(const std::filesystem::path& path) { + std::ifstream file(path, std::ios::binary); + if (!file) { + return Error(ErrorCode::FileOpenFailure, "Failed to open file: " + path.string()); + } - std::vector data(static_cast(length)); - file.read(reinterpret_cast(data.data()), length); + file.seekg(0, std::ios::end); + std::streampos length = file.tellg(); + file.seekg(0, std::ios::beg); - return Asset3D::from_bytes(data, Asset3D::guess_media_type(path)); - } + std::vector data(static_cast(length)); + file.read(reinterpret_cast(data.data()), length); - std::optional Asset3D::guess_media_type( - const std::filesystem::path& path - ) { - std::filesystem::path file_path(path); - std::string ext = file_path.extension().string(); - std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - - if (ext == ".glb") { - return rerun::components::MediaType::glb(); - } else if (ext == ".gltf") { - return rerun::components::MediaType::gltf(); - } else if (ext == ".obj") { - return rerun::components::MediaType::obj(); - } else { - return std::nullopt; - } + return Asset3D::from_bytes( + Collection::take_ownership(std::move(data)), + Asset3D::guess_media_type(path) + ); + } + + std::optional Asset3D::guess_media_type( + const std::filesystem::path& path + ) { + std::filesystem::path file_path(path); + std::string ext = file_path.extension().string(); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + if (ext == ".glb") { + return rerun::components::MediaType::glb(); + } else if (ext == ".gltf") { + return rerun::components::MediaType::gltf(); + } else if (ext == ".obj") { + return rerun::components::MediaType::obj(); + } else { + return std::nullopt; } - - } // namespace archetypes -} // namespace rerun + } +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/bar_chart.cpp b/rerun_cpp/src/rerun/archetypes/bar_chart.cpp index e4f9f8df7c2f..5a3120e0b3dd 100644 --- a/rerun_cpp/src/rerun/archetypes/bar_chart.cpp +++ b/rerun_cpp/src/rerun/archetypes/bar_chart.cpp @@ -19,15 +19,16 @@ namespace rerun { cells.reserve(1); { - auto result = Collection(archetype.values).serialize(); + const size_t size = 1; + auto result = rerun::components::TensorData::to_data_cell(&archetype.values, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection(BarChart::IndicatorComponent()) - .serialize(); + auto indicator = BarChart::IndicatorComponent(); + auto result = BarChart::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/bar_chart.hpp b/rerun_cpp/src/rerun/archetypes/bar_chart.hpp index dd8b33270b1c..856127436229 100644 --- a/rerun_cpp/src/rerun/archetypes/bar_chart.hpp +++ b/rerun_cpp/src/rerun/archetypes/bar_chart.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -52,109 +53,107 @@ namespace rerun::archetypes { // -------------------------------------------------------------------- // Implicit constructors: - // TODO(#3794): don't use std::vector here - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u8) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u8) : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u16) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u16) : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u32) : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u64) : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i8) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i8) : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i16) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i16) : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i32) : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i64) : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {} - /// Construct aBarChart` from a `std::vector`. - BarChart(std::vector f16) + /// Construct aBarChart` from a `Collection`. + BarChart(Collection f16) : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection f32) : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection f64) : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {} // -------------------------------------------------------------------- // Explicit static constructors: - // TODO(#3794): don't use std::vector here - /// Construct a `BarChart` from a `std::vector`. - static BarChart u8(std::vector u8) { - return BarChart(u8); + /// Construct a `BarChart` from a `Collection`. + static BarChart u8(Collection u8) { + return BarChart(std::move(u8)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u16(std::vector u16) { - return BarChart(u16); + /// Construct a `BarChart` from a `Collection`. + static BarChart u16(Collection u16) { + return BarChart(std::move(u16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u32(std::vector u32) { - return BarChart(u32); + /// Construct a `BarChart` from a `Collection`. + static BarChart u32(Collection u32) { + return BarChart(std::move(u32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u64(std::vector u64) { - return BarChart(u64); + /// Construct a `BarChart` from a `Collection`. + static BarChart u64(Collection u64) { + return BarChart(std::move(u64)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i8(std::vector i8) { - return BarChart(i8); + /// Construct a `BarChart` from a `Collection`. + static BarChart i8(Collection i8) { + return BarChart(std::move(i8)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i16(std::vector i16) { - return BarChart(i16); + /// Construct a `BarChart` from a `Collection`. + static BarChart i16(Collection i16) { + return BarChart(std::move(i16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i32(std::vector i32) { - return BarChart(i32); + /// Construct a `BarChart` from a `Collection`. + static BarChart i32(Collection i32) { + return BarChart(std::move(i32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i64(std::vector i64) { - return BarChart(i64); + /// Construct a `BarChart` from a `Collection`. + static BarChart i64(Collection i64) { + return BarChart(std::move(i64)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f16(std::vector f16) { - return BarChart(f16); + /// Construct a `BarChart` from a `Collection`. + static BarChart f16(Collection f16) { + return BarChart(std::move(f16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f32(std::vector f32) { - return BarChart(f32); + /// Construct a `BarChart` from a `Collection`. + static BarChart f32(Collection f32) { + return BarChart(std::move(f32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f64(std::vector f64) { - return BarChart(f64); + /// Construct a `BarChart` from a `Collection`. + static BarChart f64(Collection f64) { + return BarChart(std::move(f64)); } public: diff --git a/rerun_cpp/src/rerun/archetypes/bar_chart_ext.cpp b/rerun_cpp/src/rerun/archetypes/bar_chart_ext.cpp index 69019f0191f1..a69c02f046e3 100644 --- a/rerun_cpp/src/rerun/archetypes/bar_chart_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/bar_chart_ext.cpp @@ -1,12 +1,9 @@ #include "../half.hpp" #include "bar_chart.hpp" -// #define EDIT_EXTENSION +namespace rerun::archetypes { -namespace rerun { - namespace archetypes { - -#ifdef EDIT_EXTENSION +#if 0 // BarChart(rerun::datatypes::TensorBuffer buffer) { @@ -16,112 +13,109 @@ namespace rerun { // -------------------------------------------------------------------- // Implicit constructors: - // TODO(#3794): don't use std::vector here - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u8) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u8) : BarChart(rerun::datatypes::TensorBuffer::u8(std::move(u8))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u16) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u16) : BarChart(rerun::datatypes::TensorBuffer::u16(std::move(u16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u32) : BarChart(rerun::datatypes::TensorBuffer::u32(std::move(u32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector u64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection u64) : BarChart(rerun::datatypes::TensorBuffer::u64(std::move(u64))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i8) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i8) : BarChart(rerun::datatypes::TensorBuffer::i8(std::move(i8))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i16) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i16) : BarChart(rerun::datatypes::TensorBuffer::i16(std::move(i16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i32) : BarChart(rerun::datatypes::TensorBuffer::i32(std::move(i32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector i64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection i64) : BarChart(rerun::datatypes::TensorBuffer::i64(std::move(i64))) {} - /// Construct aBarChart` from a `std::vector`. - BarChart(std::vector f16) + /// Construct aBarChart` from a `Collection`. + BarChart(Collection f16) : BarChart(rerun::datatypes::TensorBuffer::f16(std::move(f16))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f32) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection f32) : BarChart(rerun::datatypes::TensorBuffer::f32(std::move(f32))) {} - /// Construct a `BarChart` from a `std::vector`. - BarChart(std::vector f64) + /// Construct a `BarChart` from a `Collection`. + BarChart(Collection f64) : BarChart(rerun::datatypes::TensorBuffer::f64(std::move(f64))) {} // -------------------------------------------------------------------- // Explicit static constructors: - // TODO(#3794): don't use std::vector here - /// Construct a `BarChart` from a `std::vector`. - static BarChart u8(std::vector u8) { - return BarChart(u8); + /// Construct a `BarChart` from a `Collection`. + static BarChart u8(Collection u8) { + return BarChart(std::move(u8)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u16(std::vector u16) { - return BarChart(u16); + /// Construct a `BarChart` from a `Collection`. + static BarChart u16(Collection u16) { + return BarChart(std::move(u16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u32(std::vector u32) { - return BarChart(u32); + /// Construct a `BarChart` from a `Collection`. + static BarChart u32(Collection u32) { + return BarChart(std::move(u32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart u64(std::vector u64) { - return BarChart(u64); + /// Construct a `BarChart` from a `Collection`. + static BarChart u64(Collection u64) { + return BarChart(std::move(u64)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i8(std::vector i8) { - return BarChart(i8); + /// Construct a `BarChart` from a `Collection`. + static BarChart i8(Collection i8) { + return BarChart(std::move(i8)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i16(std::vector i16) { - return BarChart(i16); + /// Construct a `BarChart` from a `Collection`. + static BarChart i16(Collection i16) { + return BarChart(std::move(i16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i32(std::vector i32) { - return BarChart(i32); + /// Construct a `BarChart` from a `Collection`. + static BarChart i32(Collection i32) { + return BarChart(std::move(i32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart i64(std::vector i64) { - return BarChart(i64); + /// Construct a `BarChart` from a `Collection`. + static BarChart i64(Collection i64) { + return BarChart(std::move(i64)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f16(std::vector f16) { - return BarChart(f16); + /// Construct a `BarChart` from a `Collection`. + static BarChart f16(Collection f16) { + return BarChart(std::move(f16)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f32(std::vector f32) { - return BarChart(f32); + /// Construct a `BarChart` from a `Collection`. + static BarChart f32(Collection f32) { + return BarChart(std::move(f32)); } - /// Construct a `BarChart` from a `std::vector`. - static BarChart f64(std::vector f64) { - return BarChart(f64); + /// Construct a `BarChart` from a `Collection`. + static BarChart f64(Collection f64) { + return BarChart(std::move(f64)); } // #endif - } // namespace archetypes -} // namespace rerun +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/boxes2d.cpp b/rerun_cpp/src/rerun/archetypes/boxes2d.cpp index 856d20ac7fd4..0cb4806e42d1 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/boxes2d.cpp @@ -19,51 +19,70 @@ namespace rerun { cells.reserve(8); { - auto result = (archetype.half_sizes).serialize(); + const size_t size = archetype.half_sizes.size(); + auto result = rerun::components::HalfSizes2D::to_data_cell( + archetype.half_sizes.data(), + archetype.half_sizes.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.centers.has_value()) { - auto result = (archetype.centers.value()).serialize(); + const size_t size = archetype.centers.value().size(); + auto result = + rerun::components::Position2D::to_data_cell(archetype.centers.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Boxes2D::IndicatorComponent()).serialize(); + auto indicator = Boxes2D::IndicatorComponent(); + auto result = Boxes2D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/boxes2d.hpp b/rerun_cpp/src/rerun/archetypes/boxes2d.hpp index 58b16d66a6eb..d483185dde30 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/boxes2d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/draw_order.hpp" @@ -15,7 +16,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -136,28 +137,28 @@ namespace rerun::archetypes { Boxes2D with_centers(Collection _centers) && { centers = std::move(_centers); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the boxes. Boxes2D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional radii for the lines that make up the boxes. Boxes2D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the boxes. Boxes2D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional floating point value that specifies the 2D drawing order. @@ -168,7 +169,7 @@ namespace rerun::archetypes { Boxes2D with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional `ClassId`s for the boxes. @@ -177,14 +178,14 @@ namespace rerun::archetypes { Boxes2D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual boxes in the batch. Boxes2D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/boxes3d.cpp b/rerun_cpp/src/rerun/archetypes/boxes3d.cpp index 710cf5d26796..363d46d31b2d 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/boxes3d.cpp @@ -19,50 +19,72 @@ namespace rerun { cells.reserve(8); { - auto result = (archetype.half_sizes).serialize(); + const size_t size = archetype.half_sizes.size(); + auto result = rerun::components::HalfSizes3D::to_data_cell( + archetype.half_sizes.data(), + archetype.half_sizes.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.centers.has_value()) { - auto result = (archetype.centers.value()).serialize(); + const size_t size = archetype.centers.value().size(); + auto result = + rerun::components::Position3D::to_data_cell(archetype.centers.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.rotations.has_value()) { - auto result = (archetype.rotations.value()).serialize(); + const size_t size = archetype.rotations.value().size(); + auto result = rerun::components::Rotation3D::to_data_cell( + archetype.rotations.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Boxes3D::IndicatorComponent()).serialize(); + auto indicator = Boxes3D::IndicatorComponent(); + auto result = Boxes3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/boxes3d.hpp b/rerun_cpp/src/rerun/archetypes/boxes3d.hpp index b863a1667453..c279216d8c42 100644 --- a/rerun_cpp/src/rerun/archetypes/boxes3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/boxes3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/half_sizes3d.hpp" @@ -15,7 +16,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -150,34 +151,34 @@ namespace rerun::archetypes { Boxes3D with_centers(Collection _centers) && { centers = std::move(_centers); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } Boxes3D with_rotations(Collection _rotations) && { rotations = std::move(_rotations); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the boxes. Boxes3D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional radii for the lines that make up the boxes. Boxes3D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the boxes. Boxes3D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional `ClassId`s for the boxes. @@ -186,14 +187,14 @@ namespace rerun::archetypes { Boxes3D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual boxes in the batch. Boxes3D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/clear.cpp b/rerun_cpp/src/rerun/archetypes/clear.cpp index 974d99df4bbf..c91abfe4d3ad 100644 --- a/rerun_cpp/src/rerun/archetypes/clear.cpp +++ b/rerun_cpp/src/rerun/archetypes/clear.cpp @@ -19,16 +19,17 @@ namespace rerun { cells.reserve(1); { + const size_t size = 1; auto result = - Collection(archetype.is_recursive).serialize(); + rerun::components::ClearIsRecursive::to_data_cell(&archetype.is_recursive, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Clear::IndicatorComponent()).serialize(); + auto indicator = Clear::IndicatorComponent(); + auto result = Clear::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/clear.hpp b/rerun_cpp/src/rerun/archetypes/clear.hpp index 450f0fafcbe7..09d33ab65b22 100644 --- a/rerun_cpp/src/rerun/archetypes/clear.hpp +++ b/rerun_cpp/src/rerun/archetypes/clear.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.cpp b/rerun_cpp/src/rerun/archetypes/depth_image.cpp index 694b5fe74080..cfaa1cf1fa8c 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.cpp @@ -19,28 +19,30 @@ namespace rerun { cells.reserve(3); { - auto result = Collection(archetype.data).serialize(); + const size_t size = 1; + auto result = rerun::components::TensorData::to_data_cell(&archetype.data, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.meter.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.meter.value()).serialize(); + rerun::components::DepthMeter::to_data_cell(&archetype.meter.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(DepthImage::IndicatorComponent()) - .serialize(); + auto indicator = DepthImage::IndicatorComponent(); + auto result = DepthImage::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/depth_image.hpp b/rerun_cpp/src/rerun/archetypes/depth_image.hpp index ad5045336f31..f7cefc0c9c6c 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image.hpp @@ -4,13 +4,14 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/depth_meter.hpp" #include "../components/draw_order.hpp" #include "../components/tensor_data.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -91,14 +92,14 @@ namespace rerun::archetypes { /// /// Sets the dimension names to "height" and "width" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2. - DepthImage(std::vector shape, datatypes::TensorBuffer buffer) + DepthImage(Collection shape, datatypes::TensorBuffer buffer) : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New depth image from tensor data. /// /// Sets the dimension names to "height" and "width" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2. - explicit DepthImage(components::TensorData _data); + explicit DepthImage(components::TensorData data_); public: DepthImage() = default; @@ -111,7 +112,7 @@ namespace rerun::archetypes { DepthImage with_meter(rerun::components::DepthMeter _meter) && { meter = std::move(_meter); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional floating point value that specifies the 2D drawing order. @@ -120,7 +121,7 @@ namespace rerun::archetypes { DepthImage with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp index 10cad34c1474..6df0e8f61ba3 100644 --- a/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/depth_image_ext.cpp @@ -1,45 +1,53 @@ #include "../error.hpp" #include "depth_image.hpp" -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION +#include "../collection_adapter_builtins.hpp" -namespace rerun { - namespace archetypes { +namespace rerun::archetypes { #ifdef EDIT_EXTENSION - // - - /// New depth image from height/width and tensor buffer. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - DepthImage(std::vector shape, datatypes::TensorBuffer buffer) - : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - - /// New depth image from tensor data. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - explicit DepthImage(components::TensorData _data); - - // + // + + /// New depth image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + DepthImage(Collection shape, datatypes::TensorBuffer buffer) + : DepthImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + /// New depth image from tensor data. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit DepthImage(components::TensorData data_); + + // #endif - DepthImage::DepthImage(components::TensorData _data) : data(std::move(_data)) { - auto& shape = data.data.shape; - if (shape.size() != 2) { - Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle(); - return; - } + DepthImage::DepthImage(components::TensorData data_) : data(std::move(data_)) { + auto& shape = data.data.shape; + if (shape.size() != 2) { + Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle(); + return; + } + + // We want to change the dimension names if they are not specified. + // But rerun collections are strictly immutable, so create a new one if necessary. + bool overwrite_height = !shape[0].name.has_value(); + bool overwrite_width = !shape[1].name.has_value(); - if (!shape[0].name.has_value()) { - shape[0].name = "height"; + if (overwrite_height || overwrite_width) { + auto new_shape = shape.to_vector(); + + if (overwrite_height) { + new_shape[0].name = "height"; } - if (!shape[1].name.has_value()) { - shape[1].name = "width"; + if (overwrite_width) { + new_shape[1].name = "width"; } + + shape = std::move(new_shape); } + } - } // namespace archetypes -} // namespace rerun +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp b/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp index 79acfbf7a4a0..9441dd4e1ccb 100644 --- a/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp +++ b/rerun_cpp/src/rerun/archetypes/disconnected_space.cpp @@ -19,19 +19,19 @@ namespace rerun { cells.reserve(1); { - auto result = - Collection(archetype.disconnected_space) - .serialize(); + const size_t size = 1; + auto result = rerun::components::DisconnectedSpace::to_data_cell( + &archetype.disconnected_space, + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection( - DisconnectedSpace::IndicatorComponent() - ) - .serialize(); + auto indicator = DisconnectedSpace::IndicatorComponent(); + auto result = DisconnectedSpace::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp b/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp index f47cccc812a0..603643c7102d 100644 --- a/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp +++ b/rerun_cpp/src/rerun/archetypes/disconnected_space.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include diff --git a/rerun_cpp/src/rerun/archetypes/image.cpp b/rerun_cpp/src/rerun/archetypes/image.cpp index 941ba4c78df9..49c89fa41fa3 100644 --- a/rerun_cpp/src/rerun/archetypes/image.cpp +++ b/rerun_cpp/src/rerun/archetypes/image.cpp @@ -19,21 +19,23 @@ namespace rerun { cells.reserve(2); { - auto result = Collection(archetype.data).serialize(); + const size_t size = 1; + auto result = rerun::components::TensorData::to_data_cell(&archetype.data, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Image::IndicatorComponent()).serialize(); + auto indicator = Image::IndicatorComponent(); + auto result = Image::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/image.hpp b/rerun_cpp/src/rerun/archetypes/image.hpp index 25f56e7000de..9e238f48478a 100644 --- a/rerun_cpp/src/rerun/archetypes/image.hpp +++ b/rerun_cpp/src/rerun/archetypes/image.hpp @@ -4,12 +4,13 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/draw_order.hpp" #include "../components/tensor_data.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -80,14 +81,14 @@ namespace rerun::archetypes { /// /// Sets the dimension names to "height", "width" and "channel" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2 or 3. - Image(std::vector shape, datatypes::TensorBuffer buffer) + Image(Collection shape, datatypes::TensorBuffer buffer) : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// New depth image from tensor data. /// /// Sets the dimension names to "height", "width" and "channel" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2 or 3. - explicit Image(rerun::components::TensorData _data); + explicit Image(rerun::components::TensorData data_); public: Image() = default; @@ -99,7 +100,7 @@ namespace rerun::archetypes { Image with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/image_ext.cpp b/rerun_cpp/src/rerun/archetypes/image_ext.cpp index e847a4292433..52667557bee7 100644 --- a/rerun_cpp/src/rerun/archetypes/image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/image_ext.cpp @@ -1,60 +1,70 @@ #include "../error.hpp" #include "image.hpp" +#include "../collection_adapter_builtins.hpp" + // Uncomment for better auto-complete while editing the extension. // #define EDIT_EXTENSION -namespace rerun { - namespace archetypes { +namespace rerun::archetypes { #ifdef EDIT_EXTENSION - // - - /// New Image from height/width/channel and tensor buffer. - /// - /// Sets the dimension names to "height", "width" and "channel" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2 or 3. - Image(std::vector shape, datatypes::TensorBuffer buffer) - : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - - /// New depth image from tensor data. - /// - /// Sets the dimension names to "height", "width" and "channel" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2 or 3. - explicit Image(rerun::components::TensorData _data); - // + // + + /// New Image from height/width/channel and tensor buffer. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + Image(Collection shape, datatypes::TensorBuffer buffer) + : Image(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + + /// New depth image from tensor data. + /// + /// Sets the dimension names to "height", "width" and "channel" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2 or 3. + explicit Image(rerun::components::TensorData data_); + // #endif - Image::Image(rerun::components::TensorData _data) : data(std::move(_data)) { - auto& shape = data.data.shape; - if (shape.size() != 2 && shape.size() != 3) { - Error( - ErrorCode::InvalidTensorDimension, - "Image shape is expected to be either rank 2 or 3." - ) - .handle(); - return; - } - if (shape.size() == 3 && shape[2].size != 1 && shape[2].size != 3 && - shape[2].size != 4) { - Error( - ErrorCode::InvalidTensorDimension, - "Only images with 1, 3 and 4 channels are supported." - ) - .handle(); - return; - } + Image::Image(rerun::components::TensorData data_) : data(std::move(data_)) { + auto& shape = data.data.shape; + if (shape.size() != 2 && shape.size() != 3) { + Error( + ErrorCode::InvalidTensorDimension, + "Image shape is expected to be either rank 2 or 3." + ) + .handle(); + return; + } + if (shape.size() == 3 && shape[2].size != 1 && shape[2].size != 3 && shape[2].size != 4) { + Error( + ErrorCode::InvalidTensorDimension, + "Only images with 1, 3 and 4 channels are supported." + ) + .handle(); + return; + } + + // We want to change the dimension names if they are not specified. + // But rerun collections are strictly immutable, so create a new one if necessary. + bool overwrite_height = !shape[0].name.has_value(); + bool overwrite_width = !shape[1].name.has_value(); + bool overwrite_depth = shape.size() > 2 && !shape[2].name.has_value(); + + if (overwrite_height || overwrite_width || overwrite_depth) { + auto new_shape = shape.to_vector(); - if (!shape[0].name.has_value()) { - shape[0].name = "height"; + if (overwrite_height) { + new_shape[0].name = "height"; } - if (!shape[1].name.has_value()) { - shape[1].name = "width"; + if (overwrite_width) { + new_shape[1].name = "width"; } - if (shape.size() > 2 && !shape[2].name.has_value()) { - shape[2].name = "depth"; + if (overwrite_depth) { + new_shape[2].name = "depth"; } - } - } // namespace archetypes -} // namespace rerun + shape = std::move(new_shape); + } + } +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp b/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp index cc0a415b82d9..11a2feb97d95 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips2d.cpp @@ -19,47 +19,63 @@ namespace rerun { cells.reserve(7); { - auto result = (archetype.strips).serialize(); + const size_t size = archetype.strips.size(); + auto result = rerun::components::LineStrip2D::to_data_cell( + archetype.strips.data(), + archetype.strips.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(LineStrips2D::IndicatorComponent()) - .serialize(); + auto indicator = LineStrips2D::IndicatorComponent(); + auto result = LineStrips2D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp b/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp index dcae1e719ceb..fe18393e2d2d 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips2d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/draw_order.hpp" @@ -14,7 +15,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -38,8 +39,8 @@ namespace rerun::archetypes { /// const auto rec = rerun::RecordingStream("rerun_example_line_strip2d"); /// rec.spawn().exit_on_failure(); /// - /// std::vector strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; - /// std::vector strip2 = + /// rerun::Collection strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}}; + /// rerun::Collection strip2 = /// {{0.f, 3.f}, {1.f, 4.f}, {2.f, 2.f}, {3.f, 4.f}, {4.f, 2.f}, {5.f, 4.f}, {6.f, 3.f}}; /// rec.log( /// "strips", @@ -95,21 +96,21 @@ namespace rerun::archetypes { LineStrips2D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the line strips. LineStrips2D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the line strips. LineStrips2D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional floating point value that specifies the 2D drawing order of each line strip. @@ -118,7 +119,7 @@ namespace rerun::archetypes { LineStrips2D with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional `ClassId`s for the lines. @@ -127,7 +128,7 @@ namespace rerun::archetypes { LineStrips2D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual line strip in the batch. @@ -135,7 +136,7 @@ namespace rerun::archetypes { ) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp b/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp index e6001bb904ce..bf3a72a50cd5 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips3d.cpp @@ -19,41 +19,56 @@ namespace rerun { cells.reserve(6); { - auto result = (archetype.strips).serialize(); + const size_t size = archetype.strips.size(); + auto result = rerun::components::LineStrip3D::to_data_cell( + archetype.strips.data(), + archetype.strips.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(LineStrips3D::IndicatorComponent()) - .serialize(); + auto indicator = LineStrips3D::IndicatorComponent(); + auto result = LineStrips3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp b/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp index 6af94ba38984..c59425606c48 100644 --- a/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/line_strips3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/instance_key.hpp" @@ -13,7 +14,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -37,13 +38,13 @@ namespace rerun::archetypes { /// const auto rec = rerun::RecordingStream("rerun_example_line_strip3d"); /// rec.spawn().exit_on_failure(); /// - /// std::vector strip1 = { + /// rerun::Collection strip1 = { /// {0.f, 0.f, 2.f}, /// {1.f, 0.f, 2.f}, /// {1.f, 1.f, 2.f}, /// {0.f, 1.f, 2.f}, /// }; - /// std::vector strip2 = { + /// rerun::Collection strip2 = { /// {0.f, 0.f, 0.f}, /// {0.f, 0.f, 1.f}, /// {1.f, 0.f, 0.f}, @@ -99,21 +100,21 @@ namespace rerun::archetypes { LineStrips3D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the line strips. LineStrips3D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the line strips. LineStrips3D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional `ClassId`s for the lines. @@ -122,7 +123,7 @@ namespace rerun::archetypes { LineStrips3D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual line strip in the batch. @@ -130,7 +131,7 @@ namespace rerun::archetypes { ) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp index 725d16d77cd0..236f916d2310 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp @@ -19,48 +19,69 @@ namespace rerun { cells.reserve(7); { - auto result = (archetype.vertex_positions).serialize(); + const size_t size = archetype.vertex_positions.size(); + auto result = rerun::components::Position3D::to_data_cell( + archetype.vertex_positions.data(), + archetype.vertex_positions.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.mesh_properties.has_value()) { - auto result = - Collection(archetype.mesh_properties.value()) - .serialize(); + const size_t size = 1; + auto result = rerun::components::MeshProperties::to_data_cell( + &archetype.mesh_properties.value(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.vertex_normals.has_value()) { - auto result = (archetype.vertex_normals.value()).serialize(); + const size_t size = archetype.vertex_normals.value().size(); + auto result = rerun::components::Vector3D::to_data_cell( + archetype.vertex_normals.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.vertex_colors.has_value()) { - auto result = (archetype.vertex_colors.value()).serialize(); + const size_t size = archetype.vertex_colors.value().size(); + auto result = rerun::components::Color::to_data_cell( + archetype.vertex_colors.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.mesh_material.has_value()) { - auto result = Collection(archetype.mesh_material.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::Material::to_data_cell(&archetype.mesh_material.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Mesh3D::IndicatorComponent()).serialize(); + auto indicator = Mesh3D::IndicatorComponent(); + auto result = Mesh3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp index 6f8e90f32809..b55b1f98be66 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/instance_key.hpp" @@ -14,7 +15,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -104,7 +105,7 @@ namespace rerun::archetypes { Mesh3D with_mesh_properties(rerun::components::MeshProperties _mesh_properties) && { mesh_properties = std::move(_mesh_properties); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional normal for each vertex. @@ -113,21 +114,21 @@ namespace rerun::archetypes { Mesh3D with_vertex_normals(Collection _vertex_normals) && { vertex_normals = std::move(_vertex_normals); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional color for each vertex. Mesh3D with_vertex_colors(Collection _vertex_colors) && { vertex_colors = std::move(_vertex_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional material properties for the mesh as a whole. Mesh3D with_mesh_material(rerun::components::Material _mesh_material) && { mesh_material = std::move(_mesh_material); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional class Ids for the vertices. @@ -136,14 +137,14 @@ namespace rerun::archetypes { Mesh3D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual vertex in the mesh. Mesh3D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/pinhole.cpp b/rerun_cpp/src/rerun/archetypes/pinhole.cpp index e484b07718cd..7cde848d56f0 100644 --- a/rerun_cpp/src/rerun/archetypes/pinhole.cpp +++ b/rerun_cpp/src/rerun/archetypes/pinhole.cpp @@ -19,30 +19,35 @@ namespace rerun { cells.reserve(3); { - auto result = - Collection(archetype.image_from_camera) - .serialize(); + const size_t size = 1; + auto result = rerun::components::PinholeProjection::to_data_cell( + &archetype.image_from_camera, + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.resolution.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.resolution.value()).serialize(); + rerun::components::Resolution::to_data_cell(&archetype.resolution.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.camera_xyz.has_value()) { - auto result = - Collection(archetype.camera_xyz.value()) - .serialize(); + const size_t size = 1; + auto result = rerun::components::ViewCoordinates::to_data_cell( + &archetype.camera_xyz.value(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Pinhole::IndicatorComponent()).serialize(); + auto indicator = Pinhole::IndicatorComponent(); + auto result = Pinhole::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/pinhole.hpp b/rerun_cpp/src/rerun/archetypes/pinhole.hpp index c6f20c57f307..ebb6d08f03ab 100644 --- a/rerun_cpp/src/rerun/archetypes/pinhole.hpp +++ b/rerun_cpp/src/rerun/archetypes/pinhole.hpp @@ -4,13 +4,14 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/pinhole_projection.hpp" #include "../components/resolution.hpp" #include "../components/view_coordinates.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -155,7 +156,7 @@ namespace rerun::archetypes { Pinhole with_resolution(rerun::components::Resolution _resolution) && { resolution = std::move(_resolution); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Sets the view coordinates for the camera. @@ -188,7 +189,7 @@ namespace rerun::archetypes { Pinhole with_camera_xyz(rerun::components::ViewCoordinates _camera_xyz) && { camera_xyz = std::move(_camera_xyz); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/points2d.cpp b/rerun_cpp/src/rerun/archetypes/points2d.cpp index 30b6f0fd7b8d..aefb2c664143 100644 --- a/rerun_cpp/src/rerun/archetypes/points2d.cpp +++ b/rerun_cpp/src/rerun/archetypes/points2d.cpp @@ -19,51 +19,72 @@ namespace rerun { cells.reserve(8); { - auto result = (archetype.positions).serialize(); + const size_t size = archetype.positions.size(); + auto result = rerun::components::Position2D::to_data_cell( + archetype.positions.data(), + archetype.positions.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.keypoint_ids.has_value()) { - auto result = (archetype.keypoint_ids.value()).serialize(); + const size_t size = archetype.keypoint_ids.value().size(); + auto result = rerun::components::KeypointId::to_data_cell( + archetype.keypoint_ids.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection(Points2D::IndicatorComponent()) - .serialize(); + auto indicator = Points2D::IndicatorComponent(); + auto result = Points2D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/points2d.hpp b/rerun_cpp/src/rerun/archetypes/points2d.hpp index 7bb7c568d0cd..ab065ea187a9 100644 --- a/rerun_cpp/src/rerun/archetypes/points2d.hpp +++ b/rerun_cpp/src/rerun/archetypes/points2d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/draw_order.hpp" @@ -15,7 +16,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -120,21 +121,21 @@ namespace rerun::archetypes { Points2D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the points. Points2D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the points. Points2D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional floating point value that specifies the 2D drawing order. @@ -143,7 +144,7 @@ namespace rerun::archetypes { Points2D with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional class Ids for the points. @@ -152,7 +153,7 @@ namespace rerun::archetypes { Points2D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional keypoint IDs for the points, identifying them within a class. @@ -166,14 +167,14 @@ namespace rerun::archetypes { Points2D with_keypoint_ids(Collection _keypoint_ids) && { keypoint_ids = std::move(_keypoint_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual point in the batch. Points2D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/points3d.cpp b/rerun_cpp/src/rerun/archetypes/points3d.cpp index e7cb8f635219..975d37081bf7 100644 --- a/rerun_cpp/src/rerun/archetypes/points3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/points3d.cpp @@ -19,45 +19,65 @@ namespace rerun { cells.reserve(7); { - auto result = (archetype.positions).serialize(); + const size_t size = archetype.positions.size(); + auto result = rerun::components::Position3D::to_data_cell( + archetype.positions.data(), + archetype.positions.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radii.has_value()) { - auto result = (archetype.radii.value()).serialize(); + const size_t size = archetype.radii.value().size(); + auto result = + rerun::components::Radius::to_data_cell(archetype.radii.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.colors.has_value()) { - auto result = (archetype.colors.value()).serialize(); + const size_t size = archetype.colors.value().size(); + auto result = + rerun::components::Color::to_data_cell(archetype.colors.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.labels.has_value()) { - auto result = (archetype.labels.value()).serialize(); + const size_t size = archetype.labels.value().size(); + auto result = + rerun::components::Text::to_data_cell(archetype.labels.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.class_ids.has_value()) { - auto result = (archetype.class_ids.value()).serialize(); + const size_t size = archetype.class_ids.value().size(); + auto result = + rerun::components::ClassId::to_data_cell(archetype.class_ids.value().data(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.keypoint_ids.has_value()) { - auto result = (archetype.keypoint_ids.value()).serialize(); + const size_t size = archetype.keypoint_ids.value().size(); + auto result = rerun::components::KeypointId::to_data_cell( + archetype.keypoint_ids.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.instance_keys.has_value()) { - auto result = (archetype.instance_keys.value()).serialize(); + const size_t size = archetype.instance_keys.value().size(); + auto result = rerun::components::InstanceKey::to_data_cell( + archetype.instance_keys.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection(Points3D::IndicatorComponent()) - .serialize(); + auto indicator = Points3D::IndicatorComponent(); + auto result = Points3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/points3d.hpp b/rerun_cpp/src/rerun/archetypes/points3d.hpp index 525337e8d790..a9244828ab41 100644 --- a/rerun_cpp/src/rerun/archetypes/points3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/points3d.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" #include "../components/instance_key.hpp" @@ -14,7 +15,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -111,21 +112,21 @@ namespace rerun::archetypes { Points3D with_radii(Collection _radii) && { radii = std::move(_radii); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional colors for the points. Points3D with_colors(Collection _colors) && { colors = std::move(_colors); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional text labels for the points. Points3D with_labels(Collection _labels) && { labels = std::move(_labels); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional class Ids for the points. @@ -134,7 +135,7 @@ namespace rerun::archetypes { Points3D with_class_ids(Collection _class_ids) && { class_ids = std::move(_class_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional keypoint IDs for the points, identifying them within a class. @@ -148,14 +149,14 @@ namespace rerun::archetypes { Points3D with_keypoint_ids(Collection _keypoint_ids) && { keypoint_ids = std::move(_keypoint_ids); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Unique identifiers for each individual point in the batch. Points3D with_instance_keys(Collection _instance_keys) && { instance_keys = std::move(_instance_keys); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp index 241d01a2d4de..65b1175cad78 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.cpp @@ -19,23 +19,23 @@ namespace rerun { cells.reserve(2); { - auto result = Collection(archetype.data).serialize(); + const size_t size = 1; + auto result = rerun::components::TensorData::to_data_cell(&archetype.data, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.draw_order.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.draw_order.value()).serialize(); + rerun::components::DrawOrder::to_data_cell(&archetype.draw_order.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection( - SegmentationImage::IndicatorComponent() - ) - .serialize(); + auto indicator = SegmentationImage::IndicatorComponent(); + auto result = SegmentationImage::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp index 37265821473b..c88954f5fff4 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image.hpp @@ -4,12 +4,13 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/draw_order.hpp" #include "../components/tensor_data.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -85,7 +86,7 @@ namespace rerun::archetypes { /// Sets the dimension names to "height" and "width" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2. SegmentationImage( - std::vector shape, datatypes::TensorBuffer buffer + Collection shape, datatypes::TensorBuffer buffer ) : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} @@ -93,7 +94,7 @@ namespace rerun::archetypes { /// /// Sets the dimension names to "height" and "width" if they are not specified. /// Calls `Error::handle()` if the shape is not rank 2. - explicit SegmentationImage(components::TensorData _data); + explicit SegmentationImage(components::TensorData data_); public: SegmentationImage() = default; @@ -105,7 +106,7 @@ namespace rerun::archetypes { SegmentationImage with_draw_order(rerun::components::DrawOrder _draw_order) && { draw_order = std::move(_draw_order); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp index 8672d322ad5a..3a2e46486b53 100644 --- a/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/segmentation_image_ext.cpp @@ -1,48 +1,53 @@ -#include "../error.hpp" #include "segmentation_image.hpp" -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION +#include "../collection_adapter_builtins.hpp" +#include "../error.hpp" -namespace rerun { - namespace archetypes { +namespace rerun::archetypes { -#ifdef EDIT_EXTENSION - // +#if 0 + // - /// New segmentation image from height/width and tensor buffer. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - SegmentationImage( - std::vector shape, datatypes::TensorBuffer buffer - ) - : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} + /// New segmentation image from height/width and tensor buffer. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + SegmentationImage(Collection shape, datatypes::TensorBuffer buffer) + : SegmentationImage(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - /// New segmentation image from tensor data. - /// - /// Sets the dimension names to "height" and "width" if they are not specified. - /// Calls `Error::handle()` if the shape is not rank 2. - explicit SegmentationImage(components::TensorData _data); + /// New segmentation image from tensor data. + /// + /// Sets the dimension names to "height" and "width" if they are not specified. + /// Calls `Error::handle()` if the shape is not rank 2. + explicit SegmentationImage(components::TensorData data_); - // + // #endif - SegmentationImage::SegmentationImage(components::TensorData _data) - : data(std::move(_data)) { - auto& shape = data.data.shape; - if (shape.size() != 2) { - Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle(); - return; - } + SegmentationImage::SegmentationImage(components::TensorData data_) : data(std::move(data_)) { + auto& shape = data.data.shape; + if (shape.size() != 2) { + Error(ErrorCode::InvalidTensorDimension, "Shape must be rank 2.").handle(); + return; + } - if (!shape[0].name.has_value()) { - shape[0].name = "height"; + // We want to change the dimension names if they are not specified. + // But rerun collections are strictly immutable, so create a new one if necessary. + bool overwrite_height = !shape[0].name.has_value(); + bool overwrite_width = !shape[1].name.has_value(); + + if (overwrite_height || overwrite_width) { + auto new_shape = shape.to_vector(); + + if (overwrite_height) { + new_shape[0].name = "height"; } - if (!shape[1].name.has_value()) { - shape[1].name = "width"; + if (overwrite_width) { + new_shape[1].name = "width"; } + + shape = std::move(new_shape); } + } - } // namespace archetypes -} // namespace rerun +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/tensor.cpp b/rerun_cpp/src/rerun/archetypes/tensor.cpp index d95657083847..35c1794ed8c2 100644 --- a/rerun_cpp/src/rerun/archetypes/tensor.cpp +++ b/rerun_cpp/src/rerun/archetypes/tensor.cpp @@ -19,15 +19,16 @@ namespace rerun { cells.reserve(1); { - auto result = Collection(archetype.data).serialize(); + const size_t size = 1; + auto result = rerun::components::TensorData::to_data_cell(&archetype.data, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Tensor::IndicatorComponent()).serialize(); + auto indicator = Tensor::IndicatorComponent(); + auto result = Tensor::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/tensor.hpp b/rerun_cpp/src/rerun/archetypes/tensor.hpp index 1959aa5bc3f4..c8514aa8bee4 100644 --- a/rerun_cpp/src/rerun/archetypes/tensor.hpp +++ b/rerun_cpp/src/rerun/archetypes/tensor.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -58,11 +59,8 @@ namespace rerun::archetypes { // Extensions to generated type defined in 'tensor_ext.cpp' /// New Tensor from dimensions and tensor buffer. - Tensor( - std::vector shape, - rerun::datatypes::TensorBuffer buffer - ) - : Tensor(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} + Tensor(Collection shape, datatypes::TensorBuffer buffer) + : Tensor(datatypes::TensorData(std::move(shape), std::move(buffer))) {} /// Update the `names` of the contained `TensorData` dimensions. /// @@ -70,9 +68,7 @@ namespace rerun::archetypes { /// /// If too many, or too few names are provided, this function will call /// Error::handle and then proceed to only update the subset of names that it can. - /// - /// TODO(#3794): don't use std::vector here. - Tensor with_dim_names(std::vector names) &&; + Tensor with_dim_names(Collection names) &&; public: Tensor() = default; diff --git a/rerun_cpp/src/rerun/archetypes/tensor_ext.cpp b/rerun_cpp/src/rerun/archetypes/tensor_ext.cpp index 75e29c54c017..1059295abc9b 100644 --- a/rerun_cpp/src/rerun/archetypes/tensor_ext.cpp +++ b/rerun_cpp/src/rerun/archetypes/tensor_ext.cpp @@ -4,56 +4,49 @@ #include // std::min #include // std::to_string #include // std::move -#include - -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION - -namespace rerun { - namespace archetypes { - -#ifdef EDIT_EXTENSION - // - - /// New Tensor from dimensions and tensor buffer. - Tensor( - std::vector shape, - rerun::datatypes::TensorBuffer buffer - ) - : Tensor(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} - - /// Update the `names` of the contained `TensorData` dimensions. - /// - /// Any existing Dimension names will be overwritten. - /// - /// If too many, or too few names are provided, this function will call - /// Error::handle and then proceed to only update the subset of names that it can. - /// - /// TODO(#3794): don't use std::vector here. - Tensor with_dim_names(std::vector names) &&; - - // -#endif - Tensor Tensor::with_dim_names(std::vector names) && { - auto& shape = data.data.shape; +#include "../collection_adapter_builtins.hpp" + +namespace rerun::archetypes { + +#if 0 + // + + /// New Tensor from dimensions and tensor buffer. + Tensor(Collection shape, datatypes::TensorBuffer buffer) + : Tensor(datatypes::TensorData(std::move(shape), std::move(buffer))) {} - if (names.size() != shape.size()) { - Error( - ErrorCode::InvalidTensorDimension, - "Wrong number of names provided for tensor dimension. " + - std::to_string(names.size()) + " provided but " + - std::to_string(shape.size()) + " expected." - ) - .handle(); - } + /// Update the `names` of the contained `TensorData` dimensions. + /// + /// Any existing Dimension names will be overwritten. + /// + /// If too many, or too few names are provided, this function will call + /// Error::handle and then proceed to only update the subset of names that it can. + Tensor with_dim_names(Collection names) &&; - for (size_t i = 0; i < std::min(shape.size(), names.size()); ++i) { - shape[i].name = std::move(names[i]); - } + // +#endif + + Tensor Tensor::with_dim_names(Collection names) && { + auto& shape = data.data.shape; + + if (names.size() != shape.size()) { + Error( + ErrorCode::InvalidTensorDimension, + "Wrong number of names provided for tensor dimension. " + + std::to_string(names.size()) + " provided but " + std::to_string(shape.size()) + + " expected." + ) + .handle(); + } - return std::move(*this); + auto new_shape = shape.to_vector(); + for (size_t i = 0; i < std::min(shape.size(), names.size()); ++i) { + new_shape[i].name = std::move(names[i]); } + shape = std::move(new_shape); + + return std::move(*this); + } - } // namespace archetypes -} // namespace rerun +} // namespace rerun::archetypes diff --git a/rerun_cpp/src/rerun/archetypes/text_document.cpp b/rerun_cpp/src/rerun/archetypes/text_document.cpp index c59d0bb0f0e9..d20bda2eda15 100644 --- a/rerun_cpp/src/rerun/archetypes/text_document.cpp +++ b/rerun_cpp/src/rerun/archetypes/text_document.cpp @@ -19,22 +19,23 @@ namespace rerun { cells.reserve(2); { - auto result = Collection(archetype.text).serialize(); + const size_t size = 1; + auto result = rerun::components::Text::to_data_cell(&archetype.text, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.media_type.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.media_type.value()).serialize(); + rerun::components::MediaType::to_data_cell(&archetype.media_type.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(TextDocument::IndicatorComponent()) - .serialize(); + auto indicator = TextDocument::IndicatorComponent(); + auto result = TextDocument::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/text_document.hpp b/rerun_cpp/src/rerun/archetypes/text_document.hpp index bce816116a2b..022320953b4a 100644 --- a/rerun_cpp/src/rerun/archetypes/text_document.hpp +++ b/rerun_cpp/src/rerun/archetypes/text_document.hpp @@ -4,12 +4,13 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/media_type.hpp" #include "../components/text.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -108,7 +109,7 @@ namespace rerun::archetypes { TextDocument with_media_type(rerun::components::MediaType _media_type) && { media_type = std::move(_media_type); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/text_log.cpp b/rerun_cpp/src/rerun/archetypes/text_log.cpp index fe198ac7fa2c..913a2adb76a8 100644 --- a/rerun_cpp/src/rerun/archetypes/text_log.cpp +++ b/rerun_cpp/src/rerun/archetypes/text_log.cpp @@ -19,26 +19,29 @@ namespace rerun { cells.reserve(3); { - auto result = Collection(archetype.text).serialize(); + const size_t size = 1; + auto result = rerun::components::Text::to_data_cell(&archetype.text, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.level.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.level.value()).serialize(); + rerun::components::TextLogLevel::to_data_cell(&archetype.level.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.color.has_value()) { - auto result = Collection(archetype.color.value()).serialize(); + const size_t size = 1; + auto result = rerun::components::Color::to_data_cell(&archetype.color.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(TextLog::IndicatorComponent()).serialize(); + auto indicator = TextLog::IndicatorComponent(); + auto result = TextLog::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/text_log.hpp b/rerun_cpp/src/rerun/archetypes/text_log.hpp index 5702e1603a1d..260f02624bf9 100644 --- a/rerun_cpp/src/rerun/archetypes/text_log.hpp +++ b/rerun_cpp/src/rerun/archetypes/text_log.hpp @@ -4,13 +4,14 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/color.hpp" #include "../components/text.hpp" #include "../components/text_log_level.hpp" #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -107,14 +108,14 @@ namespace rerun::archetypes { TextLog with_level(rerun::components::TextLogLevel _level) && { level = std::move(_level); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional color to use for the log line in the Rerun Viewer. TextLog with_color(rerun::components::Color _color) && { color = std::move(_color); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp b/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp index b29a50f845d7..9db2b8961d45 100644 --- a/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp +++ b/rerun_cpp/src/rerun/archetypes/time_series_scalar.cpp @@ -19,40 +19,43 @@ namespace rerun { cells.reserve(5); { - auto result = Collection(archetype.scalar).serialize(); + const size_t size = 1; + auto result = rerun::components::Scalar::to_data_cell(&archetype.scalar, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.radius.has_value()) { - auto result = - Collection(archetype.radius.value()).serialize(); + const size_t size = 1; + auto result = rerun::components::Radius::to_data_cell(&archetype.radius.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.color.has_value()) { - auto result = Collection(archetype.color.value()).serialize(); + const size_t size = 1; + auto result = rerun::components::Color::to_data_cell(&archetype.color.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.label.has_value()) { - auto result = Collection(archetype.label.value()).serialize(); + const size_t size = 1; + auto result = rerun::components::Text::to_data_cell(&archetype.label.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.scattered.has_value()) { - auto result = - Collection(archetype.scattered.value()) - .serialize(); + const size_t size = 1; + auto result = rerun::components::ScalarScattering::to_data_cell( + &archetype.scattered.value(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection( - TimeSeriesScalar::IndicatorComponent() - ) - .serialize(); + auto indicator = TimeSeriesScalar::IndicatorComponent(); + auto result = TimeSeriesScalar::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp b/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp index 54eee586d458..e1023183e1d5 100644 --- a/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp +++ b/rerun_cpp/src/rerun/archetypes/time_series_scalar.hpp @@ -4,6 +4,7 @@ #pragma once #include "../collection.hpp" +#include "../compiler_utils.hpp" #include "../components/color.hpp" #include "../components/radius.hpp" #include "../components/scalar.hpp" @@ -12,7 +13,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" +#include "../serialized_component_batch.hpp" #include #include @@ -113,7 +114,7 @@ namespace rerun::archetypes { TimeSeriesScalar with_radius(rerun::components::Radius _radius) && { radius = std::move(_radius); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Optional color for the scalar entry. @@ -130,7 +131,7 @@ namespace rerun::archetypes { TimeSeriesScalar with_color(rerun::components::Color _color) && { color = std::move(_color); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// An optional label for the point. @@ -144,7 +145,7 @@ namespace rerun::archetypes { TimeSeriesScalar with_label(rerun::components::Text _label) && { label = std::move(_label); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Specifies whether a point in a scatter plot should form a continuous line. @@ -157,7 +158,7 @@ namespace rerun::archetypes { TimeSeriesScalar with_scattered(rerun::components::ScalarScattering _scattered) && { scattered = std::move(_scattered); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/src/rerun/archetypes/transform3d.cpp b/rerun_cpp/src/rerun/archetypes/transform3d.cpp index d65945c2877e..5963ebe98cb1 100644 --- a/rerun_cpp/src/rerun/archetypes/transform3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/transform3d.cpp @@ -19,17 +19,16 @@ namespace rerun { cells.reserve(1); { - auto result = - Collection(archetype.transform).serialize(); + const size_t size = 1; + auto result = rerun::components::Transform3D::to_data_cell(&archetype.transform, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(Transform3D::IndicatorComponent()) - .serialize(); + auto indicator = Transform3D::IndicatorComponent(); + auto result = Transform3D::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/transform3d.hpp b/rerun_cpp/src/rerun/archetypes/transform3d.hpp index c2409ceb1c2a..ef552e14e349 100644 --- a/rerun_cpp/src/rerun/archetypes/transform3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/transform3d.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include diff --git a/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp b/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp index b680439f3112..a253192dbcce 100644 --- a/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp +++ b/rerun_cpp/src/rerun/archetypes/view_coordinates.cpp @@ -19,17 +19,16 @@ namespace rerun { cells.reserve(1); { - auto result = Collection(archetype.xyz).serialize(); + const size_t size = 1; + auto result = rerun::components::ViewCoordinates::to_data_cell(&archetype.xyz, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = Collection( - ViewCoordinates::IndicatorComponent() - ) - .serialize(); + auto indicator = ViewCoordinates::IndicatorComponent(); + auto result = ViewCoordinates::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp b/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp index e78df59e8411..170087566eef 100644 --- a/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp +++ b/rerun_cpp/src/rerun/archetypes/view_coordinates.hpp @@ -8,6 +8,7 @@ #include "../data_cell.hpp" #include "../indicator_component.hpp" #include "../result.hpp" +#include "../serialized_component_batch.hpp" #include #include diff --git a/rerun_cpp/src/rerun/as_components.hpp b/rerun_cpp/src/rerun/as_components.hpp index 001e8ea878c3..5436c331d881 100644 --- a/rerun_cpp/src/rerun/as_components.hpp +++ b/rerun_cpp/src/rerun/as_components.hpp @@ -2,6 +2,7 @@ #include "collection.hpp" #include "indicator_component.hpp" +#include "serialized_component_batch.hpp" namespace rerun { /// The AsComponents trait is used to convert a type into a list of serialized component. @@ -11,13 +12,14 @@ namespace rerun { /// Anything that implements `AsComponents` can be logged to a recording stream. template struct AsComponents { + /// \private + /// `NoAsComponentsFor` always evaluates to false, but in a way that requires template instantiation. template struct NoAsComponentsFor : std::false_type {}; // TODO(andreas): This should also mention an example of how to implement this. static_assert( - NoAsComponentsFor::value, // Always evaluate to false, but in a way that requires - // template instantiation. + NoAsComponentsFor::value, "AsComponents is not implemented for this type. " "It is implemented for all built-in archetypes as well as std::vector, std::array, and " "c-arrays of components. " @@ -34,9 +36,12 @@ namespace rerun { static Result> serialize( const Collection& components ) { - const auto result = components.serialize(); - RR_RETURN_NOT_OK(result.error); - return Result(std::vector{std::move(result.value)}); + auto cell_result = TComponent::to_data_cell(components.data(), components.size()); + RR_RETURN_NOT_OK(cell_result.error); + + return Result>( + {SerializedComponentBatch(std::move(cell_result.value), components.size())} + ); } }; diff --git a/rerun_cpp/src/rerun/blueprint/entity_properties_component.hpp b/rerun_cpp/src/rerun/blueprint/entity_properties_component.hpp index d56b9910c2b9..a894db825e67 100644 --- a/rerun_cpp/src/rerun/blueprint/entity_properties_component.hpp +++ b/rerun_cpp/src/rerun/blueprint/entity_properties_component.hpp @@ -3,12 +3,12 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include #include -#include namespace arrow { class DataType; @@ -21,14 +21,14 @@ namespace rerun::blueprint { /// /// Unstable. Used for the ongoing blueprint experimentations. struct EntityPropertiesComponent { - std::vector props; + rerun::Collection props; public: EntityPropertiesComponent() = default; - EntityPropertiesComponent(std::vector props_) : props(std::move(props_)) {} + EntityPropertiesComponent(rerun::Collection props_) : props(std::move(props_)) {} - EntityPropertiesComponent& operator=(std::vector props_) { + EntityPropertiesComponent& operator=(rerun::Collection props_) { props = std::move(props_); return *this; } diff --git a/rerun_cpp/src/rerun/blueprint/query_expressions.hpp b/rerun_cpp/src/rerun/blueprint/query_expressions.hpp index 9e960a8509fd..e4bb207b2354 100644 --- a/rerun_cpp/src/rerun/blueprint/query_expressions.hpp +++ b/rerun_cpp/src/rerun/blueprint/query_expressions.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include #include #include -#include namespace arrow { class DataType; @@ -23,15 +23,15 @@ namespace rerun::blueprint { /// Unstable. Used for the ongoing blueprint experimentations. struct QueryExpressions { /// A set of strings that can be parsed as `EntityPathExpression`s. - std::vector expressions; + rerun::Collection expressions; public: QueryExpressions() = default; - QueryExpressions(std::vector expressions_) + QueryExpressions(rerun::Collection expressions_) : expressions(std::move(expressions_)) {} - QueryExpressions& operator=(std::vector expressions_) { + QueryExpressions& operator=(rerun::Collection expressions_) { expressions = std::move(expressions_); return *this; } diff --git a/rerun_cpp/src/rerun/blueprint/space_view_component.hpp b/rerun_cpp/src/rerun/blueprint/space_view_component.hpp index 35261ca169e2..1921cdc21dbd 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_component.hpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_component.hpp @@ -3,12 +3,12 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include #include -#include namespace arrow { class DataType; @@ -21,14 +21,15 @@ namespace rerun::blueprint { /// /// Unstable. Used for the ongoing blueprint experimentations. struct SpaceViewComponent { - std::vector space_view; + rerun::Collection space_view; public: SpaceViewComponent() = default; - SpaceViewComponent(std::vector space_view_) : space_view(std::move(space_view_)) {} + SpaceViewComponent(rerun::Collection space_view_) + : space_view(std::move(space_view_)) {} - SpaceViewComponent& operator=(std::vector space_view_) { + SpaceViewComponent& operator=(rerun::Collection space_view_) { space_view = std::move(space_view_); return *this; } diff --git a/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp b/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp index 693b72aafe14..9bab506c5199 100644 --- a/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp +++ b/rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include #include #include -#include namespace arrow { class DataType; @@ -22,14 +22,14 @@ namespace rerun::blueprint { /// /// Unstable. Used for the ongoing blueprint experimentations. struct SpaceViewMaximized { - std::optional> id; + std::optional> id; public: SpaceViewMaximized() = default; - SpaceViewMaximized(std::optional> id_) : id(std::move(id_)) {} + SpaceViewMaximized(std::optional> id_) : id(std::move(id_)) {} - SpaceViewMaximized& operator=(std::optional> id_) { + SpaceViewMaximized& operator=(std::optional> id_) { id = std::move(id_); return *this; } diff --git a/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp b/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp index 1e36ca31d356..5f4b304d925d 100644 --- a/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp +++ b/rerun_cpp/src/rerun/blueprint/viewport_layout.hpp @@ -3,11 +3,11 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include -#include namespace arrow { class DataType; @@ -21,10 +21,10 @@ namespace rerun::blueprint { /// Unstable. Used for the ongoing blueprint experimentations. struct ViewportLayout { /// space_view_keys - std::vector space_view_keys; + rerun::Collection space_view_keys; /// tree - std::vector tree; + rerun::Collection tree; /// auto_layout bool auto_layout; diff --git a/rerun_cpp/src/rerun/collection.hpp b/rerun_cpp/src/rerun/collection.hpp index 4efcac73fc18..acfe12fd0ca2 100644 --- a/rerun_cpp/src/rerun/collection.hpp +++ b/rerun_cpp/src/rerun/collection.hpp @@ -1,18 +1,14 @@ #pragma once #include -#include - +#include +#include // std::memset #include #include #include "collection.hpp" #include "collection_adapter.hpp" -#include "warning_macros.hpp" - -// TODO(#3794): remove, needed for serialization. -#include "result.hpp" -#include "serialized_component_batch.hpp" +#include "compiler_utils.hpp" namespace rerun { /// Type of ownership of a collection's data. @@ -38,6 +34,10 @@ namespace rerun { /// or (most commonly in user code) implicitly using the `CollectionAdapter` trait /// (see documentation for `CollectionAdapter` for more information on how data can be adapted). /// + /// Other than being assignable, collections are generally immutable: + /// there is no mutable data access in order to not violate the contract with the data lender + /// and changes in size are not possible. + /// /// ## Implementation notes: /// /// Does intentionally not implement copy construction since this for the owned case this may @@ -46,12 +46,19 @@ namespace rerun { template class Collection { public: - using ElementType = TElement; + /// Type of the elements in the collection. + /// + /// Note that calling this `value_type` makes it compatible with the STL. + using value_type = TElement; - /// Type of an adapter given input types Ts. - template + /// Type of an adapter given an input container type. + /// + /// Note that the "container" passed may also be a single element of something. + /// The only thing relevant is that there's an Adapter for it. + template using Adapter = CollectionAdapter< - TElement, std::remove_cv_t>, std::enable_if_t>; + TElement, std::remove_cv_t>, + std::enable_if_t>; /// Creates a new empty collection. Collection() : ownership(CollectionOwnership::Borrowed) { @@ -60,16 +67,68 @@ namespace rerun { } /// Construct using a `CollectionAdapter` for the given input type. - template - Collection(T&& input) : Collection(Adapter()(std::forward(input))) {} + template < + typename TContainer, // + // Avoid conflicting with the copy/move constructor. + // We could implement this also with an adapter, but this might confuse trait checks like `std::is_copy_constructible`. + typename = std::enable_if_t< + !std::is_same_v, Collection>> // + > + Collection(TContainer&& input) + : Collection(Adapter()(std::forward(input))) {} + + /// Copy constructor. + /// + /// If the data is owned, this will copy the data. + /// If the data is borrowed, this will copy the borrow, + /// meaning there's now (at least) two collections borrowing the same data. + Collection(const Collection& other) : ownership(other.ownership) { + switch (other.ownership) { + case CollectionOwnership::Borrowed: { + storage.borrowed = other.storage.borrowed; + break; + } + + case CollectionOwnership::VectorOwned: { + new (&storage.vector_owned) std::vector(other.storage.vector_owned); + break; + } + } + } - /// Construct from a temporary list of elements. + /// Copy assignment. + /// + /// If the data is owned, this will copy the data. + /// If the data is borrowed, this will copy the borrow, + /// meaning there's now (at least) two collections borrowing the same data. + void operator=(const Collection& other) { + this->~Collection(); + new (this) Collection(other); + } + + /// Move constructor. + Collection(Collection&& other) : Collection() { + swap(other); + } + + /// Move assignment. + void operator=(Collection&& other) { + // Need to disable the maybe-uninitialized here. It seems like the compiler may be confused in situations where + // we are assigning into an unused optional from a temporary. The fact that this hits the move-assignment without + // having called the move constructor is suspicious though and hints of an actual bug. + // + // See: https://github.com/rerun-io/rerun/issues/4027 + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(this->swap(other);) + } + + /// Construct from a initializer list of elements that are compatible with TElement. /// /// Takes ownership of the passed elements. /// If you want to avoid an allocation, you have to manually keep the data on the stack /// (e.g. as `std::array`) and construct the collection from this instead. /// - /// This is not done as a `CollectionAdapter` since it tends to cause deduction issues. + /// This is not done as a `CollectionAdapter` since it tends to cause deduction issues + /// (since there's special rules for overload resolution for initializer lists) Collection(std::initializer_list data) : ownership(CollectionOwnership::VectorOwned) { // Don't assign, since the vector is in an undefined state and assigning may @@ -83,6 +142,9 @@ namespace rerun { /// (If the pointer passed is into an std::vector or similar, this std::vector mustn't be /// resized.) /// The passed type must be binary compatible with the collection type. + /// + /// Since `rerun::Collection` does not provide write access, data is guaranteed to be unchanged by + /// any function or operation taking on a `Collection`. template static Collection borrow(const T* data, size_t num_instances) { static_assert( @@ -108,6 +170,9 @@ namespace rerun { /// Borrowed data must outlive the collection! /// (If the pointer passed is into an std::vector or similar, this std::vector mustn't be /// resized.) + /// + /// Since `rerun::Collection` does not provide write access, data is guaranteed to be unchanged by + /// any function or operation taking on a `rerun::Collection`. static Collection borrow(const void* data, size_t num_instances) { return borrow(reinterpret_cast(data), num_instances); } @@ -128,22 +193,9 @@ namespace rerun { /// Takes ownership of a single element, moving it into the collection. static Collection take_ownership(TElement&& data) { // TODO(andreas): there should be a special path here to avoid allocating a vector. - return take_ownership(std::vector{std::move(data)}); - } - - /// Move constructor. - Collection(Collection&& other) : Collection() { - swap(other); - } - - /// Move assignment. - void operator=(Collection&& other) { - // Need to disable the maybe-uninitialized here. It seems like the compiler may be confused in situations where - // we are assigning into an unused optional from a temporary. The fact that this hits the move-assignment without - // having called the move constructor is suspicious though and hints of an actual bug. - // - // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(this->swap(other);) + std::vector elements; + elements.emplace_back(std::move(data)); + return take_ownership(std::move(elements)); } /// Swaps the content of this collection with another. @@ -198,9 +250,6 @@ namespace rerun { } } - /// Copy constructor. - Collection(const Collection&) = delete; - /// Returns the number of instances in this collection. size_t size() const { switch (ownership) { @@ -212,37 +261,44 @@ namespace rerun { return 0; } - /// Serializes the component batch into a rerun datacell that can be sent to a store. - Result serialize() const { - // TODO(#3794): Invert this relationship - a user of this *container* should call - // TElement::serialize (or similar) passing in this container. - switch (this->ownership) { - case CollectionOwnership::Borrowed: { - auto cell_result = TElement::to_data_cell( - this->storage.borrowed.data, - this->storage.borrowed.num_instances - ); - RR_RETURN_NOT_OK(cell_result.error); - return SerializedComponentBatch( - this->storage.borrowed.num_instances, - std::move(cell_result.value) - ); - } - - case CollectionOwnership::VectorOwned: { - auto cell_result = TElement::to_data_cell( - this->storage.vector_owned.data(), - this->storage.vector_owned.size() - ); - RR_RETURN_NOT_OK(cell_result.error); - return SerializedComponentBatch( - this->storage.vector_owned.size(), - std::move(cell_result.value) - ); - } + /// Returns a raw pointer to the underlying data. + /// + /// Do not use this if the data is not continuous in memory! + /// TODO(#4225): So far it always is continuous, but in the future we want to support strides! + /// + /// The pointer is only valid as long as backing storage is alive + /// which is either until the collection is destroyed the borrowed source is destroyed/moved. + const TElement* data() const { + switch (ownership) { + case CollectionOwnership::Borrowed: + return storage.borrowed.data; + case CollectionOwnership::VectorOwned: + return storage.vector_owned.data(); } - return Error(ErrorCode::Unknown, "Invalid ownership state"); + // We need to return something to avoid compiler warnings. + // But if we don't mark this as unreachable, GCC will complain that we're dereferencing null down the line. + RERUN_UNREACHABLE(); + // But with this in place, MSVC complains that the return statement is not reachable (GCC/clang on the other hand need it). +#ifndef _MSC_VER + return nullptr; +#endif + } + + /// TODO(andreas): Return proper iterator + const TElement* begin() const { + return data(); + } + + /// TODO(andreas): Return proper iterator + const TElement* end() const { + return data() + size(); + } + + /// Random read access to the underlying data. + const TElement& operator[](size_t i) const { + assert(i < size()); + return data()[i]; } /// Returns the data ownership of collection. @@ -252,6 +308,15 @@ namespace rerun { return ownership; } + /// Copies the data into a new `std::vector`. + std::vector to_vector() const { + // TODO(andreas): Overload this for `const &` and `&&` to avoid the copy when possible. + std::vector result; + result.reserve(size()); + result.insert(result.end(), begin(), end()); + return result; + } + private: template union CollectionStorage { @@ -263,7 +328,7 @@ namespace rerun { std::vector vector_owned; CollectionStorage() { - memset(reinterpret_cast(this), 0, sizeof(CollectionStorage)); + std::memset(reinterpret_cast(this), 0, sizeof(CollectionStorage)); } ~CollectionStorage() {} @@ -273,3 +338,8 @@ namespace rerun { CollectionStorage storage; }; } // namespace rerun + +// Could keep this separately, but its very hard to use the collection without the basic suite of adapters. +// Needs to know about `rerun::Collection` which means that it needs to be included after `rerun::Collection` is defined. +// (it tried to include `Collection.hpp` but if that was our starting point that include wouldn't do anything) +#include "collection_adapter_builtins.hpp" diff --git a/rerun_cpp/src/rerun/collection_adapter.hpp b/rerun_cpp/src/rerun/collection_adapter.hpp index 33199d276582..9767bdc75376 100644 --- a/rerun_cpp/src/rerun/collection_adapter.hpp +++ b/rerun_cpp/src/rerun/collection_adapter.hpp @@ -1,5 +1,7 @@ #pragma once +#include // std::enable_if, std::false_type + namespace rerun { /// The `rerun::CollectionAdapter` trait is responsible for mapping an input argument to a `rerun::Collection`. /// @@ -21,7 +23,7 @@ namespace rerun { /// input)` in order to accidentally borrow data that is passed in as a temporary! /// /// TODO(andreas): Point to an example here and in the assert. - template > + template > struct CollectionAdapter { /// \private /// `NoAdapterFor` always evaluates to false, but in a way that requires template instantiation. @@ -29,13 +31,13 @@ namespace rerun { struct NoAdapterFor : std::false_type {}; static_assert( - NoAdapterFor::value, + NoAdapterFor::value, "CollectionAdapter is not implemented for this type. " "It is implemented for single elements as well as std::vector, std::array, and " "c-arrays of components. " "You can add your own implementation by specializing " - "CollectionAdapter for a given " - "target type TElement and your input type T." + "rerun::CollectionAdapter for a given " + "target type TElement and your input type TContainer." ); }; } // namespace rerun diff --git a/rerun_cpp/src/rerun/collection_adapter_builtins.hpp b/rerun_cpp/src/rerun/collection_adapter_builtins.hpp index ac6739404f36..099ee5a685f4 100644 --- a/rerun_cpp/src/rerun/collection_adapter_builtins.hpp +++ b/rerun_cpp/src/rerun/collection_adapter_builtins.hpp @@ -2,14 +2,19 @@ #include "collection.hpp" #include "collection_adapter.hpp" +#include "type_traits.hpp" + +#include +#include // Documenting the builtin adapters is too much clutter for the doc class overview. /// \cond private namespace rerun { - /// Adapter from std::vector of components. + /// Adapter from `std::vector` of elements with the target type. /// /// Only takes ownership if a temporary is passed. + /// No allocation or copy is performed in any case. Furthermore, elements are not moved. template struct CollectionAdapter> { Collection operator()(const std::vector& input) { @@ -21,39 +26,44 @@ namespace rerun { } }; - /// Adapter from std::vector where T can be converted to TElement - template + /// Adapter for a iterable container (see `rerun::traits::is_iterable_v`) which + /// has a value type from which `TElement` can be constructed but is not equal to `TElement`. + /// + /// Since this needs to do a conversion, this will always need to allocate space. + /// However, if a temporary is passed, elements will be moved instead of copied upon construction of `TElement`. + template struct CollectionAdapter< - TElement, std::vector, + TElement, TContainer, std::enable_if_t< - !std::is_same_v && std::is_constructible_v>> { - Collection operator()(const std::vector& input) { - std::vector transformed(input.size()); - - std::transform(input.begin(), input.end(), transformed.begin(), [](const T& datum) { - return TElement(datum); - }); - - return Collection::take_ownership(std::move(transformed)); + !std::is_same_v> && // + traits::is_iterable_v && // + std::is_constructible_v< + TElement, + traits::value_type_of_t> // + >> { + Collection operator()(const TContainer& input) { + std::vector elements(std::begin(input), std::end(input)); + return Collection::take_ownership(std::move(elements)); } - Collection operator()(std::vector&& input) { - std::vector transformed(input.size()); - - std::transform( - std::make_move_iterator(input.begin()), - std::make_move_iterator(input.end()), - transformed.begin(), - [](T&& datum) { return TElement(std::move(datum)); } + Collection operator()(TContainer&& input) { + std::vector elements; + // There's no batch emplace method, so we need to reserve and then emplace manually. + // We decide here to take the performance cost if a the input's iterator is not a random access iterator. + // (in that case determining the size will have linear complexity) + elements.reserve(static_cast(std::distance(std::begin(input), std::end(input))) ); + for (auto& element : input) { + elements.emplace_back(std::move(element)); + } - return Collection::take_ownership(std::move(transformed)); + return Collection::take_ownership(std::move(elements)); } }; - /// Adapter from std::array of components. + /// Adapter from std::array of elements with the target type. /// - /// Only takes ownership if a temporary is passed. + /// Only takes ownership if a temporary is passed in which case an allocation and per element move is performed. template struct CollectionAdapter> { Collection operator()(const std::array& array) { @@ -61,16 +71,17 @@ namespace rerun { } Collection operator()(std::array&& array) { - return Collection::take_ownership( - std::vector(array.begin(), array.end()) + std::vector elements( + std::make_move_iterator(array.begin()), + std::make_move_iterator(array.end()) ); + return Collection::take_ownership(std::move(elements)); } }; - /// Adapter from a C-Array reference. + /// Adapter from a C-Array reference with the target type. /// - /// *Attention*: Does *not* take ownership of the data, - /// you need to ensure that the data outlives the component batch. + /// Only takes ownership if a temporary is passed in which case an allocation and per element move is performed. template struct CollectionAdapter { Collection operator()(const TElement (&array)[NumInstances]) { @@ -78,18 +89,18 @@ namespace rerun { } Collection operator()(TElement (&&array)[NumInstances]) { - std::vector components; - components.reserve(NumInstances); - components.insert( - components.end(), + std::vector elements( std::make_move_iterator(array), std::make_move_iterator(array + NumInstances) ); - return Collection::take_ownership(std::move(components)); + return Collection::take_ownership(std::move(elements)); } }; - /// Adapter for a single component, temporary or reference. + /// Adapter for a single element from which `TElement`, temporary or reference. + /// + /// Only takes ownership if a temporary is passed in which case the element is moved. + /// Otherwise a borrow takes place. template struct CollectionAdapter { Collection operator()(const TElement& one_and_only) { @@ -100,6 +111,28 @@ namespace rerun { return Collection::take_ownership(std::move(one_and_only)); } }; + + /// Adapter for a single element of from which `TElement` can be constructed. + /// + /// Since this needs to do a conversion, this will always need to allocate space. + /// However, if a temporary is passed the element will be moved instead of copied upon construction of `TElement`. + template + struct CollectionAdapter< + TElement, TInput, + std::enable_if_t< + !std::is_same_v && // + !traits::is_iterable_v && // + std::is_constructible_v // + >> { + Collection operator()(const TInput& input) { + return Collection::take_ownership(TElement(input)); + } + + Collection operator()(TInput&& input) { + return Collection::take_ownership(TElement(std::move(input))); + } + }; + } // namespace rerun /// \endcond diff --git a/rerun_cpp/src/rerun/compiler_utils.hpp b/rerun_cpp/src/rerun/compiler_utils.hpp new file mode 100644 index 000000000000..a9d96e8cd450 --- /dev/null +++ b/rerun_cpp/src/rerun/compiler_utils.hpp @@ -0,0 +1,34 @@ +#pragma once + +// Macro for enabling and disabling the "-Wmaybe-uninitialized" warning in GCC. +// See: https://github.com/rerun-io/rerun/issues/4027 + +#define RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(expr) \ + RERUN_DISABLE_MAYBE_UNINITIALIZED_PUSH \ + expr RERUN_DISABLE_MAYBE_UNINITIALIZED_POP + +#if defined(__GNUC__) && !defined(__clang__) +#define RERUN_DISABLE_MAYBE_UNINITIALIZED_PUSH \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#else +#define RERUN_DISABLE_MAYBE_UNINITIALIZED_PUSH +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#define RERUN_DISABLE_MAYBE_UNINITIALIZED_POP _Pragma("GCC diagnostic pop") +#else +#define RERUN_DISABLE_MAYBE_UNINITIALIZED_POP +#endif + +// Macro for marking code as unreachable. +// Reaching the code after all is undefined behavior. + +#if defined(__GNUC__) || defined(__clang__) +#define RERUN_UNREACHABLE() __builtin_unreachable() +#elif defined(_MSC_VER) +#define RERUN_UNREACHABLE() __assume(false) +#else +#define RERUN_UNREACHABLE() \ + do { \ + } while (false) +#endif diff --git a/rerun_cpp/src/rerun/components/annotation_context.hpp b/rerun_cpp/src/rerun/components/annotation_context.hpp index cfdab680cb03..8cf1eead12f6 100644 --- a/rerun_cpp/src/rerun/components/annotation_context.hpp +++ b/rerun_cpp/src/rerun/components/annotation_context.hpp @@ -3,14 +3,15 @@ #pragma once +#include "../collection.hpp" #include "../data_cell.hpp" #include "../datatypes/class_description_map_elem.hpp" #include "../result.hpp" #include #include +#include #include -#include namespace arrow { class DataType; @@ -28,7 +29,7 @@ namespace rerun::components { /// path. struct AnnotationContext { /// List of class descriptions, mapping class indices to class names, colors etc. - std::vector class_map; + rerun::Collection class_map; /// Name of the component, used for serialization. static const char NAME[]; @@ -36,23 +37,38 @@ namespace rerun::components { public: // Extensions to generated type defined in 'annotation_context_ext.cpp' - AnnotationContext( - std::initializer_list class_descriptions - ) { - class_map.reserve(class_descriptions.size()); + /// Construct from an initializer list of elements from which `rerun::datatypes::ClassDescriptionMapElem`s can be constructed. + /// + /// This will then create a new collection of `rerun::datatypes::ClassDescriptionMapElem`. + /// + /// _Implementation note_: + /// We handle this type of conversion in a generic `rerun::ContainerAdapter`. + /// However, it is *still* necessary since initializer list overload resolution is handled + /// in a special way by the compiler, making this case not being covered by the general container case. + template < + typename TElement, // + typename = std::enable_if_t< + std::is_constructible_v> // + > + AnnotationContext(std::initializer_list class_descriptions) { + std::vector class_map_new; + class_map_new.reserve(class_descriptions.size()); for (const auto& class_description : class_descriptions) { - class_map.emplace_back(std::move(class_description)); + class_map_new.emplace_back(std::move(class_description)); } + class_map = Collection::take_ownership( + std::move(class_map_new) + ); } public: AnnotationContext() = default; - AnnotationContext(std::vector class_map_) + AnnotationContext(rerun::Collection class_map_) : class_map(std::move(class_map_)) {} AnnotationContext& operator=( - std::vector class_map_ + rerun::Collection class_map_ ) { class_map = std::move(class_map_); return *this; diff --git a/rerun_cpp/src/rerun/components/annotation_context_ext.cpp b/rerun_cpp/src/rerun/components/annotation_context_ext.cpp index 0f5919e1d515..52b8a3efae47 100644 --- a/rerun_cpp/src/rerun/components/annotation_context_ext.cpp +++ b/rerun_cpp/src/rerun/components/annotation_context_ext.cpp @@ -1,31 +1,42 @@ #include #include "annotation_context.hpp" -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION - -namespace rerun { - namespace components { -#ifdef EDIT_EXTENSION - struct AnnotationContextExt { - std::vector class_map; - -#define AnnotationContext AnnotationContextExt - - // - - AnnotationContext( - std::initializer_list class_descriptions - ) { - class_map.reserve(class_descriptions.size()); - for (const auto& class_description : class_descriptions) { - class_map.emplace_back(std::move(class_description)); - } - } - - // - }; +// + +#include // std::is_convertible_v + +// + +namespace rerun::components { + +#if 0 + // + + /// Construct from an initializer list of elements from which `rerun::datatypes::ClassDescriptionMapElem`s can be constructed. + /// + /// This will then create a new collection of `rerun::datatypes::ClassDescriptionMapElem`. + /// + /// _Implementation note_: + /// We handle this type of conversion in a generic `rerun::ContainerAdapter`. + /// However, it is *still* necessary since initializer list overload resolution is handled + /// in a special way by the compiler, making this case not being covered by the general container case. + template < + typename TElement, // + typename = std::enable_if_t< + std::is_constructible_v> // + > + AnnotationContext(std::initializer_list class_descriptions) { + std::vector class_map_new; + class_map_new.reserve(class_descriptions.size()); + for (const auto& class_description : class_descriptions) { + class_map_new.emplace_back(std::move(class_description)); + } + class_map = Collection::take_ownership( + std::move(class_map_new) + ); + } + + // #endif - } // namespace components -} // namespace rerun +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/blob.hpp b/rerun_cpp/src/rerun/components/blob.hpp index d942ea2694c1..a44edb048fd2 100644 --- a/rerun_cpp/src/rerun/components/blob.hpp +++ b/rerun_cpp/src/rerun/components/blob.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../data_cell.hpp" #include "../result.hpp" #include #include #include -#include namespace arrow { class DataType; @@ -20,7 +20,7 @@ namespace arrow { namespace rerun::components { /// **Component**: A binary blob of data. struct Blob { - std::vector data; + rerun::Collection data; /// Name of the component, used for serialization. static const char NAME[]; @@ -28,9 +28,9 @@ namespace rerun::components { public: Blob() = default; - Blob(std::vector data_) : data(std::move(data_)) {} + Blob(rerun::Collection data_) : data(std::move(data_)) {} - Blob& operator=(std::vector data_) { + Blob& operator=(rerun::Collection data_) { data = std::move(data_); return *this; } diff --git a/rerun_cpp/src/rerun/components/line_strip2d.hpp b/rerun_cpp/src/rerun/components/line_strip2d.hpp index 5b5f9677b390..663db5eb73f9 100644 --- a/rerun_cpp/src/rerun/components/line_strip2d.hpp +++ b/rerun_cpp/src/rerun/components/line_strip2d.hpp @@ -3,15 +3,14 @@ #pragma once +#include "../collection.hpp" #include "../data_cell.hpp" #include "../datatypes/vec2d.hpp" #include "../result.hpp" -#include #include #include #include -#include namespace arrow { class DataType; @@ -33,27 +32,18 @@ namespace rerun::components { /// 4 /// ``` struct LineStrip2D { - std::vector points; + rerun::Collection points; /// Name of the component, used for serialization. static const char NAME[]; - public: - // Extensions to generated type defined in 'line_strip2d_ext.cpp' - - template - LineStrip2D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec2D(pt); - }); - } - public: LineStrip2D() = default; - LineStrip2D(std::vector points_) : points(std::move(points_)) {} + LineStrip2D(rerun::Collection points_) + : points(std::move(points_)) {} - LineStrip2D& operator=(std::vector points_) { + LineStrip2D& operator=(rerun::Collection points_) { points = std::move(points_); return *this; } diff --git a/rerun_cpp/src/rerun/components/line_strip2d_ext.cpp b/rerun_cpp/src/rerun/components/line_strip2d_ext.cpp deleted file mode 100644 index d0c083cd9648..000000000000 --- a/rerun_cpp/src/rerun/components/line_strip2d_ext.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "line_strip2d.hpp" - -// -#include - -// - -namespace rerun { - namespace components { - -#if 0 - // - - template - LineStrip2D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec2D(pt); - }); - } - - // -#endif - } // namespace components -} // namespace rerun diff --git a/rerun_cpp/src/rerun/components/line_strip3d.hpp b/rerun_cpp/src/rerun/components/line_strip3d.hpp index 1f897cc2e19a..defbf3269217 100644 --- a/rerun_cpp/src/rerun/components/line_strip3d.hpp +++ b/rerun_cpp/src/rerun/components/line_strip3d.hpp @@ -3,15 +3,14 @@ #pragma once +#include "../collection.hpp" #include "../data_cell.hpp" #include "../datatypes/vec3d.hpp" #include "../result.hpp" -#include #include #include #include -#include namespace arrow { class DataType; @@ -33,27 +32,18 @@ namespace rerun::components { /// 4 /// ``` struct LineStrip3D { - std::vector points; + rerun::Collection points; /// Name of the component, used for serialization. static const char NAME[]; - public: - // Extensions to generated type defined in 'line_strip3d_ext.cpp' - - template - LineStrip3D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec3D(pt); - }); - } - public: LineStrip3D() = default; - LineStrip3D(std::vector points_) : points(std::move(points_)) {} + LineStrip3D(rerun::Collection points_) + : points(std::move(points_)) {} - LineStrip3D& operator=(std::vector points_) { + LineStrip3D& operator=(rerun::Collection points_) { points = std::move(points_); return *this; } diff --git a/rerun_cpp/src/rerun/components/line_strip3d_ext.cpp b/rerun_cpp/src/rerun/components/line_strip3d_ext.cpp deleted file mode 100644 index be6c6cc4ebfb..000000000000 --- a/rerun_cpp/src/rerun/components/line_strip3d_ext.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "line_strip3d.hpp" - -// -#include - -// - -namespace rerun { - namespace components { - -#if 0 - // - - template - LineStrip3D(const std::vector& points_) : points(points_.size()) { - std::transform(points_.begin(), points_.end(), points.begin(), [](const T& pt) { - return rerun::datatypes::Vec3D(pt); - }); - } - - // -#endif - } // namespace components -} // namespace rerun diff --git a/rerun_cpp/src/rerun/components/mesh_properties.hpp b/rerun_cpp/src/rerun/components/mesh_properties.hpp index d3ced1e69203..30898fd335dc 100644 --- a/rerun_cpp/src/rerun/components/mesh_properties.hpp +++ b/rerun_cpp/src/rerun/components/mesh_properties.hpp @@ -3,6 +3,7 @@ #pragma once +#include "../collection.hpp" #include "../data_cell.hpp" #include "../datatypes/mesh_properties.hpp" #include "../result.hpp" @@ -11,7 +12,6 @@ #include #include #include -#include namespace arrow { class DataType; @@ -30,8 +30,8 @@ namespace rerun::components { public: // Extensions to generated type defined in 'mesh_properties_ext.cpp' - static MeshProperties from_triangle_indices(std::vector indices) { - return MeshProperties(indices); + static MeshProperties from_triangle_indices(Collection indices) { + return MeshProperties(std::move(indices)); } public: @@ -44,10 +44,10 @@ namespace rerun::components { return *this; } - MeshProperties(std::optional> indices_) + MeshProperties(std::optional> indices_) : props(std::move(indices_)) {} - MeshProperties& operator=(std::optional> indices_) { + MeshProperties& operator=(std::optional> indices_) { props = std::move(indices_); return *this; } diff --git a/rerun_cpp/src/rerun/components/mesh_properties_ext.cpp b/rerun_cpp/src/rerun/components/mesh_properties_ext.cpp index efbce521831b..24624036fb4e 100644 --- a/rerun_cpp/src/rerun/components/mesh_properties_ext.cpp +++ b/rerun_cpp/src/rerun/components/mesh_properties_ext.cpp @@ -1,23 +1,13 @@ #include "mesh_properties.hpp" -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION +namespace rerun::components { +#if 0 + // -namespace rerun { - namespace components { + static MeshProperties from_triangle_indices(Collection indices) { + return MeshProperties(std::move(indices)); + } -#ifdef EDIT_EXTENSION - struct MeshPropertiesExt { -#define MeshProperties MeshPropertiesExt - - // - - static MeshProperties from_triangle_indices(std::vector indices) { - return MeshProperties(indices); - } - - // - }; + // #endif - } // namespace components -} // namespace rerun +} // namespace rerun::components diff --git a/rerun_cpp/src/rerun/components/tensor_data.hpp b/rerun_cpp/src/rerun/components/tensor_data.hpp index 9b7138b96ba8..4e67cc22643d 100644 --- a/rerun_cpp/src/rerun/components/tensor_data.hpp +++ b/rerun_cpp/src/rerun/components/tensor_data.hpp @@ -30,7 +30,7 @@ namespace rerun::components { /// New Tensor from dimensions and tensor buffer. TensorData( - std::vector shape, + rerun::Collection shape, rerun::datatypes::TensorBuffer buffer ) : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} diff --git a/rerun_cpp/src/rerun/components/tensor_data_ext.cpp b/rerun_cpp/src/rerun/components/tensor_data_ext.cpp index 32752af109ea..9e024db18f51 100644 --- a/rerun_cpp/src/rerun/components/tensor_data_ext.cpp +++ b/rerun_cpp/src/rerun/components/tensor_data_ext.cpp @@ -14,7 +14,7 @@ namespace rerun { /// New Tensor from dimensions and tensor buffer. TensorData( - std::vector shape, + rerun::Collection shape, rerun::datatypes::TensorBuffer buffer ) : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {} diff --git a/rerun_cpp/src/rerun/datatypes/class_description.hpp b/rerun_cpp/src/rerun/datatypes/class_description.hpp index 84fc643b12fc..769d6ec67170 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description.hpp +++ b/rerun_cpp/src/rerun/datatypes/class_description.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include "annotation_info.hpp" #include "keypoint_pair.hpp" #include #include -#include namespace arrow { class DataType; @@ -37,21 +37,28 @@ namespace rerun::datatypes { rerun::datatypes::AnnotationInfo info; /// The `AnnotationInfo` for all of the keypoints. - std::vector keypoint_annotations; + rerun::Collection keypoint_annotations; /// The connections between keypoints. - std::vector keypoint_connections; + rerun::Collection keypoint_connections; public: // Extensions to generated type defined in 'class_description_ext.cpp' + /// Create a new `ClassDescription` from a single annotation info. ClassDescription( - AnnotationInfo _info, std::vector _keypoint_annotations = {}, - std::vector _keypoint_connections = {} + uint16_t id, std::optional label = std::nullopt, + std::optional color = std::nullopt ) - : info(std::move(_info)), - keypoint_annotations(std::move(_keypoint_annotations)), - keypoint_connections(std::move(_keypoint_connections)) {} + : info(id, label, color) {} + + ClassDescription( + AnnotationInfo info_, Collection keypoint_annotations_ = {}, + Collection keypoint_connections_ = {} + ) + : info(std::move(info_)), + keypoint_annotations(std::move(keypoint_annotations_)), + keypoint_connections(std::move(keypoint_connections_)) {} public: ClassDescription() = default; diff --git a/rerun_cpp/src/rerun/datatypes/class_description_ext.cpp b/rerun_cpp/src/rerun/datatypes/class_description_ext.cpp index 22f7dfd314f1..e94ba8082a13 100644 --- a/rerun_cpp/src/rerun/datatypes/class_description_ext.cpp +++ b/rerun_cpp/src/rerun/datatypes/class_description_ext.cpp @@ -1,32 +1,26 @@ #include "class_description.hpp" -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION - -namespace rerun { - namespace datatypes { - -#ifdef EDIT_EXTENSION - struct ClassDescriptionExt { - AnnotationInfo info; - std::vector keypoint_annotations; - std::vector keypoint_connections; - -#define ClassDescription ClassDescriptionExt - - // - - ClassDescription( - AnnotationInfo _info, std::vector _keypoint_annotations = {}, - std::vector _keypoint_connections = {} - ) - : info(std::move(_info)), - keypoint_annotations(std::move(_keypoint_annotations)), - keypoint_connections(std::move(_keypoint_connections)) {} - - // - }; +namespace rerun::datatypes { + +#if 0 + // + + /// Create a new `ClassDescription` from a single annotation info. + ClassDescription( + uint16_t id, std::optional label = std::nullopt, + std::optional color = std::nullopt + ) + : info(id, label, color) {} + + ClassDescription( + AnnotationInfo info_, Collection keypoint_annotations_ = {}, + Collection keypoint_connections_ = {} + ) + : info(std::move(info_)), + keypoint_annotations(std::move(keypoint_annotations_)), + keypoint_connections(std::move(keypoint_connections_)) {} + + // #endif - } // namespace datatypes -} // namespace rerun +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp b/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp index b37a84bf2d90..1f55fa798441 100644 --- a/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp +++ b/rerun_cpp/src/rerun/datatypes/mesh_properties.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include #include #include #include -#include namespace arrow { class DataType; @@ -23,15 +23,15 @@ namespace rerun::datatypes { /// A flattened array of vertex indices that describe the mesh's triangles. /// /// Its length must be divisible by 3. - std::optional> indices; + std::optional> indices; public: MeshProperties() = default; - MeshProperties(std::optional> indices_) + MeshProperties(std::optional> indices_) : indices(std::move(indices_)) {} - MeshProperties& operator=(std::optional> indices_) { + MeshProperties& operator=(std::optional> indices_) { indices = std::move(indices_); return *this; } diff --git a/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp b/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp index 1211db72c494..d2e2bc76f0cf 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_buffer.hpp @@ -3,15 +3,16 @@ #pragma once +#include "../collection.hpp" #include "../half.hpp" #include "../result.hpp" +#include "../type_traits.hpp" #include #include #include #include #include -#include namespace arrow { class DataType; @@ -42,31 +43,31 @@ namespace rerun::datatypes { /// \private union TensorBufferData { - std::vector u8; + rerun::Collection u8; - std::vector u16; + rerun::Collection u16; - std::vector u32; + rerun::Collection u32; - std::vector u64; + rerun::Collection u64; - std::vector i8; + rerun::Collection i8; - std::vector i16; + rerun::Collection i16; - std::vector i32; + rerun::Collection i32; - std::vector i64; + rerun::Collection i64; - std::vector f16; + rerun::Collection f16; - std::vector f32; + rerun::Collection f32; - std::vector f64; + rerun::Collection f64; - std::vector jpeg; + rerun::Collection jpeg; - std::vector nv12; + rerun::Collection nv12; TensorBufferData() { std::memset(reinterpret_cast(this), 0, sizeof(TensorBufferData)); @@ -96,55 +97,55 @@ namespace rerun::datatypes { TensorBuffer(const TensorBuffer& other) : _tag(other._tag) { switch (other._tag) { case detail::TensorBufferTag::U8: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.u8) TypeAlias(other._data.u8); } break; case detail::TensorBufferTag::U16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.u16) TypeAlias(other._data.u16); } break; case detail::TensorBufferTag::U32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.u32) TypeAlias(other._data.u32); } break; case detail::TensorBufferTag::U64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.u64) TypeAlias(other._data.u64); } break; case detail::TensorBufferTag::I8: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.i8) TypeAlias(other._data.i8); } break; case detail::TensorBufferTag::I16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.i16) TypeAlias(other._data.i16); } break; case detail::TensorBufferTag::I32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.i32) TypeAlias(other._data.i32); } break; case detail::TensorBufferTag::I64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.i64) TypeAlias(other._data.i64); } break; case detail::TensorBufferTag::F16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.f16) TypeAlias(other._data.f16); } break; case detail::TensorBufferTag::F32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.f32) TypeAlias(other._data.f32); } break; case detail::TensorBufferTag::F64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.f64) TypeAlias(other._data.f64); } break; case detail::TensorBufferTag::JPEG: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.jpeg) TypeAlias(other._data.jpeg); } break; case detail::TensorBufferTag::NV12: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.nv12) TypeAlias(other._data.nv12); } break; case detail::TensorBufferTag::None: { @@ -173,55 +174,55 @@ namespace rerun::datatypes { // Nothing to destroy } break; case detail::TensorBufferTag::U8: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.u8.~TypeAlias(); } break; case detail::TensorBufferTag::U16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.u16.~TypeAlias(); } break; case detail::TensorBufferTag::U32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.u32.~TypeAlias(); } break; case detail::TensorBufferTag::U64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.u64.~TypeAlias(); } break; case detail::TensorBufferTag::I8: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.i8.~TypeAlias(); } break; case detail::TensorBufferTag::I16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.i16.~TypeAlias(); } break; case detail::TensorBufferTag::I32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.i32.~TypeAlias(); } break; case detail::TensorBufferTag::I64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.i64.~TypeAlias(); } break; case detail::TensorBufferTag::F16: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.f16.~TypeAlias(); } break; case detail::TensorBufferTag::F32: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.f32.~TypeAlias(); } break; case detail::TensorBufferTag::F64: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.f64.~TypeAlias(); } break; case detail::TensorBufferTag::JPEG: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.jpeg.~TypeAlias(); } break; case detail::TensorBufferTag::NV12: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.nv12.~TypeAlias(); } break; } @@ -230,41 +231,49 @@ namespace rerun::datatypes { public: // Extensions to generated type defined in 'tensor_buffer_ext.cpp' - // TODO(#3794): don't use std::vector here + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u16) : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u16) : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u32) : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u32) : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u64) : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u64) : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i16) : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i16) : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i32) : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i32) : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i64) : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i64) : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} - - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f16) + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f16) : TensorBuffer(TensorBuffer::f16(std::move(f16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f32) : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f32) : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} + + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f64) : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f64) : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} + /// Construct a `TensorBuffer` from any container type that has a `value_type` member and for which a + /// `rerun::ContainerAdapter` exists. + /// + /// This constructor assumes the type of tensor buffer you want to use is defined by `TContainer::value_type` + /// and then forwards the argument as-is to the appropriate `rerun::Container` constructor. + /// \see rerun::ContainerAdapter, rerun::Container + template > + TensorBuffer(TContainer&& container) + : TensorBuffer(Collection(std::forward(container))) {} /// Number of elements in the buffer. /// @@ -276,99 +285,99 @@ namespace rerun::datatypes { this->_data.swap(other._data); } - static TensorBuffer u8(std::vector u8) { + static TensorBuffer u8(rerun::Collection u8) { TensorBuffer self; self._tag = detail::TensorBufferTag::U8; - new (&self._data.u8) std::vector(std::move(u8)); + new (&self._data.u8) rerun::Collection(std::move(u8)); return self; } - static TensorBuffer u16(std::vector u16) { + static TensorBuffer u16(rerun::Collection u16) { TensorBuffer self; self._tag = detail::TensorBufferTag::U16; - new (&self._data.u16) std::vector(std::move(u16)); + new (&self._data.u16) rerun::Collection(std::move(u16)); return self; } - static TensorBuffer u32(std::vector u32) { + static TensorBuffer u32(rerun::Collection u32) { TensorBuffer self; self._tag = detail::TensorBufferTag::U32; - new (&self._data.u32) std::vector(std::move(u32)); + new (&self._data.u32) rerun::Collection(std::move(u32)); return self; } - static TensorBuffer u64(std::vector u64) { + static TensorBuffer u64(rerun::Collection u64) { TensorBuffer self; self._tag = detail::TensorBufferTag::U64; - new (&self._data.u64) std::vector(std::move(u64)); + new (&self._data.u64) rerun::Collection(std::move(u64)); return self; } - static TensorBuffer i8(std::vector i8) { + static TensorBuffer i8(rerun::Collection i8) { TensorBuffer self; self._tag = detail::TensorBufferTag::I8; - new (&self._data.i8) std::vector(std::move(i8)); + new (&self._data.i8) rerun::Collection(std::move(i8)); return self; } - static TensorBuffer i16(std::vector i16) { + static TensorBuffer i16(rerun::Collection i16) { TensorBuffer self; self._tag = detail::TensorBufferTag::I16; - new (&self._data.i16) std::vector(std::move(i16)); + new (&self._data.i16) rerun::Collection(std::move(i16)); return self; } - static TensorBuffer i32(std::vector i32) { + static TensorBuffer i32(rerun::Collection i32) { TensorBuffer self; self._tag = detail::TensorBufferTag::I32; - new (&self._data.i32) std::vector(std::move(i32)); + new (&self._data.i32) rerun::Collection(std::move(i32)); return self; } - static TensorBuffer i64(std::vector i64) { + static TensorBuffer i64(rerun::Collection i64) { TensorBuffer self; self._tag = detail::TensorBufferTag::I64; - new (&self._data.i64) std::vector(std::move(i64)); + new (&self._data.i64) rerun::Collection(std::move(i64)); return self; } - static TensorBuffer f16(std::vector f16) { + static TensorBuffer f16(rerun::Collection f16) { TensorBuffer self; self._tag = detail::TensorBufferTag::F16; - new (&self._data.f16) std::vector(std::move(f16)); + new (&self._data.f16) rerun::Collection(std::move(f16)); return self; } - static TensorBuffer f32(std::vector f32) { + static TensorBuffer f32(rerun::Collection f32) { TensorBuffer self; self._tag = detail::TensorBufferTag::F32; - new (&self._data.f32) std::vector(std::move(f32)); + new (&self._data.f32) rerun::Collection(std::move(f32)); return self; } - static TensorBuffer f64(std::vector f64) { + static TensorBuffer f64(rerun::Collection f64) { TensorBuffer self; self._tag = detail::TensorBufferTag::F64; - new (&self._data.f64) std::vector(std::move(f64)); + new (&self._data.f64) rerun::Collection(std::move(f64)); return self; } - static TensorBuffer jpeg(std::vector jpeg) { + static TensorBuffer jpeg(rerun::Collection jpeg) { TensorBuffer self; self._tag = detail::TensorBufferTag::JPEG; - new (&self._data.jpeg) std::vector(std::move(jpeg)); + new (&self._data.jpeg) rerun::Collection(std::move(jpeg)); return self; } - static TensorBuffer nv12(std::vector nv12) { + static TensorBuffer nv12(rerun::Collection nv12) { TensorBuffer self; self._tag = detail::TensorBufferTag::NV12; - new (&self._data.nv12) std::vector(std::move(nv12)); + new (&self._data.nv12) rerun::Collection(std::move(nv12)); return self; } /// Return a pointer to u8 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u8() const { + const rerun::Collection* get_u8() const { if (_tag == detail::TensorBufferTag::U8) { return &_data.u8; } else { @@ -377,7 +386,7 @@ namespace rerun::datatypes { } /// Return a pointer to u16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u16() const { + const rerun::Collection* get_u16() const { if (_tag == detail::TensorBufferTag::U16) { return &_data.u16; } else { @@ -386,7 +395,7 @@ namespace rerun::datatypes { } /// Return a pointer to u32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u32() const { + const rerun::Collection* get_u32() const { if (_tag == detail::TensorBufferTag::U32) { return &_data.u32; } else { @@ -395,7 +404,7 @@ namespace rerun::datatypes { } /// Return a pointer to u64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_u64() const { + const rerun::Collection* get_u64() const { if (_tag == detail::TensorBufferTag::U64) { return &_data.u64; } else { @@ -404,7 +413,7 @@ namespace rerun::datatypes { } /// Return a pointer to i8 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i8() const { + const rerun::Collection* get_i8() const { if (_tag == detail::TensorBufferTag::I8) { return &_data.i8; } else { @@ -413,7 +422,7 @@ namespace rerun::datatypes { } /// Return a pointer to i16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i16() const { + const rerun::Collection* get_i16() const { if (_tag == detail::TensorBufferTag::I16) { return &_data.i16; } else { @@ -422,7 +431,7 @@ namespace rerun::datatypes { } /// Return a pointer to i32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i32() const { + const rerun::Collection* get_i32() const { if (_tag == detail::TensorBufferTag::I32) { return &_data.i32; } else { @@ -431,7 +440,7 @@ namespace rerun::datatypes { } /// Return a pointer to i64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_i64() const { + const rerun::Collection* get_i64() const { if (_tag == detail::TensorBufferTag::I64) { return &_data.i64; } else { @@ -440,7 +449,7 @@ namespace rerun::datatypes { } /// Return a pointer to f16 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f16() const { + const rerun::Collection* get_f16() const { if (_tag == detail::TensorBufferTag::F16) { return &_data.f16; } else { @@ -449,7 +458,7 @@ namespace rerun::datatypes { } /// Return a pointer to f32 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f32() const { + const rerun::Collection* get_f32() const { if (_tag == detail::TensorBufferTag::F32) { return &_data.f32; } else { @@ -458,7 +467,7 @@ namespace rerun::datatypes { } /// Return a pointer to f64 if the union is in that state, otherwise `nullptr`. - const std::vector* get_f64() const { + const rerun::Collection* get_f64() const { if (_tag == detail::TensorBufferTag::F64) { return &_data.f64; } else { @@ -467,7 +476,7 @@ namespace rerun::datatypes { } /// Return a pointer to jpeg if the union is in that state, otherwise `nullptr`. - const std::vector* get_jpeg() const { + const rerun::Collection* get_jpeg() const { if (_tag == detail::TensorBufferTag::JPEG) { return &_data.jpeg; } else { @@ -476,7 +485,7 @@ namespace rerun::datatypes { } /// Return a pointer to nv12 if the union is in that state, otherwise `nullptr`. - const std::vector* get_nv12() const { + const rerun::Collection* get_nv12() const { if (_tag == detail::TensorBufferTag::NV12) { return &_data.nv12; } else { diff --git a/rerun_cpp/src/rerun/datatypes/tensor_buffer_ext.cpp b/rerun_cpp/src/rerun/datatypes/tensor_buffer_ext.cpp index ca8e74887739..651d7b82139e 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_buffer_ext.cpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_buffer_ext.cpp @@ -3,126 +3,124 @@ #include -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION +// -namespace rerun { - namespace datatypes { +#include "../type_traits.hpp" -#ifdef EDIT_EXTENSION - struct TensorBufferExt { -#define TensorBuffer TensorBufferExt +// - // +namespace rerun::datatypes { - // TODO(#3794): don't use std::vector here +#if 0 + // - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u8) : TensorBuffer(TensorBuffer::u8(std::move(u8))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u16) - : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u16) + : TensorBuffer(TensorBuffer::u16(std::move(u16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u32) - : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u32) + : TensorBuffer(TensorBuffer::u32(std::move(u32))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector u64) - : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection u64) + : TensorBuffer(TensorBuffer::u64(std::move(u64))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i8) : TensorBuffer(TensorBuffer::i8(std::move(i8))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i16) - : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i16) + : TensorBuffer(TensorBuffer::i16(std::move(i16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i32) - : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i32) + : TensorBuffer(TensorBuffer::i32(std::move(i32))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector i64) - : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection i64) + : TensorBuffer(TensorBuffer::i64(std::move(i64))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f16) - : TensorBuffer(TensorBuffer::f16(std::move(f16))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f16) + : TensorBuffer(TensorBuffer::f16(std::move(f16))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f32) - : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f32) : TensorBuffer(TensorBuffer::f32(std::move(f32))) {} - /// Construct a `TensorBuffer` from a `std::vector`. - TensorBuffer(std::vector f64) - : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} + /// Construct a `TensorBuffer` from a `Collection`. + TensorBuffer(Collection f64) + : TensorBuffer(TensorBuffer::f64(std::move(f64))) {} - /// Number of elements in the buffer. - /// - /// You may NOT call this for JPEG buffers. - size_t num_elems() const; + /// Construct a `TensorBuffer` from any container type that has a `value_type` member and for which a + /// `rerun::ContainerAdapter` exists. + /// + /// This constructor assumes the type of tensor buffer you want to use is defined by `TContainer::value_type` + /// and then forwards the argument as-is to the appropriate `rerun::Container` constructor. + /// \see rerun::ContainerAdapter, rerun::Container + template > + TensorBuffer(TContainer&& container) + : TensorBuffer(Collection(std::forward(container))) {} - // - }; + /// Number of elements in the buffer. + /// + /// You may NOT call this for JPEG buffers. + size_t num_elems() const; -#undef TensorBuffer -#else -#define TensorBufferExt TensorBuffer + // #endif - /// Number of elements in the buffer. - size_t TensorBufferExt::num_elems() const { - switch (this->_tag) { - case detail::TensorBufferTag::None: { - return 0; - } - case detail::TensorBufferTag::U8: { - return _data.u8.size(); - } - case detail::TensorBufferTag::U16: { - return _data.u16.size(); - } - case detail::TensorBufferTag::U32: { - return _data.u32.size(); - } - case detail::TensorBufferTag::U64: { - return _data.u64.size(); - } - case detail::TensorBufferTag::I8: { - return _data.i8.size(); - } - case detail::TensorBufferTag::I16: { - return _data.i16.size(); - } - case detail::TensorBufferTag::I32: { - return _data.i32.size(); - } - case detail::TensorBufferTag::I64: { - return _data.i64.size(); - } - case detail::TensorBufferTag::F16: { - return _data.f16.size(); - } - case detail::TensorBufferTag::F32: { - return _data.f32.size(); - } - case detail::TensorBufferTag::F64: { - return _data.f64.size(); - } - case detail::TensorBufferTag::NV12: { - assert( - false && "Can't ask for the number of elements in an NV12 encoded image" - ); - } - case detail::TensorBufferTag::JPEG: { - assert(false && "Can't ask for the number of elements in a JPEG"); - } + /// Number of elements in the buffer. + size_t TensorBuffer::num_elems() const { + switch (this->_tag) { + case detail::TensorBufferTag::None: { + return 0; + } + case detail::TensorBufferTag::U8: { + return _data.u8.size(); + } + case detail::TensorBufferTag::U16: { + return _data.u16.size(); + } + case detail::TensorBufferTag::U32: { + return _data.u32.size(); + } + case detail::TensorBufferTag::U64: { + return _data.u64.size(); + } + case detail::TensorBufferTag::I8: { + return _data.i8.size(); + } + case detail::TensorBufferTag::I16: { + return _data.i16.size(); + } + case detail::TensorBufferTag::I32: { + return _data.i32.size(); + } + case detail::TensorBufferTag::I64: { + return _data.i64.size(); + } + case detail::TensorBufferTag::F16: { + return _data.f16.size(); + } + case detail::TensorBufferTag::F32: { + return _data.f32.size(); + } + case detail::TensorBufferTag::F64: { + return _data.f64.size(); + } + case detail::TensorBufferTag::NV12: { + assert(false && "Can't ask for the number of elements in an NV12 encoded image"); + } + case detail::TensorBufferTag::JPEG: { + assert(false && "Can't ask for the number of elements in a JPEG"); } - assert(false && "Unknown TensorBuffer tag"); - return 0; } + assert(false && "Unknown TensorBuffer tag"); + return 0; + } - } // namespace datatypes -} // namespace rerun +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/tensor_data.hpp b/rerun_cpp/src/rerun/datatypes/tensor_data.hpp index 89ea0b8cbf44..3af839759244 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_data.hpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_data.hpp @@ -3,13 +3,13 @@ #pragma once +#include "../collection.hpp" #include "../result.hpp" #include "tensor_buffer.hpp" #include "tensor_dimension.hpp" #include #include -#include namespace arrow { class DataType; @@ -27,17 +27,15 @@ namespace rerun::datatypes { /// These dimensions are combined with an index to look up values from the `buffer` field, /// which stores a contiguous array of typed values. struct TensorData { - std::vector shape; + rerun::Collection shape; rerun::datatypes::TensorBuffer buffer; public: // Extensions to generated type defined in 'tensor_data_ext.cpp' - // TODO(#3794): There should be the option to not have TensorData take ownership of the buffer. TensorData( - std::vector shape_, - rerun::datatypes::TensorBuffer buffer_ + Collection shape_, datatypes::TensorBuffer buffer_ ) : shape(std::move(shape_)), buffer(std::move(buffer_)) {} diff --git a/rerun_cpp/src/rerun/datatypes/tensor_data_ext.cpp b/rerun_cpp/src/rerun/datatypes/tensor_data_ext.cpp index 3daafad4fbf9..ba0eb7fe1ab3 100644 --- a/rerun_cpp/src/rerun/datatypes/tensor_data_ext.cpp +++ b/rerun_cpp/src/rerun/datatypes/tensor_data_ext.cpp @@ -1,24 +1,15 @@ #include "tensor_data.hpp" -// Uncomment for better auto-complete while editing the extension. -//#define EDIT_EXTENSION +namespace rerun::datatypes { -namespace rerun { - namespace datatypes { +#if 0 + // -#ifdef EDIT_EXTENSION -#define TensorData TensorDataExt + TensorData( + Collection shape_, datatypes::TensorBuffer buffer_ + ) + : shape(std::move(shape_)), buffer(std::move(buffer_)) {} - // - - // TODO(#3794): There should be the option to not have TensorData take ownership of the buffer. - TensorData( - std::vector shape_, - rerun::datatypes::TensorBuffer buffer_ - ) - : shape(std::move(shape_)), buffer(std::move(buffer_)) {} - - // + // #endif - } // namespace datatypes -} // namespace rerun +} // namespace rerun::datatypes diff --git a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp index 56716203dd4f..f51e20f53ee9 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp +++ b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d.hpp @@ -3,8 +3,8 @@ #pragma once +#include "../compiler_utils.hpp" #include "../result.hpp" -#include "../warning_macros.hpp" #include "rotation3d.hpp" #include "scale3d.hpp" #include "vec3d.hpp" @@ -50,14 +50,14 @@ namespace rerun::datatypes { // of union-types datatypes inside of an optional component. // // See: https://github.com/rerun-io/rerun/issues/4027 - DISABLE_MAYBE_UNINITIALIZED_PUSH + RERUN_DISABLE_MAYBE_UNINITIALIZED_PUSH TranslationRotationScale3D(const TranslationRotationScale3D& other) : translation(other.translation), rotation(other.rotation), scale(other.scale), from_parent(other.from_parent) {} - DISABLE_MAYBE_UNINITIALIZED_POP + RERUN_DISABLE_MAYBE_UNINITIALIZED_POP /// Creates a new 3D transform from translation/rotation/scale. /// diff --git a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d_ext.cpp b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d_ext.cpp index 5afd129b8cfe..c29def76514f 100644 --- a/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d_ext.cpp +++ b/rerun_cpp/src/rerun/datatypes/translation_rotation_scale3d_ext.cpp @@ -1,7 +1,7 @@ #include "translation_rotation_scale3d.hpp" // -#include "../warning_macros.hpp" +#include "../compiler_utils.hpp" // namespace rerun { @@ -20,14 +20,14 @@ namespace rerun { // of union-types datatypes inside of an optional component. // // See: https://github.com/rerun-io/rerun/issues/4027 - DISABLE_MAYBE_UNINITIALIZED_PUSH + RERUN_DISABLE_MAYBE_UNINITIALIZED_PUSH TranslationRotationScale3D(const TranslationRotationScale3D& other) : translation(other.translation), rotation(other.rotation), scale(other.scale), from_parent(other.from_parent) {} - DISABLE_MAYBE_UNINITIALIZED_POP + RERUN_DISABLE_MAYBE_UNINITIALIZED_POP /// Creates a new 3D transform from translation/rotation/scale. /// diff --git a/rerun_cpp/src/rerun/indicator_component.hpp b/rerun_cpp/src/rerun/indicator_component.hpp index 48c308b12887..66ce99167cdf 100644 --- a/rerun_cpp/src/rerun/indicator_component.hpp +++ b/rerun_cpp/src/rerun/indicator_component.hpp @@ -14,10 +14,7 @@ namespace rerun { IndicatorComponent() = default; /// Creates a Rerun DataCell from an array of IndicatorComponent components. - static Result to_data_cell( - const IndicatorComponent*, size_t num_instances - ) { - (void)num_instances; // unused + static Result to_data_cell(const IndicatorComponent*, size_t) { return rerun::DataCell::create_indicator_component(Name); } }; diff --git a/rerun_cpp/src/rerun/serialized_component_batch.hpp b/rerun_cpp/src/rerun/serialized_component_batch.hpp index 3c77cd8e3556..0b5580409ad5 100644 --- a/rerun_cpp/src/rerun/serialized_component_batch.hpp +++ b/rerun_cpp/src/rerun/serialized_component_batch.hpp @@ -3,17 +3,17 @@ #include "data_cell.hpp" namespace rerun { - /// A `Collection` serialized using Apache Arrow. + /// One or more instances of a single component serialized using Apache Arrow. struct SerializedComponentBatch { SerializedComponentBatch() = default; - SerializedComponentBatch(size_t _num_instances, DataCell _data_cell) - : num_instances(_num_instances), data_cell(std::move(_data_cell)) {} - - /// How many components were serialized. - size_t num_instances; + SerializedComponentBatch(DataCell data_cell_, size_t num_instances_) + : data_cell(std::move(data_cell_)), num_instances(num_instances_) {} /// The underlying data. DataCell data_cell; + + /// How many components were serialized. + size_t num_instances; }; } // namespace rerun diff --git a/rerun_cpp/src/rerun/type_traits.hpp b/rerun_cpp/src/rerun/type_traits.hpp new file mode 100644 index 000000000000..4904bcb4ed93 --- /dev/null +++ b/rerun_cpp/src/rerun/type_traits.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include // std::begin, std::end, std::size +#include + +/// Type trait utilities. +/// +/// The defined traits acts as an extension to std defined type traits and are used as utilities +/// across the SDK. +namespace rerun::traits { + /// Gets the value/element type of a container. + /// + /// This works for all types that stick with the std convention of having a `value_type` member type. + /// Fails to compile if the type does not have a `value_type` member type - this can be used for SFINAE checks. + template + using value_type_of_t = typename std::remove_reference_t::value_type; + + /// \private + namespace details { + /// False type if a given type is not iterable and has a size (has `begin` and `end`). + template + struct is_iterable : std::false_type {}; + + /// True type if a given type is iterable and has a size (has `begin` and `end` implemented). + /// + /// Makes no restrictions on the type returned by `begin`/`end`. + template + struct is_iterable< + T, std::void_t< + decltype(std::begin(std::declval())), // + decltype(std::end(std::declval())) // + >> : std::true_type {}; + } // namespace details + + /// True if a given type is iterable, meaning there is a `begin` & `end` implementation. + /// + /// Makes no restrictions on the type returned by `begin`/`end`. + template + constexpr bool is_iterable_v = details::is_iterable::value; +} // namespace rerun::traits diff --git a/rerun_cpp/src/rerun/warning_macros.hpp b/rerun_cpp/src/rerun/warning_macros.hpp deleted file mode 100644 index 1e7067d9e814..000000000000 --- a/rerun_cpp/src/rerun/warning_macros.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -// Macro for enabling and disabling the "-Wmaybe-uninitialized" warning in GCC. -// See: https://github.com/rerun-io/rerun/issues/4027 - -#define WITH_MAYBE_UNINITIALIZED_DISABLED(expr) \ - DISABLE_MAYBE_UNINITIALIZED_PUSH \ - expr DISABLE_MAYBE_UNINITIALIZED_POP - -#if defined(__GNUC__) && !defined(__clang__) -#define DISABLE_MAYBE_UNINITIALIZED_PUSH \ - _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -#else -#define DISABLE_MAYBE_UNINITIALIZED_PUSH -#endif - -#if defined(__GNUC__) && !defined(__clang__) -#define DISABLE_MAYBE_UNINITIALIZED_POP _Pragma("GCC diagnostic pop") -#else -#define DISABLE_MAYBE_UNINITIALIZED_POP -#endif diff --git a/rerun_cpp/tests/archetypes/annotation_context.cpp b/rerun_cpp/tests/archetypes/annotation_context.cpp index 921ad81bd429..a6336ab13dd4 100644 --- a/rerun_cpp/tests/archetypes/annotation_context.cpp +++ b/rerun_cpp/tests/archetypes/annotation_context.cpp @@ -13,7 +13,7 @@ SCENARIO( ) { GIVEN("A annotation context created with various utilities and one manual step by step") { rerun::archetypes::AnnotationContext from_utilities({ - rerun::datatypes::ClassDescription({1, "hello"}), + rerun::datatypes::ClassDescription(1, "hello"), rerun::datatypes::ClassDescription(rerun::datatypes::AnnotationInfo(1, "hello")), rerun::datatypes::ClassDescription( {2, "world", rerun::datatypes::Rgba32(3, 4, 5)}, @@ -37,7 +37,7 @@ SCENARIO( }); AnnotationContext manual_archetype; - auto& class_map = manual_archetype.context.class_map; + std::vector class_map; { rerun::datatypes::ClassDescriptionMapElem element; rerun::datatypes::KeypointPair pair; @@ -52,6 +52,9 @@ SCENARIO( class_map.push_back(element); } { + std::vector keypoint_annotations; + std::vector keypoint_connections; + element.class_id = 2; element.class_description.info.id = 2; element.class_description.info.color = rerun::datatypes::Rgba32(3, 4, 5); @@ -60,25 +63,29 @@ SCENARIO( keypoint_annotation.id = 17; keypoint_annotation.color = std::nullopt; keypoint_annotation.label = "head"; - element.class_description.keypoint_annotations.push_back(keypoint_annotation); + keypoint_annotations.push_back(keypoint_annotation); keypoint_annotation.id = 42; keypoint_annotation.color = std::nullopt; keypoint_annotation.label = "shoulders"; - element.class_description.keypoint_annotations.push_back(keypoint_annotation); + keypoint_annotations.push_back(keypoint_annotation); pair.keypoint0 = 1; pair.keypoint1 = 2; - element.class_description.keypoint_connections.push_back(pair); + keypoint_connections.push_back(pair); pair.keypoint0 = 3; pair.keypoint1 = 4; - element.class_description.keypoint_connections.push_back(pair); + keypoint_connections.push_back(pair); + + element.class_description.keypoint_connections = std::move(keypoint_connections); + element.class_description.keypoint_annotations = std::move(keypoint_annotations); class_map.push_back(element); class_map.push_back(element); } } + manual_archetype.context.class_map = std::move(class_map); test_compare_archetype_serialization(from_utilities, manual_archetype); } diff --git a/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp b/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp index 4145c478b002..50f095c9386f 100644 --- a/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp +++ b/rerun_cpp/tests/archetypes/segmentation_and_depth_image.cpp @@ -76,9 +76,9 @@ void run_image_tests() { GIVEN("tensor data with too low rank") { rerun::datatypes::TensorData data( - {{ + { rerun::datatypes::TensorDimension(1, "dr robotnik"), - }}, + }, std::vector(1, 0) ); THEN("a warning occurs on image construction") { diff --git a/rerun_cpp/tests/collection.cpp b/rerun_cpp/tests/collection.cpp index 71bc9188b197..572c4e0c4d14 100644 --- a/rerun_cpp/tests/collection.cpp +++ b/rerun_cpp/tests/collection.cpp @@ -11,101 +11,366 @@ using namespace rerun::components; -SCENARIO("Collection creation via common adapters", TEST_TAG) { - GIVEN("a vector of components") { - std::vector components = { - Position2D(0.0f, 1.0f), - Position2D(1.0f, 2.0f), - }; +// Input type that can be converted to the one held by the container. +struct ConvertibleElement { + ConvertibleElement(int v) : value(v) {} + + ConvertibleElement(const ConvertibleElement& e) = default; + + ConvertibleElement& operator=(const ConvertibleElement& e) = default; + + int value = 99999; +}; + +// Type held by the container. +struct Element { + Element(int v) : value(v) {} + + Element(const Element& e) : value(e.value) { + ++copy_count; + } + + Element(Element&& e) : value(e.value) { + ++move_count; + } + + Element& operator=(const Element& e) = default; + + Element(const ConvertibleElement& e) : value(e.value) { + ++move_convertible_count; + } + + Element(ConvertibleElement&& e) : value(e.value) { + ++copy_convertible_count; + } + + bool operator==(const Element& other) const { + return value == other.value; + } + + int value = 99999; + + static int move_count; + static int copy_count; + static int move_convertible_count; + static int copy_convertible_count; +}; + +int Element::move_count = 0; +int Element::copy_count = 0; +int Element::move_convertible_count = 0; +int Element::copy_convertible_count = 0; + +struct CheckElementMoveAndCopyCount { + CheckElementMoveAndCopyCount() + : copy_count_before(Element::copy_count), + move_count_before(Element::move_count), + copy_convertible_count_before(Element::copy_convertible_count), + move_convertible_count_before(Element::move_convertible_count) {} + + ~CheckElementMoveAndCopyCount() { +// Both moves and copies can be elided, so we can only check for a minimum. +// But in debug builds this seems to be surprisingly reliable! +#ifdef NDEBUG +#define CMP >= +#else +#define CMP == +#endif + + CHECK(Element::copy_count - copy_count_before CMP expected_copy_increase); + CHECK(Element::move_count - move_count_before CMP expected_move_increase); + CHECK( + Element::copy_convertible_count - + copy_convertible_count_before CMP expected_copy_convertible_increase + ); + CHECK( + Element::move_convertible_count - + move_convertible_count_before CMP expected_move_convertible_increase + ); +#undef CMP + } + + CheckElementMoveAndCopyCount(const CheckElementMoveAndCopyCount&) = delete; + + CheckElementMoveAndCopyCount& expect_move(int i) { + expected_move_increase = i; + return *this; + } + + CheckElementMoveAndCopyCount& expect_copy(int i) { + expected_copy_increase = i; + return *this; + } + + CheckElementMoveAndCopyCount& expect_convertible_move(int i) { + expected_copy_convertible_increase = i; + return *this; + } + + CheckElementMoveAndCopyCount& expect_convertible_copy(int i) { + expected_move_convertible_increase = i; + return *this; + } + + int expected_copy_increase = 0; + int expected_move_increase = 0; + int expected_copy_convertible_increase = 0; + int expected_move_convertible_increase = 0; + + int copy_count_before, move_count_before; + int copy_convertible_count_before, move_convertible_count_before; +}; + +#define EXPECTED_ELEMENT_LIST \ + { 1337, 42 } + +// Checks if the collection contains the elements defined in `EXPECTED_ELEMENT_LIST`. +void check_for_expected_list(const rerun::Collection& collection) { + std::array expected = EXPECTED_ELEMENT_LIST; + CHECK(collection.size() == expected.size()); + CHECK(collection[0] == expected[0]); + CHECK(collection[1] == expected[1]); +} + +#define EXPECTED_SINGLE 666 + +// Checks if the collection contains the elements defined in `EXPECTED_SINGLE`. +void check_for_expected_single(const rerun::Collection& collection) { + Element expected = EXPECTED_SINGLE; + CHECK(collection.size() == 1); + CHECK(collection[0] == expected); +} + +SCENARIO( + "Collection creation via basic adapters, using the container's value_type as input", TEST_TAG +) { + GIVEN("a vector of elements") { + std::vector elements = EXPECTED_ELEMENT_LIST; THEN("a collection created from it borrows its data") { - const rerun::Collection batch(components); - CHECK(batch.size() == components.size()); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::Borrowed); + CheckElementMoveAndCopyCount check; // No copies or moves. + + const rerun::Collection collection(elements); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::Borrowed); } - THEN("a collection created from it moving it owns the data") { - const rerun::Collection batch(std::move(components)); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + THEN("a collection created from moving it owns the data") { + CheckElementMoveAndCopyCount check; + // No element copies or moves, the vector itself is moved. + + const rerun::Collection collection(std::move(elements)); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } - GIVEN("a temporary vector of components") { + GIVEN("a temporary vector of elements") { THEN("a collection created from it owns its data") { - const rerun::Collection batch(std::vector{ - Position2D(0.0f, 1.0f), - Position2D(1.0f, 2.0f), - }); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + CheckElementMoveAndCopyCount check; + // No element moves, the vector itself is moved. + check.expect_copy(2); // for constructing the temporary vector. + + const rerun::Collection collection(std::vector EXPECTED_ELEMENT_LIST); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } - GIVEN("an std::array of components") { - std::array components = { - Position2D(0.0f, 1.0f), - Position2D(1.0f, 2.0f), - }; + GIVEN("an std::array of elements") { + std::array elements = EXPECTED_ELEMENT_LIST; THEN("a collection created from it borrows its data") { - const rerun::Collection batch(components); - CHECK(batch.size() == components.size()); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::Borrowed); + CheckElementMoveAndCopyCount check; // No copies or moves. + + const rerun::Collection collection(elements); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::Borrowed); } THEN("a collection created from it moving it owns the data") { - const rerun::Collection batch(std::move(components)); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + CheckElementMoveAndCopyCount check; + check.expect_move(2); + + const rerun::Collection collection(std::move(elements)); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } - GIVEN("a temporary std::array of components") { + GIVEN("a temporary std::array of elements") { THEN("a collection created from it owns its data") { - const rerun::Collection batch(std::array{ - Position2D(0.0f, 1.0f), - Position2D(1.0f, 2.0f), - }); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + CheckElementMoveAndCopyCount check; + check.expect_move(2); + + const rerun::Collection collection(std::array EXPECTED_ELEMENT_LIST + ); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } - GIVEN("a c-array of components") { - Position2D components[] = { - Position2D(0.0f, 1.0f), - Position2D(1.0f, 2.0f), - }; + GIVEN("a c-array of elements") { + Element elements[] = EXPECTED_ELEMENT_LIST; THEN("a collection created from it borrows its data") { - const rerun::Collection batch(components); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::Borrowed); + CheckElementMoveAndCopyCount check; // No copies or moves. + + const rerun::Collection collection(elements); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::Borrowed); } THEN("a collection created from moving it owns the data") { - const rerun::Collection batch(std::move(components)); - CHECK(batch.size() == 2); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + CheckElementMoveAndCopyCount check; + check.expect_move(2); + + const rerun::Collection collection(std::move(elements)); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } - GIVEN("a single components") { - Position2D component = Position2D(0.0f, 1.0f); + GIVEN("a single element") { + Element component = EXPECTED_SINGLE; THEN("a collection created from it borrows its data") { - const rerun::Collection batch(component); - CHECK(batch.size() == 1); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::Borrowed); + CheckElementMoveAndCopyCount check; // No copies or moves. + + const rerun::Collection collection(component); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::Borrowed); } - THEN("a collection created from it moving it owns the data") { - const rerun::Collection batch(std::move(component)); - CHECK(batch.size() == 1); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + THEN("a collection created from moving it owns the data") { + CheckElementMoveAndCopyCount check; + check.expect_move(1); + + const rerun::Collection collection(std::move(component)); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } GIVEN("a single temporary component") { - THEN("a collection created from it borrows its data") { - const rerun::Collection batch(Position2D(0.0f, 1.0f)); - CHECK(batch.size() == 1); - CHECK(batch.get_ownership() == rerun::CollectionOwnership::VectorOwned); + THEN("a collection created from it owns the data") { + CheckElementMoveAndCopyCount check; + check.expect_move(1); + + const rerun::Collection collection(Element(EXPECTED_SINGLE)); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } +} + +SCENARIO( + "Collection creation via basic adapters, using a type that is compatible to the container's value_type as input", + TEST_TAG +) { + GIVEN("a vector of convertible elements") { + std::vector elements = EXPECTED_ELEMENT_LIST; + + THEN("a collection created from it copies its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_copy(2); + + const rerun::Collection collection(elements); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + THEN("a collection created from it moves its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(2); + + const rerun::Collection collection(std::move(elements)); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } + + GIVEN("a temporary vector of convertible elements") { + THEN("a collection created from it moves its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(2); + + const rerun::Collection + collection(std::vector EXPECTED_ELEMENT_LIST); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } + + GIVEN("an std::array of convertible elements") { + std::array elements = EXPECTED_ELEMENT_LIST; + + THEN("a collection created from it copies its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_copy(2); + + const rerun::Collection collection(elements); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + THEN("a collection created from it moves its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(2); + + const rerun::Collection collection(std::move(elements)); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } + GIVEN("a temporary std::array of convertible elements") { + THEN("a collection created from it moves its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(2); + + const rerun::Collection + collection(std::array EXPECTED_ELEMENT_LIST); + check_for_expected_list(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } + + // Not yet supported. + // GIVEN("a c-array of convertible elements") { + // ConvertibleElement elements[] = EXPECTED_ELEMENT_LIST; + // + // THEN("a collection created from it borrows its data") { + // } + // THEN("a collection created from moving it owns the data") { + // } + // } + + GIVEN("a single convertible element") { + ConvertibleElement element = EXPECTED_SINGLE; + + THEN("a collection created from it copies its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_copy(1); + // The resulting value is moved internally into a vector. + check.expect_move(1); + + const rerun::Collection collection(element); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + THEN("a collection created from it move its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(1); + // The resulting value is moved internally into a vector. + check.expect_move(1); + + const rerun::Collection collection(std::move(element)); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); + } + } + GIVEN("a single temporary convertible element") { + THEN("a collection created from it move its data") { + CheckElementMoveAndCopyCount check; + check.expect_convertible_move(1); + // The resulting value is moved internally into a vector. + check.expect_move(1); + + const rerun::Collection collection(ConvertibleElement(EXPECTED_SINGLE)); + check_for_expected_single(collection); + CHECK(collection.get_ownership() == rerun::CollectionOwnership::VectorOwned); } } } @@ -169,7 +434,7 @@ SCENARIO("Collection creation via a custom adapter for a datalayout compatible t } } -SCENARIO("Collection move behavior", TEST_TAG) { +SCENARIO("Move construction/assignment of collections", TEST_TAG) { std::vector components = { Position2D(0.0f, 1.0f), Position2D(1.0f, 2.0f), @@ -232,3 +497,135 @@ SCENARIO("Collection move behavior", TEST_TAG) { //std::vector strings = {"a", "b", "c"}; //rerun::Collection batch(strings); } + +SCENARIO("Copy/move construction/assignment of collections", TEST_TAG) { + GIVEN("A default constructed collection") { + rerun::Collection collection; + const int* old_data_ptr = collection.data(); + + THEN("it can be move constructed") { + rerun::Collection collection2(std::move(collection)); + CHECK(collection2.size() == 0); + CHECK(collection2.data() == old_data_ptr); + } + THEN("it can be move assigned") { + rerun::Collection collection2; + collection2 = std::move(collection); + CHECK(collection2.size() == 0); + CHECK(collection2.data() == old_data_ptr); + } + + THEN("it can be copy constructed") { + rerun::Collection collection2(collection); + CHECK(collection2.size() == 0); + } + THEN("it can be copy assigned") { + rerun::Collection collection2; + collection2 = collection; + CHECK(collection2.size() == 0); + } + } + + GIVEN("a collection with owned data") { + auto collection = + rerun::Collection::take_ownership(std::vector EXPECTED_ELEMENT_LIST); + const Element* old_data_ptr = collection.data(); + + THEN("it can be move constructed") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2(std::move(collection)); + check_for_expected_list(collection2); + CHECK(collection2.data() == old_data_ptr); + } + THEN("it can be move assigned") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2; + collection2 = std::move(collection); + check_for_expected_list(collection2); + CHECK(collection2.data() == old_data_ptr); + } + + THEN("it can be copy constructed") { + CheckElementMoveAndCopyCount check; + check.expect_copy(2); + + rerun::Collection collection2(collection); + check_for_expected_list(collection2); + } + THEN("it can be copy assigned") { + CheckElementMoveAndCopyCount check; + check.expect_copy(2); + + rerun::Collection collection2; + + collection2 = collection; + check_for_expected_list(collection2); + } + } + + GIVEN("a collection with borrowed data") { + std::vector data EXPECTED_ELEMENT_LIST; + auto collection = rerun::Collection::borrow(data.data(), data.size()); + const Element* old_data_ptr = data.data(); + + THEN("it can be move constructed") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2(std::move(collection)); + check_for_expected_list(collection2); + CHECK(collection2.data() == old_data_ptr); + } + THEN("it can be move assigned") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2; + collection2 = std::move(collection); + check_for_expected_list(collection2); + CHECK(collection2.data() == old_data_ptr); + } + + THEN("it can be copy constructed") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2(collection); + check_for_expected_list(collection2); + } + THEN("it can be copy assigned") { + CheckElementMoveAndCopyCount check; // No move or copy. + + rerun::Collection collection2; + + collection2 = collection; + check_for_expected_list(collection2); + } + } +} + +SCENARIO("Conversion to vector using `to_vector`", TEST_TAG) { + auto expected_vector = std::vector EXPECTED_ELEMENT_LIST; + + GIVEN("a collection with owned data") { + auto collection = + rerun::Collection::take_ownership(std::vector EXPECTED_ELEMENT_LIST); + + THEN("it can be converted to a vector") { + CheckElementMoveAndCopyCount check; + check.expect_copy(2); + + CHECK(collection.to_vector() == expected_vector); + } + } + GIVEN("a collection with borrowed data") { + std::vector data EXPECTED_ELEMENT_LIST; + auto collection = rerun::Collection::borrow(data.data(), data.size()); + + THEN("it can be converted to a vector") { + CheckElementMoveAndCopyCount check; + check.expect_copy(2); + + CHECK(collection.to_vector() == expected_vector); + } + } +} diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp index 10f883f31e67..7408711082c8 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.cpp @@ -20,137 +20,136 @@ namespace rerun { cells.reserve(21); { - auto result = - Collection(archetype.fuzz1001).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer1::to_data_cell(&archetype.fuzz1001, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1002).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer2::to_data_cell(&archetype.fuzz1002, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1003).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer3::to_data_cell(&archetype.fuzz1003, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1004).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer4::to_data_cell(&archetype.fuzz1004, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1005).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer5::to_data_cell(&archetype.fuzz1005, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1006).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer6::to_data_cell(&archetype.fuzz1006, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1007).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer7::to_data_cell(&archetype.fuzz1007, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1008).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer8::to_data_cell(&archetype.fuzz1008, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1009).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer9::to_data_cell(&archetype.fuzz1009, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1010).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer10::to_data_cell(&archetype.fuzz1010, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1011).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer11::to_data_cell(&archetype.fuzz1011, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1012).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer12::to_data_cell(&archetype.fuzz1012, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1013).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer13::to_data_cell(&archetype.fuzz1013, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1014).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer14::to_data_cell(&archetype.fuzz1014, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1015).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer15::to_data_cell(&archetype.fuzz1015, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1016).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer16::to_data_cell(&archetype.fuzz1016, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1017).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer17::to_data_cell(&archetype.fuzz1017, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1018).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer18::to_data_cell(&archetype.fuzz1018, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1019).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer19::to_data_cell(&archetype.fuzz1019, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1020).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer20::to_data_cell(&archetype.fuzz1020, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(archetype.fuzz1021).serialize(); + const size_t size = 1; + auto result = rerun::components::AffixFuzzer21::to_data_cell(&archetype.fuzz1021, size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(AffixFuzzer1::IndicatorComponent()) - .serialize(); + auto indicator = AffixFuzzer1::IndicatorComponent(); + auto result = AffixFuzzer1::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp index 3912f4e0e7f6..690cd8803158 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer1.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp index 4abc1e27c34d..ae9e1cee4bb9 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.cpp @@ -20,101 +20,172 @@ namespace rerun { cells.reserve(18); { - auto result = (archetype.fuzz1101).serialize(); + const size_t size = archetype.fuzz1101.size(); + auto result = rerun::components::AffixFuzzer1::to_data_cell( + archetype.fuzz1101.data(), + archetype.fuzz1101.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1102).serialize(); + const size_t size = archetype.fuzz1102.size(); + auto result = rerun::components::AffixFuzzer2::to_data_cell( + archetype.fuzz1102.data(), + archetype.fuzz1102.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1103).serialize(); + const size_t size = archetype.fuzz1103.size(); + auto result = rerun::components::AffixFuzzer3::to_data_cell( + archetype.fuzz1103.data(), + archetype.fuzz1103.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1104).serialize(); + const size_t size = archetype.fuzz1104.size(); + auto result = rerun::components::AffixFuzzer4::to_data_cell( + archetype.fuzz1104.data(), + archetype.fuzz1104.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1105).serialize(); + const size_t size = archetype.fuzz1105.size(); + auto result = rerun::components::AffixFuzzer5::to_data_cell( + archetype.fuzz1105.data(), + archetype.fuzz1105.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1106).serialize(); + const size_t size = archetype.fuzz1106.size(); + auto result = rerun::components::AffixFuzzer6::to_data_cell( + archetype.fuzz1106.data(), + archetype.fuzz1106.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1107).serialize(); + const size_t size = archetype.fuzz1107.size(); + auto result = rerun::components::AffixFuzzer7::to_data_cell( + archetype.fuzz1107.data(), + archetype.fuzz1107.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1108).serialize(); + const size_t size = archetype.fuzz1108.size(); + auto result = rerun::components::AffixFuzzer8::to_data_cell( + archetype.fuzz1108.data(), + archetype.fuzz1108.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1109).serialize(); + const size_t size = archetype.fuzz1109.size(); + auto result = rerun::components::AffixFuzzer9::to_data_cell( + archetype.fuzz1109.data(), + archetype.fuzz1109.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1110).serialize(); + const size_t size = archetype.fuzz1110.size(); + auto result = rerun::components::AffixFuzzer10::to_data_cell( + archetype.fuzz1110.data(), + archetype.fuzz1110.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1111).serialize(); + const size_t size = archetype.fuzz1111.size(); + auto result = rerun::components::AffixFuzzer11::to_data_cell( + archetype.fuzz1111.data(), + archetype.fuzz1111.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1112).serialize(); + const size_t size = archetype.fuzz1112.size(); + auto result = rerun::components::AffixFuzzer12::to_data_cell( + archetype.fuzz1112.data(), + archetype.fuzz1112.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1113).serialize(); + const size_t size = archetype.fuzz1113.size(); + auto result = rerun::components::AffixFuzzer13::to_data_cell( + archetype.fuzz1113.data(), + archetype.fuzz1113.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1114).serialize(); + const size_t size = archetype.fuzz1114.size(); + auto result = rerun::components::AffixFuzzer14::to_data_cell( + archetype.fuzz1114.data(), + archetype.fuzz1114.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1115).serialize(); + const size_t size = archetype.fuzz1115.size(); + auto result = rerun::components::AffixFuzzer15::to_data_cell( + archetype.fuzz1115.data(), + archetype.fuzz1115.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1116).serialize(); + const size_t size = archetype.fuzz1116.size(); + auto result = rerun::components::AffixFuzzer16::to_data_cell( + archetype.fuzz1116.data(), + archetype.fuzz1116.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1117).serialize(); + const size_t size = archetype.fuzz1117.size(); + auto result = rerun::components::AffixFuzzer17::to_data_cell( + archetype.fuzz1117.data(), + archetype.fuzz1117.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = (archetype.fuzz1118).serialize(); + const size_t size = archetype.fuzz1118.size(); + auto result = rerun::components::AffixFuzzer18::to_data_cell( + archetype.fuzz1118.data(), + archetype.fuzz1118.size() + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(AffixFuzzer2::IndicatorComponent()) - .serialize(); + auto indicator = AffixFuzzer2::IndicatorComponent(); + auto result = AffixFuzzer2::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp index 665e606f787c..b29275cb286f 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer2.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp index 62f9d5f3c671..cf5e3c49704e 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.cpp @@ -20,119 +20,136 @@ namespace rerun { cells.reserve(18); if (archetype.fuzz2001.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2001.value()).serialize(); + rerun::components::AffixFuzzer1::to_data_cell(&archetype.fuzz2001.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2002.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2002.value()).serialize(); + rerun::components::AffixFuzzer2::to_data_cell(&archetype.fuzz2002.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2003.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2003.value()).serialize(); + rerun::components::AffixFuzzer3::to_data_cell(&archetype.fuzz2003.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2004.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2004.value()).serialize(); + rerun::components::AffixFuzzer4::to_data_cell(&archetype.fuzz2004.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2005.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2005.value()).serialize(); + rerun::components::AffixFuzzer5::to_data_cell(&archetype.fuzz2005.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2006.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2006.value()).serialize(); + rerun::components::AffixFuzzer6::to_data_cell(&archetype.fuzz2006.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2007.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2007.value()).serialize(); + rerun::components::AffixFuzzer7::to_data_cell(&archetype.fuzz2007.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2008.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2008.value()).serialize(); + rerun::components::AffixFuzzer8::to_data_cell(&archetype.fuzz2008.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2009.has_value()) { + const size_t size = 1; auto result = - Collection(archetype.fuzz2009.value()).serialize(); + rerun::components::AffixFuzzer9::to_data_cell(&archetype.fuzz2009.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2010.has_value()) { - auto result = Collection(archetype.fuzz2010.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer10::to_data_cell(&archetype.fuzz2010.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2011.has_value()) { - auto result = Collection(archetype.fuzz2011.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer11::to_data_cell(&archetype.fuzz2011.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2012.has_value()) { - auto result = Collection(archetype.fuzz2012.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer12::to_data_cell(&archetype.fuzz2012.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2013.has_value()) { - auto result = Collection(archetype.fuzz2013.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer13::to_data_cell(&archetype.fuzz2013.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2014.has_value()) { - auto result = Collection(archetype.fuzz2014.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer14::to_data_cell(&archetype.fuzz2014.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2015.has_value()) { - auto result = Collection(archetype.fuzz2015.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer15::to_data_cell(&archetype.fuzz2015.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2016.has_value()) { - auto result = Collection(archetype.fuzz2016.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer16::to_data_cell(&archetype.fuzz2016.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2017.has_value()) { - auto result = Collection(archetype.fuzz2017.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer17::to_data_cell(&archetype.fuzz2017.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2018.has_value()) { - auto result = Collection(archetype.fuzz2018.value()) - .serialize(); + const size_t size = 1; + auto result = + rerun::components::AffixFuzzer18::to_data_cell(&archetype.fuzz2018.value(), size); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(AffixFuzzer3::IndicatorComponent()) - .serialize(); + auto indicator = AffixFuzzer3::IndicatorComponent(); + auto result = AffixFuzzer3::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp index e22e5a70f568..c57f88e2ab33 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer3.hpp @@ -25,10 +25,11 @@ #include #include #include +#include #include #include #include -#include +#include #include #include @@ -82,109 +83,109 @@ namespace rerun::archetypes { AffixFuzzer3 with_fuzz2001(rerun::components::AffixFuzzer1 _fuzz2001) && { fuzz2001 = std::move(_fuzz2001); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2002(rerun::components::AffixFuzzer2 _fuzz2002) && { fuzz2002 = std::move(_fuzz2002); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2003(rerun::components::AffixFuzzer3 _fuzz2003) && { fuzz2003 = std::move(_fuzz2003); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2004(rerun::components::AffixFuzzer4 _fuzz2004) && { fuzz2004 = std::move(_fuzz2004); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2005(rerun::components::AffixFuzzer5 _fuzz2005) && { fuzz2005 = std::move(_fuzz2005); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2006(rerun::components::AffixFuzzer6 _fuzz2006) && { fuzz2006 = std::move(_fuzz2006); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2007(rerun::components::AffixFuzzer7 _fuzz2007) && { fuzz2007 = std::move(_fuzz2007); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2008(rerun::components::AffixFuzzer8 _fuzz2008) && { fuzz2008 = std::move(_fuzz2008); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2009(rerun::components::AffixFuzzer9 _fuzz2009) && { fuzz2009 = std::move(_fuzz2009); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2010(rerun::components::AffixFuzzer10 _fuzz2010) && { fuzz2010 = std::move(_fuzz2010); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2011(rerun::components::AffixFuzzer11 _fuzz2011) && { fuzz2011 = std::move(_fuzz2011); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2012(rerun::components::AffixFuzzer12 _fuzz2012) && { fuzz2012 = std::move(_fuzz2012); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2013(rerun::components::AffixFuzzer13 _fuzz2013) && { fuzz2013 = std::move(_fuzz2013); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2014(rerun::components::AffixFuzzer14 _fuzz2014) && { fuzz2014 = std::move(_fuzz2014); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2015(rerun::components::AffixFuzzer15 _fuzz2015) && { fuzz2015 = std::move(_fuzz2015); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2016(rerun::components::AffixFuzzer16 _fuzz2016) && { fuzz2016 = std::move(_fuzz2016); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2017(rerun::components::AffixFuzzer17 _fuzz2017) && { fuzz2017 = std::move(_fuzz2017); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer3 with_fuzz2018(rerun::components::AffixFuzzer18 _fuzz2018) && { fuzz2018 = std::move(_fuzz2018); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp index 1c1b83bd2c26..2b2dc1999347 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.cpp @@ -20,101 +20,172 @@ namespace rerun { cells.reserve(18); if (archetype.fuzz2101.has_value()) { - auto result = (archetype.fuzz2101.value()).serialize(); + const size_t size = archetype.fuzz2101.value().size(); + auto result = rerun::components::AffixFuzzer1::to_data_cell( + archetype.fuzz2101.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2102.has_value()) { - auto result = (archetype.fuzz2102.value()).serialize(); + const size_t size = archetype.fuzz2102.value().size(); + auto result = rerun::components::AffixFuzzer2::to_data_cell( + archetype.fuzz2102.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2103.has_value()) { - auto result = (archetype.fuzz2103.value()).serialize(); + const size_t size = archetype.fuzz2103.value().size(); + auto result = rerun::components::AffixFuzzer3::to_data_cell( + archetype.fuzz2103.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2104.has_value()) { - auto result = (archetype.fuzz2104.value()).serialize(); + const size_t size = archetype.fuzz2104.value().size(); + auto result = rerun::components::AffixFuzzer4::to_data_cell( + archetype.fuzz2104.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2105.has_value()) { - auto result = (archetype.fuzz2105.value()).serialize(); + const size_t size = archetype.fuzz2105.value().size(); + auto result = rerun::components::AffixFuzzer5::to_data_cell( + archetype.fuzz2105.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2106.has_value()) { - auto result = (archetype.fuzz2106.value()).serialize(); + const size_t size = archetype.fuzz2106.value().size(); + auto result = rerun::components::AffixFuzzer6::to_data_cell( + archetype.fuzz2106.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2107.has_value()) { - auto result = (archetype.fuzz2107.value()).serialize(); + const size_t size = archetype.fuzz2107.value().size(); + auto result = rerun::components::AffixFuzzer7::to_data_cell( + archetype.fuzz2107.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2108.has_value()) { - auto result = (archetype.fuzz2108.value()).serialize(); + const size_t size = archetype.fuzz2108.value().size(); + auto result = rerun::components::AffixFuzzer8::to_data_cell( + archetype.fuzz2108.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2109.has_value()) { - auto result = (archetype.fuzz2109.value()).serialize(); + const size_t size = archetype.fuzz2109.value().size(); + auto result = rerun::components::AffixFuzzer9::to_data_cell( + archetype.fuzz2109.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2110.has_value()) { - auto result = (archetype.fuzz2110.value()).serialize(); + const size_t size = archetype.fuzz2110.value().size(); + auto result = rerun::components::AffixFuzzer10::to_data_cell( + archetype.fuzz2110.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2111.has_value()) { - auto result = (archetype.fuzz2111.value()).serialize(); + const size_t size = archetype.fuzz2111.value().size(); + auto result = rerun::components::AffixFuzzer11::to_data_cell( + archetype.fuzz2111.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2112.has_value()) { - auto result = (archetype.fuzz2112.value()).serialize(); + const size_t size = archetype.fuzz2112.value().size(); + auto result = rerun::components::AffixFuzzer12::to_data_cell( + archetype.fuzz2112.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2113.has_value()) { - auto result = (archetype.fuzz2113.value()).serialize(); + const size_t size = archetype.fuzz2113.value().size(); + auto result = rerun::components::AffixFuzzer13::to_data_cell( + archetype.fuzz2113.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2114.has_value()) { - auto result = (archetype.fuzz2114.value()).serialize(); + const size_t size = archetype.fuzz2114.value().size(); + auto result = rerun::components::AffixFuzzer14::to_data_cell( + archetype.fuzz2114.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2115.has_value()) { - auto result = (archetype.fuzz2115.value()).serialize(); + const size_t size = archetype.fuzz2115.value().size(); + auto result = rerun::components::AffixFuzzer15::to_data_cell( + archetype.fuzz2115.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2116.has_value()) { - auto result = (archetype.fuzz2116.value()).serialize(); + const size_t size = archetype.fuzz2116.value().size(); + auto result = rerun::components::AffixFuzzer16::to_data_cell( + archetype.fuzz2116.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2117.has_value()) { - auto result = (archetype.fuzz2117.value()).serialize(); + const size_t size = archetype.fuzz2117.value().size(); + auto result = rerun::components::AffixFuzzer17::to_data_cell( + archetype.fuzz2117.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } if (archetype.fuzz2118.has_value()) { - auto result = (archetype.fuzz2118.value()).serialize(); + const size_t size = archetype.fuzz2118.value().size(); + auto result = rerun::components::AffixFuzzer18::to_data_cell( + archetype.fuzz2118.value().data(), + size + ); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), size); } { - auto result = - Collection(AffixFuzzer4::IndicatorComponent()) - .serialize(); + auto indicator = AffixFuzzer4::IndicatorComponent(); + auto result = AffixFuzzer4::IndicatorComponent::to_data_cell(&indicator, 1); RR_RETURN_NOT_OK(result.error); - cells.emplace_back(std::move(result.value)); + cells.emplace_back(std::move(result.value), 1); } return cells; diff --git a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp index eb0f9a73ebab..671416113215 100644 --- a/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp +++ b/rerun_cpp/tests/generated/archetypes/affix_fuzzer4.hpp @@ -25,10 +25,11 @@ #include #include #include +#include #include #include #include -#include +#include #include #include @@ -82,109 +83,109 @@ namespace rerun::archetypes { AffixFuzzer4 with_fuzz2101(Collection _fuzz2101) && { fuzz2101 = std::move(_fuzz2101); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2102(Collection _fuzz2102) && { fuzz2102 = std::move(_fuzz2102); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2103(Collection _fuzz2103) && { fuzz2103 = std::move(_fuzz2103); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2104(Collection _fuzz2104) && { fuzz2104 = std::move(_fuzz2104); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2105(Collection _fuzz2105) && { fuzz2105 = std::move(_fuzz2105); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2106(Collection _fuzz2106) && { fuzz2106 = std::move(_fuzz2106); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2107(Collection _fuzz2107) && { fuzz2107 = std::move(_fuzz2107); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2108(Collection _fuzz2108) && { fuzz2108 = std::move(_fuzz2108); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2109(Collection _fuzz2109) && { fuzz2109 = std::move(_fuzz2109); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2110(Collection _fuzz2110) && { fuzz2110 = std::move(_fuzz2110); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2111(Collection _fuzz2111) && { fuzz2111 = std::move(_fuzz2111); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2112(Collection _fuzz2112) && { fuzz2112 = std::move(_fuzz2112); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2113(Collection _fuzz2113) && { fuzz2113 = std::move(_fuzz2113); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2114(Collection _fuzz2114) && { fuzz2114 = std::move(_fuzz2114); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2115(Collection _fuzz2115) && { fuzz2115 = std::move(_fuzz2115); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2116(Collection _fuzz2116) && { fuzz2116 = std::move(_fuzz2116); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2117(Collection _fuzz2117) && { fuzz2117 = std::move(_fuzz2117); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } AffixFuzzer4 with_fuzz2118(Collection _fuzz2118) && { fuzz2118 = std::move(_fuzz2118); // See: https://github.com/rerun-io/rerun/issues/4027 - WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) + RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } /// Returns the number of primary instances of this archetype. diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp index 4fec10280b6b..7ad15cf9571e 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer11.hpp @@ -6,10 +6,10 @@ #include #include #include +#include #include #include #include -#include namespace arrow { class DataType; @@ -19,7 +19,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer11 { - std::optional> many_floats_optional; + std::optional> many_floats_optional; /// Name of the component, used for serialization. static const char NAME[]; @@ -27,10 +27,10 @@ namespace rerun::components { public: AffixFuzzer11() = default; - AffixFuzzer11(std::optional> many_floats_optional_) + AffixFuzzer11(std::optional> many_floats_optional_) : many_floats_optional(std::move(many_floats_optional_)) {} - AffixFuzzer11& operator=(std::optional> many_floats_optional_) { + AffixFuzzer11& operator=(std::optional> many_floats_optional_) { many_floats_optional = std::move(many_floats_optional_); return *this; } diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp index 15730c1cac57..283db5c2a4df 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer12.hpp @@ -5,11 +5,11 @@ #include #include +#include #include #include #include #include -#include namespace arrow { class DataType; @@ -19,7 +19,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer12 { - std::vector many_strings_required; + rerun::Collection many_strings_required; /// Name of the component, used for serialization. static const char NAME[]; @@ -27,10 +27,10 @@ namespace rerun::components { public: AffixFuzzer12() = default; - AffixFuzzer12(std::vector many_strings_required_) + AffixFuzzer12(rerun::Collection many_strings_required_) : many_strings_required(std::move(many_strings_required_)) {} - AffixFuzzer12& operator=(std::vector many_strings_required_) { + AffixFuzzer12& operator=(rerun::Collection many_strings_required_) { many_strings_required = std::move(many_strings_required_); return *this; } diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp index 03ada841ca05..0d02b60105b0 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer13.hpp @@ -6,11 +6,11 @@ #include #include #include +#include #include #include #include #include -#include namespace arrow { class DataType; @@ -20,7 +20,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer13 { - std::optional> many_strings_optional; + std::optional> many_strings_optional; /// Name of the component, used for serialization. static const char NAME[]; @@ -28,10 +28,12 @@ namespace rerun::components { public: AffixFuzzer13() = default; - AffixFuzzer13(std::optional> many_strings_optional_) + AffixFuzzer13(std::optional> many_strings_optional_) : many_strings_optional(std::move(many_strings_optional_)) {} - AffixFuzzer13& operator=(std::optional> many_strings_optional_) { + AffixFuzzer13& operator=( + std::optional> many_strings_optional_ + ) { many_strings_optional = std::move(many_strings_optional_); return *this; } diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp index a2e8a64cdac4..a54e69272b5b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer16.hpp @@ -7,10 +7,10 @@ #include #include +#include #include #include #include -#include namespace arrow { class DataType; @@ -20,7 +20,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer16 { - std::vector many_required_unions; + rerun::Collection many_required_unions; /// Name of the component, used for serialization. static const char NAME[]; @@ -28,10 +28,11 @@ namespace rerun::components { public: AffixFuzzer16() = default; - AffixFuzzer16(std::vector many_required_unions_) + AffixFuzzer16(rerun::Collection many_required_unions_) : many_required_unions(std::move(many_required_unions_)) {} - AffixFuzzer16& operator=(std::vector many_required_unions_ + AffixFuzzer16& operator=( + rerun::Collection many_required_unions_ ) { many_required_unions = std::move(many_required_unions_); return *this; diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp index 039b5499ff51..0676bbb94d3b 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer17.hpp @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include namespace arrow { class DataType; @@ -21,7 +21,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer17 { - std::optional> many_optional_unions; + std::optional> many_optional_unions; /// Name of the component, used for serialization. static const char NAME[]; @@ -30,12 +30,12 @@ namespace rerun::components { AffixFuzzer17() = default; AffixFuzzer17( - std::optional> many_optional_unions_ + std::optional> many_optional_unions_ ) : many_optional_unions(std::move(many_optional_unions_)) {} AffixFuzzer17& operator=( - std::optional> many_optional_unions_ + std::optional> many_optional_unions_ ) { many_optional_unions = std::move(many_optional_unions_); return *this; diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp index 5f3796b1d762..34aed17a3f5e 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer18.hpp @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include namespace arrow { class DataType; @@ -21,7 +21,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer18 { - std::optional> many_optional_unions; + std::optional> many_optional_unions; /// Name of the component, used for serialization. static const char NAME[]; @@ -30,12 +30,12 @@ namespace rerun::components { AffixFuzzer18() = default; AffixFuzzer18( - std::optional> many_optional_unions_ + std::optional> many_optional_unions_ ) : many_optional_unions(std::move(many_optional_unions_)) {} AffixFuzzer18& operator=( - std::optional> many_optional_unions_ + std::optional> many_optional_unions_ ) { many_optional_unions = std::move(many_optional_unions_); return *this; diff --git a/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp b/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp index 8cfa6764649e..30e4e989708f 100644 --- a/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp +++ b/rerun_cpp/tests/generated/components/affix_fuzzer7.hpp @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include namespace arrow { class DataType; @@ -21,7 +21,7 @@ namespace arrow { namespace rerun::components { struct AffixFuzzer7 { - std::optional> many_optional; + std::optional> many_optional; /// Name of the component, used for serialization. static const char NAME[]; @@ -29,11 +29,12 @@ namespace rerun::components { public: AffixFuzzer7() = default; - AffixFuzzer7(std::optional> many_optional_) + AffixFuzzer7(std::optional> many_optional_ + ) : many_optional(std::move(many_optional_)) {} AffixFuzzer7& operator=( - std::optional> many_optional_ + std::optional> many_optional_ ) { many_optional = std::move(many_optional_); return *this; diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp index e92440c1d3c7..ce271b2952e0 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer1.hpp @@ -8,9 +8,9 @@ #include #include #include +#include #include #include -#include namespace arrow { class DataType; @@ -26,11 +26,11 @@ namespace rerun::datatypes { std::optional single_string_optional; - std::optional> many_floats_optional; + std::optional> many_floats_optional; - std::vector many_strings_required; + rerun::Collection many_strings_required; - std::optional> many_strings_optional; + std::optional> many_strings_optional; float flattened_scalar; diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp index dfa57ac64b99..c0427f730358 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer21.hpp @@ -5,9 +5,9 @@ #include #include +#include #include #include -#include namespace arrow { class DataType; @@ -19,7 +19,7 @@ namespace rerun::datatypes { struct AffixFuzzer21 { rerun::half single_half; - std::vector many_halves; + rerun::Collection many_halves; public: AffixFuzzer21() = default; diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp index 00b6dfaf4be5..3c65bfafe941 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer3.hpp @@ -11,9 +11,9 @@ #include #include #include +#include #include #include -#include namespace arrow { class DataType; @@ -39,7 +39,7 @@ namespace rerun::datatypes { std::optional radians; - std::vector craziness; + rerun::Collection craziness; std::array fixed_size_shenanigans; @@ -68,7 +68,7 @@ namespace rerun::datatypes { AffixFuzzer3(const AffixFuzzer3& other) : _tag(other._tag) { switch (other._tag) { case detail::AffixFuzzer3Tag::craziness: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.craziness) TypeAlias(other._data.craziness); } break; case detail::AffixFuzzer3Tag::degrees: @@ -110,7 +110,7 @@ namespace rerun::datatypes { // has a trivial destructor } break; case detail::AffixFuzzer3Tag::craziness: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.craziness.~TypeAlias(); } break; case detail::AffixFuzzer3Tag::fixed_size_shenanigans: { @@ -138,11 +138,11 @@ namespace rerun::datatypes { return self; } - static AffixFuzzer3 craziness(std::vector craziness) { + static AffixFuzzer3 craziness(rerun::Collection craziness) { AffixFuzzer3 self; self._tag = detail::AffixFuzzer3Tag::craziness; new (&self._data.craziness) - std::vector(std::move(craziness)); + rerun::Collection(std::move(craziness)); return self; } @@ -173,7 +173,7 @@ namespace rerun::datatypes { } /// Return a pointer to craziness if the union is in that state, otherwise `nullptr`. - const std::vector* get_craziness() const { + const rerun::Collection* get_craziness() const { if (_tag == detail::AffixFuzzer3Tag::craziness) { return &_data.craziness; } else { diff --git a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp index 9f1760eadf4e..4c5ed09676f8 100644 --- a/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp +++ b/rerun_cpp/tests/generated/datatypes/affix_fuzzer4.hpp @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include namespace arrow { class DataType; @@ -35,9 +35,9 @@ namespace rerun::datatypes { union AffixFuzzer4Data { rerun::datatypes::AffixFuzzer3 single_required; - std::vector many_required; + rerun::Collection many_required; - std::optional> many_optional; + std::optional> many_optional; AffixFuzzer4Data() { std::memset(reinterpret_cast(this), 0, sizeof(AffixFuzzer4Data)); @@ -68,11 +68,12 @@ namespace rerun::datatypes { new (&_data.single_required) TypeAlias(other._data.single_required); } break; case detail::AffixFuzzer4Tag::many_required: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; new (&_data.many_required) TypeAlias(other._data.many_required); } break; case detail::AffixFuzzer4Tag::many_optional: { - using TypeAlias = std::optional>; + using TypeAlias = + std::optional>; new (&_data.many_optional) TypeAlias(other._data.many_optional); } break; case detail::AffixFuzzer4Tag::None: { @@ -105,11 +106,12 @@ namespace rerun::datatypes { _data.single_required.~TypeAlias(); } break; case detail::AffixFuzzer4Tag::many_required: { - using TypeAlias = std::vector; + using TypeAlias = rerun::Collection; _data.many_required.~TypeAlias(); } break; case detail::AffixFuzzer4Tag::many_optional: { - using TypeAlias = std::optional>; + using TypeAlias = + std::optional>; _data.many_optional.~TypeAlias(); } break; } @@ -128,22 +130,25 @@ namespace rerun::datatypes { return self; } - static AffixFuzzer4 many_required(std::vector many_required + static AffixFuzzer4 many_required( + rerun::Collection many_required ) { AffixFuzzer4 self; self._tag = detail::AffixFuzzer4Tag::many_required; new (&self._data.many_required) - std::vector(std::move(many_required)); + rerun::Collection(std::move(many_required)); return self; } static AffixFuzzer4 many_optional( - std::optional> many_optional + std::optional> many_optional ) { AffixFuzzer4 self; self._tag = detail::AffixFuzzer4Tag::many_optional; - new (&self._data.many_optional - ) std::optional>(std::move(many_optional)); + new (&self._data.many_optional) + std::optional>( + std::move(many_optional) + ); return self; } @@ -157,7 +162,7 @@ namespace rerun::datatypes { } /// Return a pointer to many_required if the union is in that state, otherwise `nullptr`. - const std::vector* get_many_required() const { + const rerun::Collection* get_many_required() const { if (_tag == detail::AffixFuzzer4Tag::many_required) { return &_data.many_required; } else { @@ -166,7 +171,7 @@ namespace rerun::datatypes { } /// Return a pointer to many_optional if the union is in that state, otherwise `nullptr`. - const std::optional>* get_many_optional( + const std::optional>* get_many_optional( ) const { if (_tag == detail::AffixFuzzer4Tag::many_optional) { return &_data.many_optional; diff --git a/tests/cpp/roundtrips/annotation_context/main.cpp b/tests/cpp/roundtrips/annotation_context/main.cpp index 89341820c679..abdde83f4774 100644 --- a/tests/cpp/roundtrips/annotation_context/main.cpp +++ b/tests/cpp/roundtrips/annotation_context/main.cpp @@ -8,7 +8,7 @@ int main(int, char** argv) { rec.log( "annotation_context", rerun::archetypes::AnnotationContext({ - rerun::datatypes::ClassDescription({1, "hello"}), + rerun::datatypes::ClassDescription(1, "hello"), rerun::datatypes::ClassDescription( {2, "world", rerun::datatypes::Rgba32(3, 4, 5)}, {{17, "head"}, {42, "shoulders"}},