MeshLib
 
Loading...
Searching...
No Matches
MRRenderWrapObject.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMesh/MRMeshFwd.h"
5
7{
8
9namespace detail
10{
11 // Need this helper base class to make sure the `subobject` is initialized before the render object, otherwise we get a crash.
12 template <typename ObjectType>
14 {
15 ObjectType subobject;
16 };
17
19 {
20 protected:
22 };
23}
24
25// The first template argument of `Wrapper` can inherit from this to know the object we're wrapping.
26template <std::derived_from<Object> ObjectType>
28{
29protected:
31public:
32 const ObjectType* target_ = nullptr;
33};
34
35// An `IRenderObject` that embeds a data model object and another render object in it.
36// The embedded render object points to the embedded data model object.
37template <typename ObjectType, typename RenderObjectType>
38class Wrapper : public detail::SubobjectStorage<ObjectType>, public RenderObjectType
39{
40public:
41 Wrapper( const VisualObject& object )
42 : RenderObjectType( detail::SubobjectStorage<ObjectType>::subobject )
43 {
44 if constexpr ( std::derived_from<ObjectType, detail::BasicWrapperTargetUntyped> )
45 this->subobject.target_ = &dynamic_cast<decltype(*this->subobject.target_)>( object );
46 }
47
48 Wrapper( const Wrapper& ) = delete;
49 Wrapper& operator=( const Wrapper& ) = delete;
50};
51
52} // namespace MR::RenderWrapObject
Definition MRRenderWrapObject.h:28
const ObjectType * target_
Definition MRRenderWrapObject.h:32
Definition MRRenderWrapObject.h:39
Wrapper(const VisualObject &object)
Definition MRRenderWrapObject.h:41
Wrapper & operator=(const Wrapper &)=delete
Wrapper(const Wrapper &)=delete
Visual Object.
Definition MRVisualObject.h:131
Definition MRRenderWrapObject.h:7
Definition MRRenderWrapObject.h:14
ObjectType subobject
Definition MRRenderWrapObject.h:15