summaryrefslogtreecommitdiffstats
path: root/src/AtomReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AtomReader.cpp')
-rw-r--r--src/AtomReader.cpp87
1 files changed, 52 insertions, 35 deletions
diff --git a/src/AtomReader.cpp b/src/AtomReader.cpp
index 74476b83..df9a8e4b 100644
--- a/src/AtomReader.cpp
+++ b/src/AtomReader.cpp
@@ -14,14 +14,14 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ingen/Atom.hpp"
#include "ingen/AtomReader.hpp"
+
+#include "ingen/Atom.hpp"
#include "ingen/Interface.hpp"
#include "ingen/Log.hpp"
#include "ingen/Message.hpp"
#include "ingen/Properties.hpp"
#include "ingen/Resource.hpp"
-#include "ingen/Status.hpp"
#include "ingen/URI.hpp"
#include "ingen/URIMap.hpp"
#include "ingen/URIs.hpp"
@@ -30,14 +30,15 @@
#include "lv2/atom/util.h"
#include "raul/Path.hpp"
-#include <boost/optional/optional.hpp>
-
#include <cstdint>
#include <cstring>
+#include <optional>
#include <string>
namespace ingen {
+enum class Status;
+
AtomReader::AtomReader(URIMap& map, URIs& uris, Log& log, Interface& iface)
: _map(map)
, _uris(uris)
@@ -71,52 +72,57 @@ AtomReader::get_props(const LV2_Atom_Object* obj,
const Atom type(sizeof(int32_t), _uris.atom_URID, &obj->body.otype);
props.emplace(_uris.rdf_type, type);
}
- LV2_ATOM_OBJECT_FOREACH(obj, p) {
+ LV2_ATOM_OBJECT_FOREACH (obj, p) {
Atom val;
get_atom(&p->value, val);
props.emplace(URI(_map.unmap_uri(p->key)), val);
}
}
-boost::optional<URI>
+std::optional<URI>
AtomReader::atom_to_uri(const LV2_Atom* atom)
{
if (!atom) {
- return boost::optional<URI>();
- } else if (atom->type == _uris.atom_URI) {
+ return {};
+ }
+
+ if (atom->type == _uris.atom_URI) {
const char* str = static_cast<const char*>(LV2_ATOM_BODY_CONST(atom));
if (URI::is_valid(str)) {
return URI(str);
- } else {
- _log.warn("Invalid URI <%1%>\n", str);
}
+
+ _log.warn("Invalid URI <%1%>\n", str);
} else if (atom->type == _uris.atom_Path) {
const char* str = static_cast<const char*>(LV2_ATOM_BODY_CONST(atom));
if (!strncmp(str, "file://", 5)) {
return URI(str);
- } else {
- return URI(std::string("file://") + str);
}
- } else if (atom->type == _uris.atom_URID) {
+
+ return URI(std::string("file://") + str);
+ }
+
+ if (atom->type == _uris.atom_URID) {
const char* str =
_map.unmap_uri(reinterpret_cast<const LV2_Atom_URID*>(atom)->body);
if (str) {
return URI(str);
- } else {
- _log.warn("Unknown URID %1%\n", str);
}
+
+ _log.warn("Unknown URID %1%\n", str);
}
- return boost::optional<URI>();
+
+ return {};
}
-boost::optional<raul::Path>
+std::optional<raul::Path>
AtomReader::atom_to_path(const LV2_Atom* atom)
{
- boost::optional<URI> uri = atom_to_uri(atom);
+ std::optional<URI> uri = atom_to_uri(atom);
if (uri && uri_is_path(*uri)) {
return uri_to_path(*uri);
}
- return boost::optional<raul::Path>();
+ return {};
}
Resource::Graph
@@ -124,7 +130,7 @@ AtomReader::atom_to_context(const LV2_Atom* atom)
{
Resource::Graph ctx = Resource::Graph::DEFAULT;
if (atom) {
- boost::optional<URI> maybe_uri = atom_to_uri(atom);
+ std::optional<URI> maybe_uri = atom_to_uri(atom);
if (maybe_uri) {
ctx = Resource::uri_to_graph(*maybe_uri);
} else {
@@ -168,7 +174,7 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
_uris.patch_sequenceNumber.urid(), &number,
nullptr);
- const boost::optional<URI> subject_uri = atom_to_uri(subject);
+ const std::optional<URI> subject_uri = atom_to_uri(subject);
const int32_t seq = ((number && number->type == _uris.atom_Int)
? reinterpret_cast<const LV2_Atom_Int*>(number)->body
@@ -195,7 +201,9 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
if (subject_uri && !body) {
_iface(Del{seq, *subject_uri});
return true;
- } else if (body && body->body.otype == _uris.ingen_Arc) {
+ }
+
+ if (body && body->body.otype == _uris.ingen_Arc) {
const LV2_Atom* tail = nullptr;
const LV2_Atom* head = nullptr;
const LV2_Atom* incidentTo = nullptr;
@@ -205,10 +213,10 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
_uris.ingen_incidentTo.urid(), &incidentTo,
nullptr);
- boost::optional<raul::Path> subject_path(atom_to_path(subject));
- boost::optional<raul::Path> tail_path(atom_to_path(tail));
- boost::optional<raul::Path> head_path(atom_to_path(head));
- boost::optional<raul::Path> other_path(atom_to_path(incidentTo));
+ std::optional<raul::Path> subject_path(atom_to_path(subject));
+ std::optional<raul::Path> tail_path(atom_to_path(tail));
+ std::optional<raul::Path> head_path(atom_to_path(head));
+ std::optional<raul::Path> other_path(atom_to_path(incidentTo));
if (tail_path && head_path) {
_iface(Disconnect{seq, *tail_path, *head_path});
} else if (subject_path && other_path) {
@@ -228,7 +236,9 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
if (!body) {
_log.warn("Put message has no body\n");
return false;
- } else if (!subject_uri) {
+ }
+
+ if (!subject_uri) {
_log.warn("Put message has no subject\n");
return false;
}
@@ -245,8 +255,8 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
return false;
}
- boost::optional<raul::Path> tail_path(atom_to_path(tail));
- boost::optional<raul::Path> head_path(atom_to_path(head));
+ std::optional<raul::Path> tail_path(atom_to_path(tail));
+ std::optional<raul::Path> head_path(atom_to_path(head));
if (tail_path && head_path) {
_iface(Connect{seq, *tail_path, *head_path});
} else {
@@ -275,7 +285,9 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
reinterpret_cast<const LV2_Atom*>(prop)->type != _uris.atom_URID) {
_log.warn("Set message missing property\n");
return false;
- } else if (!value) {
+ }
+
+ if (!value) {
_log.warn("Set message missing value\n");
return false;
}
@@ -304,7 +316,9 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
if (!remove) {
_log.warn("Patch message has no remove\n");
return false;
- } else if (!add) {
+ }
+
+ if (!add) {
_log.warn("Patch message has no add\n");
return false;
}
@@ -336,7 +350,7 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
}
- boost::optional<URI> dest_uri(atom_to_uri(dest));
+ std::optional<URI> dest_uri(atom_to_uri(dest));
if (!dest_uri) {
_log.warn("Copy message has non-URI destination\n");
return false;
@@ -356,13 +370,13 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
return false;
}
- boost::optional<raul::Path> subject_path(atom_to_path(subject));
+ std::optional<raul::Path> subject_path(atom_to_path(subject));
if (!subject_path) {
_log.warn("Move message has non-path subject\n");
return false;
}
- boost::optional<raul::Path> dest_path(atom_to_path(dest));
+ std::optional<raul::Path> dest_path(atom_to_path(dest));
if (!dest_path) {
_log.warn("Move message has non-path destination\n");
return false;
@@ -377,10 +391,13 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id)
if (!number || number->type != _uris.atom_Int) {
_log.warn("Response message has no sequence number\n");
return false;
- } else if (!body || body->type != _uris.atom_Int) {
+ }
+
+ if (!body || body->type != _uris.atom_Int) {
_log.warn("Response message body is not integer\n");
return false;
}
+
_iface(Response{reinterpret_cast<const LV2_Atom_Int*>(number)->body,
static_cast<ingen::Status>(
reinterpret_cast<const LV2_Atom_Int*>(body)->body),