MeshLib C++ Docs
Loading...
Searching...
No Matches
MRObjectFactory.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRBindingMacros.h"
5#include <memory>
6#include <string>
7
8namespace MR
9{
12
13
16
18MRMESH_API std::shared_ptr<Object> createObject( const std::string & className );
19
21#define MR_ADD_CLASS_FACTORY( className ) \
22 static MR::ObjectFactory<className> className##_Factory_{ #className };
23
24using ObjectMakerFunc = std::shared_ptr<Object>();
25
27{
28public:
29 MR_BIND_IGNORE MRMESH_API ObjectFactoryBase( std::string className, ObjectMakerFunc * creator );
30 MRMESH_API ~ObjectFactoryBase();
31
32private:
33 std::string className_;
34};
35
36template<typename T>
38{
39public:
40 static_assert( std::is_base_of_v<Object, T>, "MR::Object is not base of T" );
41
42 ObjectFactory( std::string className )
43 : ObjectFactoryBase( std::move( className ),
44 []() { return std::static_pointer_cast<Object>( std::make_shared<T>() ); } )
45 { }
46};
47
49
50}
Definition MRObjectFactory.h:27
Definition MRObjectFactory.h:38
MRMESH_API std::shared_ptr< Object > createObject(const std::string &className)
the function to create new object instance by registered class name
ObjectFactory(std::string className)
Definition MRObjectFactory.h:42
std::shared_ptr< Object >() ObjectMakerFunc
Definition MRObjectFactory.h:24
MRMESH_API ~ObjectFactoryBase()
MR_BIND_IGNORE MRMESH_API ObjectFactoryBase(std::string className, ObjectMakerFunc *creator)
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
only for bindings generation
Definition MRCameraOrientationPlugin.h:8