annotate oscpack/osc/OscOutboundPacketStream.h @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents 0ae87af84e2f
children
rev   line source
rob@76 1 /*
rob@76 2 oscpack -- Open Sound Control (OSC) packet manipulation library
rob@76 3 http://www.rossbencina.com/code/oscpack
rob@76 4
rob@76 5 Copyright (c) 2004-2013 Ross Bencina <rossb@audiomulch.com>
rob@76 6
rob@76 7 Permission is hereby granted, free of charge, to any person obtaining
rob@76 8 a copy of this software and associated documentation files
rob@76 9 (the "Software"), to deal in the Software without restriction,
rob@76 10 including without limitation the rights to use, copy, modify, merge,
rob@76 11 publish, distribute, sublicense, and/or sell copies of the Software,
rob@76 12 and to permit persons to whom the Software is furnished to do so,
rob@76 13 subject to the following conditions:
rob@76 14
rob@76 15 The above copyright notice and this permission notice shall be
rob@76 16 included in all copies or substantial portions of the Software.
rob@76 17
rob@76 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
rob@76 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
rob@76 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
rob@76 21 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
rob@76 22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
rob@76 23 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
rob@76 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rob@76 25 */
rob@76 26
rob@76 27 /*
rob@76 28 The text above constitutes the entire oscpack license; however,
rob@76 29 the oscpack developer(s) also make the following non-binding requests:
rob@76 30
rob@76 31 Any person wishing to distribute modifications to the Software is
rob@76 32 requested to send the modifications to the original developer so that
rob@76 33 they can be incorporated into the canonical version. It is also
rob@76 34 requested that these non-binding requests be included whenever the
rob@76 35 above license is reproduced.
rob@76 36 */
rob@76 37 #ifndef INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H
rob@76 38 #define INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H
rob@76 39
rob@76 40 #include <cstring> // size_t
rob@76 41
rob@76 42 #include "OscTypes.h"
rob@76 43 #include "OscException.h"
rob@76 44
rob@76 45
rob@76 46 namespace osc{
rob@76 47
rob@76 48 class OutOfBufferMemoryException : public Exception{
rob@76 49 public:
rob@76 50 OutOfBufferMemoryException( const char *w="out of buffer memory" )
rob@76 51 : Exception( w ) {}
rob@76 52 };
rob@76 53
rob@76 54 class BundleNotInProgressException : public Exception{
rob@76 55 public:
rob@76 56 BundleNotInProgressException(
rob@76 57 const char *w="call to EndBundle when bundle is not in progress" )
rob@76 58 : Exception( w ) {}
rob@76 59 };
rob@76 60
rob@76 61 class MessageInProgressException : public Exception{
rob@76 62 public:
rob@76 63 MessageInProgressException(
rob@76 64 const char *w="opening or closing bundle or message while message is in progress" )
rob@76 65 : Exception( w ) {}
rob@76 66 };
rob@76 67
rob@76 68 class MessageNotInProgressException : public Exception{
rob@76 69 public:
rob@76 70 MessageNotInProgressException(
rob@76 71 const char *w="call to EndMessage when message is not in progress" )
rob@76 72 : Exception( w ) {}
rob@76 73 };
rob@76 74
rob@76 75
rob@76 76 class OutboundPacketStream{
rob@76 77 public:
rob@76 78 OutboundPacketStream( char *buffer, std::size_t capacity );
rob@76 79 ~OutboundPacketStream();
rob@76 80
rob@76 81 void Clear();
rob@76 82
rob@76 83 std::size_t Capacity() const;
rob@76 84
rob@76 85 // invariant: size() is valid even while building a message.
rob@76 86 std::size_t Size() const;
rob@76 87
rob@76 88 const char *Data() const;
rob@76 89
rob@76 90 // indicates that all messages have been closed with a matching EndMessage
rob@76 91 // and all bundles have been closed with a matching EndBundle
rob@76 92 bool IsReady() const;
rob@76 93
rob@76 94 bool IsMessageInProgress() const;
rob@76 95 bool IsBundleInProgress() const;
rob@76 96
rob@76 97 OutboundPacketStream& operator<<( const BundleInitiator& rhs );
rob@76 98 OutboundPacketStream& operator<<( const BundleTerminator& rhs );
rob@76 99
rob@76 100 OutboundPacketStream& operator<<( const BeginMessage& rhs );
rob@76 101 OutboundPacketStream& operator<<( const MessageTerminator& rhs );
rob@76 102
rob@76 103 OutboundPacketStream& operator<<( bool rhs );
rob@76 104 OutboundPacketStream& operator<<( const NilType& rhs );
rob@76 105 OutboundPacketStream& operator<<( const InfinitumType& rhs );
rob@76 106 OutboundPacketStream& operator<<( int32 rhs );
rob@76 107
rob@76 108 #if !(defined(__x86_64__) || defined(_M_X64))
rob@76 109 OutboundPacketStream& operator<<( int rhs )
rob@76 110 { *this << (int32)rhs; return *this; }
rob@76 111 #endif
rob@76 112
rob@76 113 OutboundPacketStream& operator<<( float rhs );
rob@76 114 OutboundPacketStream& operator<<( char rhs );
rob@76 115 OutboundPacketStream& operator<<( const RgbaColor& rhs );
rob@76 116 OutboundPacketStream& operator<<( const MidiMessage& rhs );
rob@76 117 OutboundPacketStream& operator<<( int64 rhs );
rob@76 118 OutboundPacketStream& operator<<( const TimeTag& rhs );
rob@76 119 OutboundPacketStream& operator<<( double rhs );
rob@76 120 OutboundPacketStream& operator<<( const char* rhs );
rob@76 121 OutboundPacketStream& operator<<( const Symbol& rhs );
rob@76 122 OutboundPacketStream& operator<<( const Blob& rhs );
rob@76 123
rob@76 124 OutboundPacketStream& operator<<( const ArrayInitiator& rhs );
rob@76 125 OutboundPacketStream& operator<<( const ArrayTerminator& rhs );
rob@76 126
rob@76 127 private:
rob@76 128
rob@76 129 char *BeginElement( char *beginPtr );
rob@76 130 void EndElement( char *endPtr );
rob@76 131
rob@76 132 bool ElementSizeSlotRequired() const;
rob@76 133 void CheckForAvailableBundleSpace();
rob@76 134 void CheckForAvailableMessageSpace( const char *addressPattern );
rob@76 135 void CheckForAvailableArgumentSpace( std::size_t argumentLength );
rob@76 136
rob@76 137 char *data_;
rob@76 138 char *end_;
rob@76 139
rob@76 140 char *typeTagsCurrent_; // stored in reverse order
rob@76 141 char *messageCursor_;
rob@76 142 char *argumentCurrent_;
rob@76 143
rob@76 144 // elementSizePtr_ has two special values: 0 indicates that a bundle
rob@76 145 // isn't open, and elementSizePtr_==data_ indicates that a bundle is
rob@76 146 // open but that it doesn't have a size slot (ie the outermost bundle)
rob@76 147 uint32 *elementSizePtr_;
rob@76 148
rob@76 149 bool messageIsInProgress_;
rob@76 150 };
rob@76 151
rob@76 152 } // namespace osc
rob@76 153
rob@76 154 #endif /* INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H */