#51 Better node system

Closed
opened 7 years ago by caryoscelus · 2 comments
  • more compile-time checks
  • better syntax
  • better runtime performance

Something like this:

class Add : public TypedNode<double, Only<double>, Only<double>> {
    NODE_PROPERTIES(a, b)
    NODE_PROPERTY(a, 0)
    NODE_PROPERTY(b, 0)
public:
    double get(shared_ptr<Context> ctx) const {
        return a(ctx)+b(ctx);
    }
};
- more compile-time checks - better syntax - better runtime performance Something like this: ```c++ class Add : public TypedNode<double, Only<double>, Only<double>> { NODE_PROPERTIES(a, b) NODE_PROPERTY(a, 0) NODE_PROPERTY(b, 0) public: double get(shared_ptr<Context> ctx) const { return a(ctx)+b(ctx); } }; ```
caryoscelus commented 7 years ago
Owner

Better yet:

template <class Self, typename... Args>
class LinkStorage {
private:
    // guaranteed to be unique per Self
    static map<string,size_t>& name_map() {
        map<string,size_t> _instance;
        return _instance;
    }
public:
    static void register_name(string const& name) {
        ...
    }
};

template <class Self, typename Result, typename... Args>
class Node;

class Add : NODE(Add, double, Only<double>, Only<double>) {
    NODE_PROPERTIES(a, b) // using variadic macro expansion

public:
    double get(shared_ptr<Context> ctx) const override {
        return get_a(ctx) + get_b(ctx);
    }
};
Better yet: ```c++ template <class Self, typename... Args> class LinkStorage { private: // guaranteed to be unique per Self static map<string,size_t>& name_map() { map<string,size_t> _instance; return _instance; } public: static void register_name(string const& name) { ... } }; template <class Self, typename Result, typename... Args> class Node; class Add : NODE(Add, double, Only<double>, Only<double>) { NODE_PROPERTIES(a, b) // using variadic macro expansion public: double get(shared_ptr<Context> ctx) const override { return get_a(ctx) + get_b(ctx); } }; ```
caryoscelus referenced this issue from a commit 6 years ago
caryoscelus commented 6 years ago
Owner

Basic system is in place, though some enhancements to API are still expected.

Basic system is in place, though some enhancements to API are still expected.
Sign in to join this conversation.
Loading...
Cancel
Save
There is no content yet.