Skip to content

Commit e159a4b

Browse files
committed
Temporary 'instance()' property of MetaClasses for singletons (but I
do not like it), fix for Graphite-in-blender demo: we need to be able to detect that we already have a SceneGraph (and reuse it).
1 parent 545f79e commit e159a4b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

plugins/OGF/gompy/interpreter/python_interpreter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ namespace OGF {
199199
PyDict_SetItemString(sys_modules, "gompy.gom", py_gom);
200200
PyDict_SetItemString(sys_modules, "gompy.types", py_meta_types);
201201
PyDict_SetItemString(sys_modules, "gompy.types.OGF", py_OGF);
202+
202203
return;
203204
}
204205

src/lib/OGF/gom/reflection/meta_class.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace OGF {
107107
if(!abstract) {
108108
set_factory(new FactoryMetaClass(this));
109109
}
110+
instance_ = nullptr;
110111
}
111112

112113
MetaClass::MetaClass(

src/lib/OGF/gom/reflection/meta_class.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ namespace OGF {
299299
*/
300300
virtual bool is_subclass_of(const MetaClass* other) const;
301301

302+
gom_properties:
303+
/**
304+
* \brief For singletons, returns instance
305+
* \return the unique instance or nullptr if not already created
306+
*/
307+
Object* get_instance() const {
308+
return instance_;
309+
}
310+
302311
public:
303312

304313
/**
@@ -455,6 +464,13 @@ namespace OGF {
455464
*/
456465
std::string get_doc() const override;
457466

467+
/**
468+
* \brief For singletons, sets instance
469+
* \param[in] object the unique instance or nullptr
470+
*/
471+
void set_instance(Object* object) {
472+
instance_ = object;
473+
}
458474

459475
protected:
460476

@@ -525,6 +541,7 @@ namespace OGF {
525541
bool abstract_;
526542
Factory_var factory_;
527543
friend class ::OGF::MetaConstructor;
544+
Object* instance_; // For singletons
528545
};
529546

530547
/**

src/lib/OGF/scene_graph/types/scene_graph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ namespace OGF {
6969
application_(nullptr) {
7070
Grob::scene_graph_ = this;
7171
SceneGraphLibrary::instance()->set_scene_graph(this, transfer_ownership);
72+
Any value;
73+
value.set_value(this);
74+
meta_class()->set_instance(this);
7275
}
7376

7477
SceneGraph::~SceneGraph() {
78+
meta_class()->set_instance(nullptr);
7579
}
7680

7781
void SceneGraph::set_scene_graph_shader_manager(

0 commit comments

Comments
 (0)