Skip to content

Commit

Permalink
add poc nose
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Jun 9, 2021
1 parent 4c08621 commit a032594
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ cmake-build-*/
# rubbish files
outputs/
rubbish.bin/
/assets/galaxy

# autogen files
zen/usr/
zen/autoload/
/zen/usr/
/zen/autoload/

# vim files
.*.swp
Expand Down
12 changes: 8 additions & 4 deletions POC/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
x: tpls.exe Makefile
x=nose

x: $x.exe Makefile
./$<
#gdb ./$< -ex r

d: $x.exe Makefile
gdb ./$< -ex r

%.exe: %.cpp Makefile
#g++ -std=c++17 -ggdb -gstabs+ -O0 -o $@ $<
g++ -std=c++17 -fopenmp -march=native -O3 -o $@ $<
g++ -std=c++17 -ggdb -gstabs+ -O0 -o $@ $<
#g++ -std=c++17 -fopenmp -march=native -O3 -o $@ $<
#clang++ -std=c++17 -march=native -O3 -o $@ $<
69 changes: 69 additions & 0 deletions POC/nose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <bits/stdc++.h>

using std::cout;
using std::endl;

using Id = std::string;

struct IObject {
virtual ~IObject() = default;
};

std::map<Id, std::unique_ptr<IObject>> objects;

struct INode {
std::map<Id, Id> inputs;
std::map<Id, Id> outputs;

virtual void apply() = 0;
};

std::map<Id, std::unique_ptr<INode>> nodes;

void addNode(Id const &id, std::unique_ptr<INode> &&node) {
nodes[id] = std::move(node);
}

void applyNode(Id const &id) {
nodes.at(id)->apply();
}

void setNodeInput(Id const &dn, Id const &ds, Id const &sn, Id const &ss) {
nodes.at(dn)->inputs[ds] = nodes.at(sn)->outputs.at(ss);
}

struct MyObject : IObject {
int i = 0;
};

struct MyNodeA : INode {
virtual void apply() override {
auto obj = std::make_unique<MyObject>();
objects["A::TestOut"] = std::move(obj);
outputs["Out0"] = "A::TestOut";
}
};

struct MyNodeB : INode {
virtual void apply() override {
auto obj = dynamic_cast<MyObject *>(objects.at(inputs.at("In0")).get());
auto newobj = std::make_unique<MyObject>();
newobj->i = obj->i + 1;
objects["B::TestOut"] = std::move(newobj);
outputs["Out0"] = "B::TestOut";
}
};

int main()
{
addNode("A", std::make_unique<MyNodeA>());
addNode("B", std::make_unique<MyNodeB>());
applyNode("A");
setNodeInput("B", "In0", "A", "Out0");
applyNode("B");
auto objid = nodes.at("B")->outputs["Out0"];
cout << "objid=" << objid << endl;
auto obj = dynamic_cast<MyObject *>(objects.at(objid).get());
cout << "obj->i=" << obj->i << endl;
return 0;
}
1 change: 0 additions & 1 deletion include/zen/zen.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ static IObject *getObject(std::string const &name);
struct INode {
using Ptr = std::unique_ptr<INode>;


ZENAPI INode();
ZENAPI ~INode();

Expand Down

0 comments on commit a032594

Please sign in to comment.