Skip to content

Commit

Permalink
Switch inputs/properties/buffers to use ordered maps, to retain order…
Browse files Browse the repository at this point in the history
…ing on export
  • Loading branch information
ideoforms committed Jan 11, 2024
1 parent 5979770 commit a0ddfea
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
13 changes: 6 additions & 7 deletions source/include/signalflow/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

namespace signalflow
Expand Down Expand Up @@ -245,10 +244,10 @@ class Node
virtual float get_value();
virtual void set_value(float value);

std::unordered_map<std::string, NodeRef *> get_inputs();
std::map<std::string, NodeRef *> get_inputs();
std::set<std::pair<Node *, std::string>> get_outputs();
std::unordered_map<std::string, PropertyRef *> get_properties();
std::unordered_map<std::string, BufferRef *> get_buffers();
std::map<std::string, PropertyRef *> get_properties();
std::map<std::string, BufferRef *> get_buffers();

protected:
/*------------------------------------------------------------------------
Expand Down Expand Up @@ -335,7 +334,7 @@ class Node
* they can be populated when the node is instantiated, such as from
* a graph of NodeDefs.
*-----------------------------------------------------------------------*/
std::unordered_map<std::string, NodeRef *> inputs;
std::map<std::string, NodeRef *> inputs;

/*------------------------------------------------------------------------
* Set of outputs.
Expand All @@ -358,13 +357,13 @@ class Node
* Similar to `inputs`, each property actually points to a local
* PropertyRef field which must be separately allocated on the object.
*-----------------------------------------------------------------------*/
std::unordered_map<std::string, PropertyRef *> properties;
std::map<std::string, PropertyRef *> properties;

/*------------------------------------------------------------------------
* Buffers are distinct from parameters, pointing to a fixed
* area of sample storage that must be non-null.
*-----------------------------------------------------------------------*/
std::unordered_map<std::string, BufferRef *> buffers;
std::map<std::string, BufferRef *> buffers;

/*------------------------------------------------------------------------
* Pointer to the Graph that this node is a part of.
Expand Down
14 changes: 7 additions & 7 deletions source/include/signalflow/patch/patch-node-spec.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <map>
#include <signalflow/core/property.h>
#include <string>
#include <unordered_map>

namespace signalflow
{
Expand Down Expand Up @@ -30,15 +30,15 @@ class PatchNodeSpec
std::string get_input_name();
void set_input_name(std::string name);

std::unordered_map<std::string, PatchNodeSpec *> get_inputs();
std::unordered_map<std::string, std::string> get_buffer_inputs();
std::map<std::string, PatchNodeSpec *> get_inputs();
std::map<std::string, std::string> get_buffer_inputs();

void add_input(std::string name, PatchNodeSpec *def);
void add_input(std::string name, float value);
void add_buffer_input(std::string patch_input_name,
std::string node_input_name);

std::unordered_map<std::string, PropertyRef> get_properties();
std::map<std::string, PropertyRef> get_properties();
void add_property(std::string name, PropertyRef property);

private:
Expand All @@ -47,9 +47,9 @@ class PatchNodeSpec
float value = 0.0;
bool is_constant = false;
std::string input_name;
std::unordered_map<std::string, PatchNodeSpec *> inputs;
std::unordered_map<std::string, std::string> buffer_inputs;
std::unordered_map<std::string, PropertyRef> properties;
std::map<std::string, PatchNodeSpec *> inputs;
std::map<std::string, std::string> buffer_inputs;
std::map<std::string, PropertyRef> properties;
};

}
8 changes: 4 additions & 4 deletions source/include/signalflow/patch/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Patch
public:
Patch();
Patch(PatchSpecRef patchspec);
Patch(PatchSpecRef patchspec, std::unordered_map<std::string, NodeRef> params);
Patch(PatchSpecRef patchspec, std::map<std::string, NodeRef> params);
Patch(std::string name);
virtual ~Patch();

Expand Down Expand Up @@ -107,7 +107,7 @@ class Patch
*
* @returns The input map.
*--------------------------------------------------------------------------------*/
std::unordered_map<std::string, NodeRef> get_inputs();
std::map<std::string, NodeRef> get_inputs();

NodeRef add_input(std::string name, sample default_value = 0);
NodeRef add_input(std::string name, NodeRef value);
Expand Down Expand Up @@ -157,8 +157,8 @@ class Patch
private:
std::string name;
NodeRef output = nullptr;
std::unordered_map<std::string, NodeRef> inputs;
std::unordered_map<std::string, BufferRef> buffer_inputs;
std::map<std::string, NodeRef> inputs;
std::map<std::string, BufferRef> buffer_inputs;
std::set<NodeRef> nodes;

