Kernel word recovery crack, Mobile themes website for samsung wave 525, Dekha ek khwab sony tv title song, Song zombies on your lawn, Bloody mary nerve endings mp3, Digittrade tv jukebox, Padosan songs mp3, Gold cup series 70 manual, Nieuwste versie van mozilla firefox en, Cant install spotify on mac, Web brute force password cracker, Belkin g peek driver windows 7

VMValue

June 7th, 2012 by Martijn Leave a reply »

After considering several variant classes for my ongoing project, I decided to roll my own.

Compared to other variant types, it implements:

– Registration of named structured types.
– Registration of type conversions. A conversion doesn’t have to always succeed. For instance a MIDI Channel message may be converted into a MIDI Controller message, but may also be an incompatible MIDI note message.
– Binary (de-)serialization to QDataStream.
– Textual (de-)serialization to QTextStream. There is an unambiguous mode useful for debugging and datatransfer (altough QDataStream is likely to be more appropriate in this case) and a “human” mode useful for displaying values, human input and scripting.

A quick example of basic functionality.

#include <vmvalue.h>
#include <vmtypemanager.h>
#include <QStringList>
 
int main() {
    VMValue a = 3;
    Q_ASSERT(a.intValue() == 3);
    Q_ASSERT(a.type() == VMValue::IntType);
 
    VMValue b = "Hello Mars !";
    Q_ASSERT(b.stringValue() == "Hello Mars !");
    Q_ASSERT(b.type() == VMValue::StringType);
 
    VMValue x;
    Q_ASSERT(!x.isValid());
    x = QStringList({"welcome", "back"});
    Q_ASSERT(x.type() == VMValue::StringListType);
 
    VMValue rect = VMValue::byName("Rect");
    Q_ASSERT(rect.typeName() == "Rect");
    rect.setAttribute("x", 200);
    Q_ASSERT(rect.attribute("x").intValue() == 200);
}

An example of a custom datatypes and a casting function:

VMValue castChannelMessageToControllerMessage(const VMValue& source) {
    if (source.attribute("status") != MIDI_CTL_STATUS)
        return VMValue::Invalid;
    VMValue v = VMValue::byName("ControllerMessage");
    v.setAttribute("channel", source.attribute("channel"));
    v.setAttribute("ctl", source.attribute("data0"));
    v.setAttribute("value", source.attribute("data1"));
    return v;
}
 
int main() {
    VMTypeDef* channelMsgDef = new VMTypeDef;
    channelMsgDef->addAttribute("channel", VMValue::IntType, 0);
    channelMsgDef->addAttribute("status", VMValue::IntType, 0);
    channelMsgDef->addAttribute("data0", VMValue::IntType, 0);
    channelMsgDef->addAttribute("data1", VMValue::IntType, 0);
 
    VMTypeDef* ctlMsgDef = new VMTypeDef;
    ctlMsgDef->addAttribute("channel", VMValue::IntType, 0);
    ctlMsgDef->addAttribute("ctl", VMValue::IntType, 0);
    ctlMsgDef->addAttribute("value", VMValue::IntType, 0);
 
    vmTypeManager()->registerType("ChannelMessage", channelMsgDef);
    vmTypeManager()->registerType("ControllerMessage", ctlMsgDef);
    vmTypeManager()->registerCastFunction("ChannelMessage", "ControllerMessage",
        &castChannelMessageToControllerMessage);
 
    Q_ASSERT(vmTypeManager()->hasType("ChannelMessage");
    VMValue channelMsg = VMValue::byName("ChannelMessage");
    channelMsg.setAttribute("status", MIDI_CTL_STATUS);
    channelMsg.setAttribute("data0", MIDI_DAMPER_CTL);
    channelMsg.setAttribute("data1", 127);
 
    Q_ASSERT(channelMsg.canCastTo("ControllerMessage"));
    VMValue ctlMsg = channelMsg.castTo("ControllerMessage");
    Q_ASSERT(ctlMsg.isValid());
    Q_ASSERT(ctlMsg.attribute("ctl").intValue() == MIDI_DAMPER_CTL);
 
    return 0;
}

Human-readable serialization to QTextStream using VMValueDumper and VMValueParser example:

    VMValueDumper dumper;
    dumper.setPrettyPrint(false);
    dumper.setBareStrings(false);
    dumper.setCompact(true);
    dumper.setOmitDefaults(false);
 
    Q_ASSERT(dumper.dump(5) == "5");
    Q_ASSERT(dumper.dump("hello") == "hello");
    Q_ASSERT(dumper.dump(IntList({1, 2, 3})), "I[1,2,3]");
 
    // ControllerMessage from previous example
    Q_ASSERT(dumper.dump(ctlMsg) == "@ControllerMessage{channel:0,ctl:7,value:127}");
 
    VMValueParser parser;
    VMValue x = parser.parse("\"hello world\"");
    Q_ASSERT(x.stringValue(), "hello world");

The missing part is currently the ability to share a value between VMValues to optimize data transfer between Units in the a graph, especially for streaming nodes (audio, video).

There isn’t much documentation for the code, except the comments inside the source and some design files, but there are unit tests that show the intended use of these classes.

As the API isn’t fully stabilized yet, the source code is available on request.

Advertisement

Leave a Reply

Authorized tags:
[b]bold[/b] [u]underline[/u] [i]italic[/i] [url=http://link.url]link[/url] more