52 using BaseArray::BaseArray;
55 template <
typename T, std::enable_if_t<std::is_base_of_v<BaseContentT, T>,
int> = 0>
56 [[nodiscard]] T
get(
size_t index)
const
59 return this->
operator[](index).template get<T>();
63 BaseContentT append(...) =
delete;
66 template <
typename T,
typename... Args>
67 T appendWithType(Args&&... args)
69 static_assert(std::is_base_of_v<BaseContentT, T>,
70 "ContentArray::appendWithType requires a compatible content base type.");
71 auto result = BaseArray::template append<T>(std::forward<Args>(args)...);
72 const BaseContentT& contentObject = result;
73 if (T::ContentTypeValue != contentObject.defaultType()) {
74 result.set_type(std::string(T::ContentTypeValue));
81 template <
typename T, std::enable_if_t<std::is_base_of_v<BaseContentT, T>,
int> = 0>
85 auto element = (*this)[index];
86 if (element.type() != T::ContentTypeValue) {
87 throw std::invalid_argument(
"Type mismatch: expected " + std::string(T::ContentTypeValue) +
88 ", got " + element.type());
90 return T(this->
root(), this->
pointer() / std::to_string(index));
Class for content arrays.
Definition ContentArray.h:49
T get(size_t index) const
Retrieve an element from the array as a specific type.
Definition ContentArray.h:56
T getTypedObject(size_t index) const
Constructs an object of type T if its type matches the JSON type.
Definition ContentArray.h:82