tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
object.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _TINYPBRT_OBJECT_HPP_
3#define _TINYPBRT_OBJECT_HPP_
4
6
8
10
11namespace tpbrt {
21 struct object : detail::wrapper<object, tpbrt_object_t> {
23 using wrapper::wrapper;
24
26 [[nodiscard]] constexpr string name() const noexcept { return _native->name; }
27
29 [[nodiscard]] constexpr shapes_list children() const noexcept { return _native->children; }
30
32 [[nodiscard]] constexpr auto begin() const noexcept { return children().begin(); }
33
35 [[nodiscard]] constexpr auto end() const noexcept { return children().end(); }
36
38 [[nodiscard]] constexpr object_idx_t idx() const noexcept { return _native->idx; }
39
41 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(name(), children(), idx()); }
42 };
43
48 struct object_handle : detail::wrapper<object_handle, tpbrt_object_handle_t> {
50 using wrapper::wrapper;
51
53 [[nodiscard]] constexpr object_idx_t object_idx() const noexcept { return _native->object_idx; }
54
56 [[nodiscard]] constexpr auto reflect() const noexcept { return std::make_tuple(object_idx()); }
57 };
58
65 struct objects_list : array<tpbrt_objects_list_t, object, &tpbrt_objects_list_t::objects> {
67 using array::array;
68
70 using array::at;
71
73 using array::operator[];
74
76 [[nodiscard]] result<element_type> at(const object_handle handle) const noexcept {
77 return detail::find_in<element_type, tpbrt_object_t>(tpbrt_get_object_by_handle, _native, handle.native());
78 }
79
81 [[nodiscard]] result<element_type> at(const std::string_view name) const noexcept {
82 return detail::find_in<element_type, tpbrt_object_t>(tpbrt_get_object_by_name, _native,
83 detail::to_native_string(name));
84 }
85
87 [[nodiscard]] result<element_type> operator[](const object_handle handle) const noexcept { return at(handle); }
88
90 [[nodiscard]] result<element_type> operator[](const std::string_view name) const noexcept { return at(name); }
91 };
92
100 [[nodiscard]] inline result<object> get_object(const objects_list list, const object_handle handle) noexcept {
101 return list.at(handle);
102 }
103
111 [[nodiscard]] inline result<object> get_object(const objects_list list, const std::string_view name) noexcept {
112 return list.at(name);
113 }
114} // namespace tpbrt
115#endif // _TINYPBRT_OBJECT_HPP_
tpbrt_object_idx_t object_idx_t
Object index type.
Definition fwd.hpp:293
result< object > get_object(const objects_list list, const object_handle handle) noexcept
Returns object to which handle is provided.
Definition object.hpp:100
tpbrt_error_t tpbrt_get_object_by_name(const tpbrt_objects_list_t *objects, tpbrt_string_t name, const tpbrt_object_t **object)
Returns pointer to object with given name.
tpbrt_error_t tpbrt_get_object_by_handle(const tpbrt_objects_list_t *objects, tpbrt_object_handle_t handle, const tpbrt_object_t **object)
Returns pointer to object to which handle is provided.
Definition accelerator.hpp:14
Generic C++ array view with type conversion (a non owning view on memory owned by the C library).
Definition common.hpp:448
constexpr iterator end() const noexcept
Returns end iterator.
Definition common.hpp:507
constexpr iterator begin() const noexcept
Returns begin iterator.
Definition common.hpp:501
constexpr result< element_type > at(const size_t index) const noexcept
Returns element on given index or error::INDEX_OUT_OF_RANGE.
Definition common.hpp:519
C++ wrapper for tpbrt_object_handle_t.
Definition object.hpp:48
constexpr object_idx_t object_idx() const noexcept
Returns object_idx value.
Definition object.hpp:53
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition object.hpp:56
C++ wrapper for tpbrt_object_t.
Definition object.hpp:21
constexpr shapes_list children() const noexcept
Returns children value.
Definition object.hpp:29
constexpr auto end() const noexcept
Returns end iterator for children.
Definition object.hpp:35
constexpr string name() const noexcept
Returns name value.
Definition object.hpp:26
constexpr auto begin() const noexcept
Returns begin iterator for children.
Definition object.hpp:32
constexpr object_idx_t idx() const noexcept
Returns idx value.
Definition object.hpp:38
constexpr auto reflect() const noexcept
Conversion to tuple.
Definition object.hpp:41
C++ wrapper for tpbrt_objects_list_t.
Definition object.hpp:65
result< element_type > at(const std::string_view name) const noexcept
Returns object with given name.
Definition object.hpp:81
result< element_type > operator[](const std::string_view name) const noexcept
Returns object with given name.
Definition object.hpp:90
result< element_type > at(const object_handle handle) const noexcept
Returns object pointed by given handle.
Definition object.hpp:76
result< element_type > operator[](const object_handle handle) const noexcept
Returns object pointed by given handle.
Definition object.hpp:87
Result of an operation: either a value or an error code (similar to C++23 std::expected).
Definition error.hpp:165
C++ wrapper for tpbrt_shapes_list_t.
Definition shape.hpp:511