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

#include "view_contents.hpp"

#include "../../collection_adapter_builtins.hpp"

namespace rerun::blueprint::archetypes {
    ViewContents ViewContents::clear_fields() {
        auto archetype = ViewContents();
        archetype.query =
            ComponentBatch::empty<rerun::blueprint::components::QueryExpression>(Descriptor_query)
                .value_or_throw();
        return archetype;
    }

    Collection<ComponentColumn> ViewContents::columns(const Collection<uint32_t>& lengths_) {
        std::vector<ComponentColumn> columns;
        columns.reserve(1);
        if (query.has_value()) {
            columns.push_back(query.value().partitioned(lengths_).value_or_throw());
        }
        return columns;
    }

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

namespace rerun {

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

        if (archetype.query.has_value()) {
            cells.push_back(archetype.query.value());
        }

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