Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rerun::Collection almost everywhere we'd use std::vector before #4247

Merged
merged 24 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
159b9de
Remove serialize method from rerun::Container
Wumpf Nov 14, 2023
3bf670b
fix docs for NoAsComponentsFor
Wumpf Nov 14, 2023
a82ae18
Make all std::vector fields in the Rerun api be of type rerun::Collec…
Wumpf Nov 15, 2023
af3b802
todo notes so I don't forget to add tests
Wumpf Nov 15, 2023
c34750e
clean up new type trait header a bit
Wumpf Nov 16, 2023
fd4da6e
test for converting adapters, add single element converting adapter
Wumpf Nov 16, 2023
3fddded
test for and fix subtleties about moves & copies
Wumpf Nov 16, 2023
be51c4a
add tests for move/copy on convertible
Wumpf Nov 16, 2023
bea6c5e
added test for copy/move assignment/construction of collections
Wumpf Nov 16, 2023
26e5263
add test for to_vector
Wumpf Nov 16, 2023
8a71e69
drop todo note, not gonna do this any time soon
Wumpf Nov 16, 2023
48f261c
fix extra vector on 3d batch examples
Wumpf Nov 16, 2023
f365409
Merge remote-tracking branch 'origin/main' into andreas/cpp/rerun-col…
Wumpf Nov 16, 2023
1ede9a8
typo fixes
Wumpf Nov 16, 2023
3e72d9f
fix missing header (gcc compile fail)
Wumpf Nov 16, 2023
1cb0f45
even more GCC fixes
Wumpf Nov 16, 2023
7b0a280
try to work around gcc complaints
Wumpf Nov 16, 2023
2b796aa
msvc fix
Wumpf Nov 17, 2023
57e8c0f
fix broken asset3d
Wumpf Nov 17, 2023
481f0fb
rename _data to data_ for arguments
Wumpf Nov 17, 2023
e6c3bf4
fix dangerous assignment with placement new
Wumpf Nov 17, 2023
469e2d8
use iterator constructor of std vector instead of insert
Wumpf Nov 17, 2023
a49c544
Merge remote-tracking branch 'origin/main' into andreas/cpp/rerun-col…
Wumpf Nov 17, 2023
825bf79
post merge codegen
Wumpf Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 43 additions & 23 deletions crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions docs/code-examples/line_strip2d_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ int main() {
const auto rec = rerun::RecordingStream("rerun_example_line_strip2d");
rec.spawn().exit_on_failure();

std::vector<rerun::Vec2D> strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}};
std::vector<rerun::Vec2D> strip2 =
rerun::Collection<rerun::Vec2D> strip1 = {{0.f, 0.f}, {2.f, 1.f}, {4.f, -1.f}, {6.f, 0.f}};
rerun::Collection<rerun::Vec2D> 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",
Expand Down
4 changes: 2 additions & 2 deletions docs/code-examples/line_strip3d_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ int main() {
const auto rec = rerun::RecordingStream("rerun_example_line_strip3d");
rec.spawn().exit_on_failure();

std::vector<rerun::Vec3D> strip1 = {
rerun::Collection<rerun::Vec3D> 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<rerun::Vec3D> strip2 = {
rerun::Collection<rerun::Vec3D> strip2 = {
{0.f, 0.f, 0.f},
{0.f, 0.f, 1.f},
{1.f, 0.f, 0.f},
Expand Down
2 changes: 2 additions & 0 deletions rerun_cpp/docs/writing_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
13 changes: 6 additions & 7 deletions rerun_cpp/src/rerun/archetypes/annotation_context.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rerun_cpp/src/rerun/archetypes/annotation_context.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 35 additions & 17 deletions rerun_cpp/src/rerun/archetypes/arrows3d.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rerun_cpp/src/rerun/archetypes/arrows3d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions rerun_cpp/src/rerun/archetypes/asset3d.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions rerun_cpp/src/rerun/archetypes/asset3d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading