MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ view()

template<typename T >
auto MayaFlux::Kakshya::DataAccess::view ( ) const

Get explicit typed view of data.

Template Parameters
TView type (glm::vec3, double, float, etc.)
Returns
Span-like view of data as type T
Note
If type conversion is needed, the view remains valid for the lifetime of this DataAccess object. Multiple calls with the same type reuse the cached conversion.

Definition at line 269 of file DataAccess.hpp.

270{
271 if constexpr (GlmType<T>) {
272 validate_structured_access<T>();
273
274 return std::visit([&](auto& vec) -> StructuredView<T> {
275 using StorageType = typename std::decay_t<decltype(vec)>::value_type;
276 using ComponentType = glm_component_type<T>;
277 constexpr size_t components = glm_component_count<T>();
278
279 size_t required_components = m_dimensions[0].size * components;
280 if (vec.size() < required_components) {
281 error<std::runtime_error>(
284 std::source_location::current(),
285 "Insufficient data: need {} elements of type {} but have {} elements of type {}",
286 m_dimensions[0].size,
287 typeid(T).name(),
288 vec.size() / components,
289 typeid(StorageType).name());
290 }
291
292 if constexpr (std::is_same_v<StorageType, ComponentType>) {
293 return StructuredView<T>(vec.data(), m_dimensions[0].size);
294 } else if constexpr (std::is_convertible_v<StorageType, ComponentType>) {
295 size_t required_bytes = vec.size() * sizeof(ComponentType);
296 void* cache_ptr = ensure_conversion_cache<ComponentType>(required_bytes);
297
298 ComponentType* cache_data = static_cast<ComponentType*>(cache_ptr);
299 std::ranges::transform(vec, cache_data,
300 [](auto val) { return static_cast<ComponentType>(val); });
301
302 return StructuredView<T>(cache_data, m_dimensions[0].size);
303 } else {
304 error<std::invalid_argument>(
307 std::source_location::current(),
308 "Cannot convert storage type {} to component type {}",
309 typeid(StorageType).name(),
310 typeid(ComponentType).name());
311 }
312 },
313 m_variant);
314
315 } else if constexpr (std::is_arithmetic_v<T>) {
316 return create_scalar_view<T>();
317
318 } else {
319 static_assert(always_false_v<T>,
320 "Unsupported view type. Use glm types or arithmetic types (double, float, int, etc.)");
321 }
322}
const std::vector< DataDimension > & m_dimensions
@ Runtime
General runtime operations (default fallback)
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.

References MayaFlux::Journal::Kakshya, m_dimensions, m_variant, and MayaFlux::Journal::Runtime.

Referenced by MayaFlux::Buffers::download_audio_from_gpu(), MayaFlux::Buffers::upload_from_view(), and MayaFlux::Buffers::upload_structured_view().

+ Here is the caller graph for this function: