PeriDyno 1.0.0
Loading...
Searching...
No Matches
NodeFactory.cpp
Go to the documentation of this file.
1#include "NodeFactory.h"
2
3namespace dyno
4{
5 std::atomic<NodeFactory*> NodeFactory::pInstance;
6 std::mutex NodeFactory::mMutex;
7
8 //Thread-safe singleton mode
10 {
11 NodeFactory* ins = pInstance.load(std::memory_order_acquire);
12 if (!ins) {
13 std::lock_guard<std::mutex> tLock(mMutex);
14 ins = pInstance.load(std::memory_order_relaxed);
15 if (!ins) {
16 ins = new NodeFactory();
17 pInstance.store(ins, std::memory_order_release);
18 }
19 }
20
21 return ins;
22 }
23
24 void NodeGroup::addAction(std::string caption, std::string icon, std::function<std::shared_ptr<Node>()> act)
25 {
26 mActions.push_back(std::make_shared<NodeAction>(caption, icon, act));
27 }
28
29 void NodeGroup::addAction(std::shared_ptr<NodeAction> nAct)
30 {
31 mActions.push_back(nAct);
32 }
33
34 bool NodePage::hasGroup(std::string name)
35 {
36 return mGroups.find(name) != mGroups.end();
37 }
38
39 std::shared_ptr<dyno::NodeGroup> NodePage::addGroup(std::string name)
40 {
41 if (mGroups.find(name) == mGroups.end())
42 {
43 mGroups[name] = std::make_shared<NodeGroup>(name);
44 }
45
46 return mGroups[name];
47 }
48
49 bool NodeFactory::hasPage(std::string name)
50 {
51 return mPages.find(name) != mPages.end();
52 }
53
54 std::shared_ptr<NodePage> NodeFactory::addPage(std::string name, std::string icon)
55 {
56 if (mPages.find(name) == mPages.end())
57 {
58 mPages[name] = std::make_shared<NodePage>(name, icon);
59 }
60
61 return mPages[name];
62 }
63}
NodeFactory()=default
static NodeFactory * instance()
static std::atomic< NodeFactory * > pInstance
std::shared_ptr< NodePage > addPage(std::string name, std::string icon)
bool hasPage(std::string name)
static std::mutex mMutex
std::map< std::string, std::shared_ptr< NodePage > > mPages
std::vector< std::shared_ptr< NodeAction > > mActions
Definition NodeFactory.h:68
std::string caption()
Definition NodeFactory.h:63
void addAction(std::shared_ptr< NodeAction > nAct)
std::map< std::string, std::shared_ptr< NodeGroup > > mGroups
Definition NodeFactory.h:94
bool hasGroup(std::string name)
std::shared_ptr< NodeGroup > addGroup(std::string name)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25