diff options
author | David Robillard <d@drobilla.net> | 2007-02-24 18:01:27 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-02-24 18:01:27 +0000 |
commit | e3cdfeb3992ac47f25abc9678a211beda320e748 (patch) | |
tree | ef69fe428478fc6f1f2239a0c530a6c636297110 | |
parent | 9cb860865809097e8d6d1412ca95f0e37a79d851 (diff) | |
download | machina-e3cdfeb3992ac47f25abc9678a211beda320e748.tar.gz machina-e3cdfeb3992ac47f25abc9678a211beda320e748.tar.bz2 machina-e3cdfeb3992ac47f25abc9678a211beda320e748.zip |
Serialization of edges.
git-svn-id: http://svn.drobilla.net/lad/machina@335 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/engine/Edge.cpp | 63 | ||||
-rw-r--r-- | src/engine/Machine.cpp | 15 | ||||
-rw-r--r-- | src/engine/Makefile.am | 1 | ||||
-rw-r--r-- | src/engine/Node.cpp | 6 | ||||
-rw-r--r-- | src/engine/machina/Edge.hpp | 5 |
5 files changed, 84 insertions, 6 deletions
diff --git a/src/engine/Edge.cpp b/src/engine/Edge.cpp new file mode 100644 index 0000000..16bc202 --- /dev/null +++ b/src/engine/Edge.cpp @@ -0,0 +1,63 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave Robillard <http://drobilla.net> + * + * Machina is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Machina is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <raul/RDFWriter.h> +#include "machina/Node.hpp" +#include "machina/Edge.hpp" + +namespace Machina { + + +void +Edge::write_state(Raul::RDFWriter& writer) +{ + using Raul::RdfId; + + if (!_id) + set_id(writer.blank_id()); + + writer.write(_id, + RdfId(RdfId::RESOURCE, "rdf:type"), + RdfId(RdfId::RESOURCE, "machina:Edge")); + + SharedPtr<Node> src = _src.lock(); + SharedPtr<Node> dst = _dst; + + if (!src || !dst) + return; + + if (!src->id()) + src->set_id(writer.blank_id()); + + if (!dst->id()) + dst->set_id(writer.blank_id()); + + writer.write(_id, + RdfId(RdfId::RESOURCE, "machina:tail"), + src->id()); + + writer.write(_id, + RdfId(RdfId::RESOURCE, "machina:head"), + dst->id()); + + writer.write(_id, + RdfId(RdfId::RESOURCE, "machina:probability"), + _probability.get()); +} + + +} // namespace Machina diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index a2d650d..2d3358b 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -218,14 +218,23 @@ Machine::write_state(Raul::RDFWriter& writer) RdfId(RdfId::RESOURCE, "machina:Machine")); for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) { - if ( ! (*n)->id() ) - (*n)->set_id(writer.blank_id()); - + (*n)->write_state(writer); writer.write(RdfId(RdfId::RESOURCE, ""), RdfId(RdfId::RESOURCE, "machina:node"), (*n)->id()); + + for (Node::EdgeList::const_iterator e = (*n)->outgoing_edges().begin(); + e != (*n)->outgoing_edges().end(); ++e) { + + (*e)->write_state(writer); + + writer.write(RdfId(RdfId::RESOURCE, ""), + RdfId(RdfId::RESOURCE, "machina:edge"), + (*e)->id()); + } + } } diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index da594e8..d325788 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -8,6 +8,7 @@ libmachina_la_LIBADD = @RAUL_LIBS@ @JACK_LIBS@ @GLIBMM_LIBS@ libmachina_la_SOURCES = \ Node.cpp \ + Edge.cpp \ Machine.cpp \ Loader.h \ Loader.cpp \ diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp index 8bf9246..e44e448 100644 --- a/src/engine/Node.cpp +++ b/src/engine/Node.cpp @@ -120,6 +120,9 @@ Node::write_state(Raul::RDFWriter& writer) { using Raul::RdfId; + if (!_id) + set_id(writer.blank_id()); + writer.write(_id, RdfId(RdfId::RESOURCE, "rdf:type"), RdfId(RdfId::RESOURCE, "machina:Node")); @@ -130,8 +133,7 @@ Node::write_state(Raul::RDFWriter& writer) for (Node::EdgeList::const_iterator e = _outgoing_edges.begin(); e != _outgoing_edges.end(); ++e) - std::cerr << "FIXME: write edge\n"; - + (*e)->write_state(writer); } diff --git a/src/engine/machina/Edge.hpp b/src/engine/machina/Edge.hpp index 8860abe..7f14788 100644 --- a/src/engine/machina/Edge.hpp +++ b/src/engine/machina/Edge.hpp @@ -23,6 +23,7 @@ #include <raul/WeakPtr.h> #include <raul/SharedPtr.h> #include <raul/DoubleBuffer.h> +#include <raul/Stateful.h> #include "types.hpp" #include "Action.hpp" @@ -30,7 +31,7 @@ namespace Machina { class Node; -class Edge : boost::noncopyable { +class Edge : public Raul::Stateful, public boost::noncopyable { public: Edge(WeakPtr<Node> src, SharedPtr<Node> dst) @@ -39,6 +40,8 @@ public: , _dst(dst) {} + void write_state(Raul::RDFWriter& writer); + WeakPtr<Node> src() { return _src; } SharedPtr<Node> dst() { return _dst; } |