From e3cdfeb3992ac47f25abc9678a211beda320e748 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 24 Feb 2007 18:01:27 +0000 Subject: Serialization of edges. git-svn-id: http://svn.drobilla.net/lad/machina@335 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Edge.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/engine/Machine.cpp | 15 ++++++++--- src/engine/Makefile.am | 1 + src/engine/Node.cpp | 6 +++-- src/engine/machina/Edge.hpp | 5 +++- 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 src/engine/Edge.cpp (limited to 'src/engine') 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 + * + * 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 +#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 src = _src.lock(); + SharedPtr 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 #include #include +#include #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 src, SharedPtr dst) @@ -39,6 +40,8 @@ public: , _dst(dst) {} + void write_state(Raul::RDFWriter& writer); + WeakPtr src() { return _src; } SharedPtr dst() { return _dst; } -- cgit v1.2.1