<commit_before>//
//  Node.h
//  Cinder-Pipeline
//
//  Created by <NAME> on 19 Apr 2014.
//  Copyright 2014 Chorded Constructions. All rights reserved.
//

#pragma once

#include "cinder/gl/Texture.h"
#include "cinder/gl/GlslProg.h"
#include "cinder/gl/Fbo.h"
#include <boost/any.hpp>

namespace Cinder { namespace Pipeline {

using namespace ci;

typedef std::shared_ptr<class Node> NodeRef;
typedef std::shared_ptr<class NodePort> NodePortRef;
typedef std::shared_ptr<class FBOImage> FBOImageRef;

class FBOImage : public std::enable_shared_from_this<FBOImage> {
public:
    static FBOImageRef create(const gl::Fbo& fbo, const int attachment) {
        return FBOImageRef(new FBOImage(fbo, attachment))->shared_from_this();
    }

    inline gl::Fbo getFBO() const { return mFBO; }
    inline int getAttachment() const { return mAttachment; }

    gl::Texture& getTexture() { return mFBO.getTexture(mAttachment); }

    void bindTexture(const int textureUnit) { mFBO.bindTexture(textureUnit, mAttachment); }
    void unbindTexture() { mFBO.unbindTexture(); }

private:
    FBOImage(const gl::Fbo& fbo, const int attachment) : mFBO(fbo), mAttachment(attachment) {}
    
    gl::Fbo mFBO;
    int mAttachment;
};

enum class NodePortType {FBOImage, Texture, Bool, Float, Int, Vec2f, Vec4f, FilePath};

// TODO - min, max
class NodePort : public std::enable_shared_from_this<NodePort> {
public:
    static NodePortRef create(const std::string& key, const NodePortType type = NodePortType::FBOImage) {
        return NodePortRef(new NodePort(key, type, boost::any()))->shared_from_this();
    }
    static NodePortRef create(const std::string& key, const NodePortType type, boost::any valueDefault) {
        return NodePortRef(new NodePort(key, type, valueDefault))->shared_from_this();
    }

    inline std::string& getKey() { return mKey; }
    inline NodePortType getType() { return mType; }
    inline bool hasValueDefault() { return !mDefault.empty(); }
    inline boost::any getValueDefault() { return mDefault; }

private:
    NodePort(const std::string& key, const NodePortType type, boost::any valueDefault) : mKey(key), mType(type), mDefault(valueDefault) {}

    std::string mKey;
    NodePortType mType;
    boost::any mDefault;
};

static const std::string NodeInputPortKeyImage = "image";
static const std::string NodeOutputPortKeyImage = "image";

class Node : public std::enable_shared_from_this<Node>, public boost::noncopyable {
public:
    Node() {
        mOutputPorts = {
            NodePort::create(NodeOutputPortKeyImage, NodePortType::FBOImage),
        };
    }
    virtual ~Node() {}

    virtual std::string getName() const = 0;

    void setInputPorts(std::vector<NodePortRef>& ports) {
        mInputPorts = ports;

        // set default values
        for (const NodePortRef& port : mInputPorts) {
            if (!port->hasValueDefault()) {
                continue;
            }
            setValueForInputPortKey(port->getValueDefault(), port->getKey());
        }
    }
    inline std::vector<NodePortRef>& getInputPorts() { return mInputPorts; }
    inline std::vector<std::string> getInputPortKeys() {
        // TODO - replace with some sort of collect
        std::vector<std::string> keys;
        for (const NodePortRef& port : mInputPorts) {
            keys.push_back(port->getKey());
        }
        return keys;
    }

    inline std::vector<NodePortRef>& getOutputPorts() { return mOutputPorts; }

    inline std::vector<std::string> getInputPortKeysWithType(NodePortType type) {
        std::vector<std::string> filteredKeys;
        for (const NodePortRef& port : mInputPorts) {
            if (port->getType() != type) {
                continue;
            }
            filteredKeys.push_back(port->getKey());
        }
        return filteredKeys;
    }
    std::vector<std::string> getImageInputPortKeys() {
        return getInputPortKeysWithType(NodePortType::FBOImage);
    }

