[][src]Module lv2_atom::object

An atom containing multiple key-value pairs.

This module is centered on the Object atom type. An object is the atomized form of an RDF instance: It has an (optional) id, a type and multiple properties declared as URID/Atom pairs. Both the id and the type are URIDs too.

Example

use lv2_core::prelude::*;
use lv2_atom::prelude::*;
use urid::*;

#[uri("urn:object-class")]
struct ObjectClass;

#[uri("urn:property-a")]
struct PropertyA;

#[derive(PortCollection)]
struct MyPorts {
    input: InputPort<AtomPort>,
    output: OutputPort<AtomPort>,
}

#[derive(URIDCollection)]
struct MyURIDs {
    atom: AtomURIDCollection,
    object_class: URID<ObjectClass>,
    property_a: URID<PropertyA>,
}

fn run(ports: &mut MyPorts, urids: &MyURIDs) {
    // Create the reading handle.
    // We don't need the header now.
    let (_header, object_reader) = ports.input.read(urids.atom.object, ()).unwrap();

    /// Iterate through all properties of the object.
    for (property_header, atom) in object_reader {
        // If the property is an integer...
        if let Some(integer) = atom.read(urids.atom.int, ()) {
            // Print it!
            println!(
                "Property No. {} has integer value {}",
                property_header.key.get(),
                integer
            );
        } else {
            // Print that is not an integer.
            println!(
                "Property No. {} is not an integer",
                property_header.key.get()
            );
        }
    }

    // Initialize the object.
    let mut object_writer = ports.output.init(
        urids.atom.object,
        ObjectHeader {
            id: None,
            otype: urids.object_class.into_general(),
        }
    ).unwrap();

    // Write a property to the object.
    object_writer.init(urids.property_a, urids.atom.int, 42).unwrap();
}

Specification

http://lv2plug.in/ns/ext/atom/atom.html#Object.

Structs

Blank

Alias of Object, used by older hosts.

Object

An atom containing multiple key-value pairs.

ObjectHeader

Information about an object atom.

ObjectReader

An iterator over all properties in an object.

ObjectWriter

Writing handle for object properties.

Property

An atom containing a key-value pair.

PropertyHeader

Information about a property atom.