#include <oscpkt.hh>
Classes | |
class | ArgReader |
Public Member Functions | |
Message (const std::string &s, TimeTag tt=TimeTag::immediate()) | |
Message (const void *ptr, size_t sz, TimeTag tt=TimeTag::immediate()) | |
bool | isOk () const |
ErrorCode | getErr () const |
const std::string & | typeTags () const |
const std::string & | addressPattern () const |
TimeTag | timeTag () const |
Message & | init (const std::string &addr, TimeTag tt=TimeTag::immediate()) |
ArgReader | match (const std::string &test) const |
ArgReader | partialMatch (const std::string &test) const |
ArgReader | arg () const |
void | buildFromRawData (const void *ptr, size_t sz) |
Message & | pushBool (bool b) |
Message & | pushInt32 (int32_t i) |
Message & | pushInt64 (int64_t h) |
Message & | pushFloat (float f) |
Message & | pushDouble (double d) |
Message & | pushStr (const std::string &s) |
Message & | pushBlob (void *ptr, size_t num_bytes) |
void | clear () |
void | packMessage (Storage &s, bool write_size) const |
struct used to hold an OSC message that will be written or read.
The list of arguments is exposed as a sort of queue. You "pop" arguments from the front of the queue when reading, you push arguments at the back of the queue when writing.
Many functions return *this, so they can be chained: init("/foo").pushInt32(2).pushStr("kllk")...
Example of use:
creation of a message:
msg.init("/foo").pushInt32(4).pushStr("bar");
reading a message, with error detection:
if (msg.match("/foo/b*ar/plop")) { int i; std::string s; std::vector<char> b; if (msg.arg().popInt32(i).popStr(s).popBlob(b).isOkNoMoreArgs()) { process message...; } else arguments mismatch; }
oscpkt_demo.cc, and oscpkt_test.cc.
const std::string& oscpkt::Message::addressPattern | ( | ) | const [inline] |
retrieve the address pattern. If you want to follow to the whole OSC spec, you have to handle its matching rules for address specifications -- this file does not provide this functionality
void oscpkt::Message::buildFromRawData | ( | const void * | ptr, | |
size_t | sz | |||
) | [inline] |
build the osc message for raw data (the message will keep a copy of that data)
void oscpkt::Message::clear | ( | ) | [inline] |
reset the message to a clean state
Message& oscpkt::Message::init | ( | const std::string & | addr, | |
TimeTag | tt = TimeTag::immediate() | |||
) | [inline] |
clear the message and start a new message with the supplied address and time_tag.
ArgReader oscpkt::Message::match | ( | const std::string & | test | ) | const [inline] |
start a matching test. The typical use-case is to follow this by a sequence of calls to popXXX() and a final call to isOkNoMoreArgs() which will allow to check that everything went fine. For example:
if (msg.match("/foo").popInt32(i).isOkNoMoreArgs()) { blah(i); } else if (msg.match("/bar").popStr(s).popInt32(i).isOkNoMoreArgs()) { plop(s,i); } else cerr << "unhandled message: " << msg << "\n";
void oscpkt::Message::packMessage | ( | Storage & | s, | |
bool | write_size | |||
) | const [inline] |
write the raw message data (used by PacketWriter)
ArgReader oscpkt::Message::partialMatch | ( | const std::string & | test | ) | const [inline] |
return true if the 'test' path matched by the first characters of addressPattern(). For ex. ("/foo/bar").partialMatch("/foo/") is true
const std::string& oscpkt::Message::typeTags | ( | ) | const [inline] |
return the type_tags string, with its initial ',' stripped.