    NodePortRef getInputPortForKey(const std::string& key) {<commit_msg>reorder input and output definitions<commit_after>//
//  Node.h
//  Cinder-Pipeline
//
//  Created by <NAME> on 19 Apr 2014.
//  Copyright 2014 Chorded Constructions. All rights reserved.
//

#pragma once

#include "cinder/gl/Texture.h"
#include "cinder/gl/GlslProg.h"
#include "cinder/gl/Fbo.h"
#include <boost/any.hpp>

namespace Cinder { namespace Pipeline {

using namespace ci;

typedef std::shared_ptr<class Node> NodeRef;
typedef std::shared_ptr<class NodePort> NodePortRef;
typedef std::shared_ptr<class FBOImage> FBOImageRef;

class FBOImage : public std::enable_shared_from_this<FBOImage> {
public:
    static FBOImageRef create(const gl::Fbo& fbo, const int attachment) {
        return FBOImageRef(new FBOImage(fbo, attachment))->shared_from_this();
    }

    inline gl::Fbo getFBO() const { return mFBO; }
    inline int getAttachment() const { return mAttachment; }

    gl::Texture& getTexture() { return mFBO.getTexture(mAttachment); }

    void bindTexture(const int textureUnit) { mFBO.bindTexture(textureUnit, mAttachment); }
    void unbindTexture() { mFBO.unbindTexture(); }

private:
    FBOImage(const gl::Fbo& fbo, const int attachment) : mFBO(fbo), mAttachment(attachment) {}
    
    gl::Fbo mFBO;
    int mAttachment;
};

enum class NodePortType {FBOImage, Texture, Bool, Float, Int, Vec2f, Vec4f, FilePath};

// TODO - min, max
class NodePort : public std::enable_shared_from_this<NodePort> {
public:
    static NodePortRef create(const std::string& key, const NodePortType type = NodePortType::FBOImage) {
        return NodePortRef(new NodePort(key, type, boost::any()))->shared_from_this();
    }
    static NodePortRef create(const std::string& key, const NodePortType type, boost::any valueDefault) {
        return NodePortRef(new NodePort(key, type, valueDefault))->shared_from_this();
    }

    inline std::string& getKey() { return mKey; }
    inline NodePortType getType() { return mType; }
    inline bool hasValueDefault() { return !mDefault.empty(); }
    inline boost::any getValueDefault() { return mDefault; }

private:
    NodePort(const std::string& key, const NodePortType type, boost::any valueDefault) : mKey(key), mType(type), mDefault(valueDefault) {}

    std::string mKey;
    NodePortType mType;
    boost::any mDefault;
};

static const std::string NodeInputPortKeyImage = "image";
static const std::string NodeOutputPortKeyImage = "image";

class Node : public std::enable_shared_from_this<Node>, public boost::noncopyable {
public:
    Node() {
        mOutputPorts = {
            NodePort::create(NodeOutputPortKeyImage, NodePortType::FBOImage),
        };
    }
    virtual ~Node() {}

    virtual std::string getName() const = 0;

    void setInputPorts(std::vector<NodePortRef>& ports) {
        mInputPorts = ports;

        // set default values
        for (const NodePortRef& port : mInputPorts) {
            if (!port->hasValueDefault()) {
                continue;
            }
            setValueForInputPortKey(port->getValueDefault(), port->getKey());
        }
    }
    inline std::vector<NodePortRef>& getInputPorts() { return mInputPorts; }
    inline std::vector<NodePortRef>& getOutputPorts() { return mOutputPorts; }

    inline std::vector<std::string> getInputPortKeys() {
        // TODO - replace with some sort of collect
        std::vector<std::string> keys;
        for (const NodePortRef& port : mInputPorts) {
            keys.push_back(port->getKey());
        }
        return keys;
    }
    inline std::vector<std::string> getInputPortKeysWithType(NodePortType type) {
        std::vector<std::string> filteredKeys;
        for (const NodePortRef& port : mInputPorts) {
            if (port->getType() != type) {
                continue;
            }
            filteredKeys.push_back(port->getKey());
        }
        return filteredKeys;
    }
    std::vector<std::string> getImageInputPortKeys() {
        return getInputPortKeysWithType(NodePortType::FBOImage);
    }

    NodePortRef getInputPortForKey(const std::string& key) {
{'fraction_non_alphanumeric': 0.1215510812826249, 'fraction_numerical': 0.003231419338801889, 'mean_word_length': 3.5207865168539327, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7405120', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2463, 'n_words': 582}