annotate external/oscpack/osc/OscOutboundPacketStream.h @ 644:16dfff1de47a

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