bool auto_free;
Expand Down
5 changes: 2 additions & 3 deletions source/src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
#include <iostream>
#include <regex>
#include <stdlib.h>
#include <unordered_map>

namespace signalflow
{

std::unordered_map<std::string, std::unordered_map<std::string, std::string>> parse_config(std::istream &stream)
std::map<std::string, std::map<std::string, std::string>> parse_config(std::istream &stream)
{
std::string line;
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> sections;
std::map<std::string, std::map<std::string, std::string>> sections;

std::string current_section;

Expand Down
6 changes: 3 additions & 3 deletions source/src/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void Node::set_state(signalflow_node_state_t state)
// Inputs and outputs
////////////////////////////////////////////////////////////////////////////////

std::unordered_map<std::string, NodeRef *> Node::get_inputs()
std::map<std::string, NodeRef *> Node::get_inputs()
{
return this->inputs;
}
Expand All @@ -297,12 +297,12 @@ std::set<std::pair<Node *, std::string>> Node::get_outputs()
return this->outputs;
}

std::unordered_map<std::string, PropertyRef *> Node::get_properties()
std::map<std::string, PropertyRef *> Node::get_properties()
{
return this->properties;
}

std::unordered_map<std::string, BufferRef *> Node::get_buffers()
std::map<std::string, BufferRef *> Node::get_buffers()
{
return this->buffers;
}
Expand Down
6 changes: 3 additions & 3 deletions source/src/patch/patch-node-spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ void PatchNodeSpec::add_buffer_input(std::string patch_input_name, std::string n
this->buffer_inputs[patch_input_name] = node_input_name;
}

std::unordered_map<std::string, PatchNodeSpec *> PatchNodeSpec::get_inputs()
std::map<std::string, PatchNodeSpec *> PatchNodeSpec::get_inputs()
{
return this->inputs;
}

std::unordered_map<std::string, std::string> PatchNodeSpec::get_buffer_inputs()
std::map<std::string, std::string> PatchNodeSpec::get_buffer_inputs()
{
return this->buffer_inputs;
}
Expand All @@ -96,7 +96,7 @@ void PatchNodeSpec::add_property(std::string name, PropertyRef property)
this->properties[name] = property;
}

std::unordered_map<std::string, PropertyRef> PatchNodeSpec::get_properties()
std::map<std::string, PropertyRef> PatchNodeSpec::get_properties()
{
return this->properties;
}
Expand Down
4 changes: 2 additions & 2 deletions source/src/patch/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Patch::Patch(PatchSpecRef patchspec)
this->parsed = true;
}

Patch::Patch(PatchSpecRef patchspec, std::unordered_map<std::string, NodeRef> inputs)
Patch::Patch(PatchSpecRef patchspec, std::map<std::string, NodeRef> inputs)
: Patch(patchspec)
{
for (auto input : inputs)
Expand Down Expand Up @@ -339,7 +339,7 @@ std::set<NodeRef> Patch::get_nodes()
return this->nodes;
}

std::unordered_map<std::string, NodeRef> Patch::get_inputs()
std::map<std::string, NodeRef> Patch::get_inputs()
{
return this->inputs;
}
Expand Down
2 changes: 1 addition & 1 deletion source/src/python/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void init_python_node(py::module &m)
.def("set_value", &Node::set_value, "value"_a, R"pbdoc(Set the node's current value. Only applicable to Constant nodes.)pbdoc")
.def_property_readonly(
"inputs", [](Node &node) {
std::unordered_map<std::string, NodeRef> inputs(node.get_inputs().size());
std::map<std::string, NodeRef> inputs;
for (auto input : node.get_inputs())
{
inputs[input.first] = *(input.second);
Expand Down
2 changes: 1 addition & 1 deletion source/src/python/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void init_python_patch(py::module &m)
/*--------------------------------------------------------------------------------
* Constructors
*-------------------------------------------------------------------------------*/
.def(py::init<PatchSpecRef, std::unordered_map<std::string, NodeRef>>())
.def(py::init<PatchSpecRef, std::map<std::string, NodeRef>>())
.def(py::init<PatchSpecRef>())
.def(py::init<>())

Expand Down

0 comments on commit a0ddfea

Please sign in to comment.