// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
// Based on "crates/store/re_types/definitions/rerun/archetypes/view_coordinates.fbs".

#include "view_coordinates.hpp"

#include "../collection_adapter_builtins.hpp"

namespace rerun::archetypes {
    ViewCoordinates ViewCoordinates::clear_fields() {
        auto archetype = ViewCoordinates();
        archetype.xyz = ComponentBatch::empty<rerun::components::ViewCoordinates>(Descriptor_xyz)
                            .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> ViewCoordinates::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(2);
        if (xyz.has_value()) {
            columns.push_back(xyz.value().partitioned(lengths_).value_or_throw());
        }
        columns.push_back(ComponentColumn::from_indicators<ViewCoordinates>(
                              static_cast<uint32_t>(lengths_.size())
        )
                              .value_or_throw());
        return columns;
    }

    Collection<ComponentColumn> ViewCoordinates::columns() {
        if (xyz.has_value()) {
            return columns(std::vector<uint32_t>(xyz.value().length(), 1));
        }
        return Collection<ComponentColumn>();
    }
} // namespace rerun::archetypes

namespace rerun {

    Result<Collection<ComponentBatch>> AsComponents<archetypes::ViewCoordinates>::as_batches(
        const archetypes::ViewCoordinates& archetype
    ) {
        using namespace archetypes;
        std::vector<ComponentBatch> cells;
        cells.reserve(2);

        if (archetype.xyz.has_value()) {
            cells.push_back(archetype.xyz.value());
        }
        {
            auto result = ComponentBatch::from_indicator<ViewCoordinates>();
            RR_RETURN_NOT_OK(result.error);
            cells.emplace_back(std::move(result.value));
        }

        return rerun::take_ownership(std::move(cells));
    }
} // namespace rerun
