2 oscpack -- Open Sound Control packet manipulation library
3 http://www.audiomulch.com/~rossb/oscpack
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction,
10 including without limitation the rights to use, copy, modify, merge,
11 publish, distribute, sublicense, and/or sell copies of the Software,
12 and to permit persons to whom the Software is furnished to do so,
13 subject to the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 Any person wishing to distribute modifications to the Software is
19 requested to send the modifications to the original developer so that
20 they can be incorporated into the canonical version.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #ifndef INCLUDED_OSCOUTBOUNDPACKET_H
31 #define INCLUDED_OSCOUTBOUNDPACKET_H
34 #include "OscException.h"
39 class OutOfBufferMemoryException
: public Exception
{
41 OutOfBufferMemoryException( const char *w
="out of buffer memory" )
45 class BundleNotInProgressException
: public Exception
{
47 BundleNotInProgressException(
48 const char *w
="call to EndBundle when bundle is not in progress" )
52 class MessageInProgressException
: public Exception
{
54 MessageInProgressException(
55 const char *w
="opening or closing bundle or message while message is in progress" )
59 class MessageNotInProgressException
: public Exception
{
61 MessageNotInProgressException(
62 const char *w
="call to EndMessage when message is not in progress" )
67 class OutboundPacketStream
{
69 OutboundPacketStream( char *buffer
, unsigned long capacity
);
70 ~OutboundPacketStream();
74 unsigned int Capacity() const;
76 // invariant: size() is valid even while building a message.
77 unsigned int Size() const;
79 const char *Data() const;
81 // indicates that all messages have been closed with a matching EndMessage
82 // and all bundles have been closed with a matching EndBundle
85 bool IsMessageInProgress() const;
86 bool IsBundleInProgress() const;
88 OutboundPacketStream
& operator<<( const BundleInitiator
& rhs
);
89 OutboundPacketStream
& operator<<( const BundleTerminator
& rhs
);
91 OutboundPacketStream
& operator<<( const BeginMessage
& rhs
);
92 OutboundPacketStream
& operator<<( const MessageTerminator
& rhs
);
94 OutboundPacketStream
& operator<<( bool rhs
);
95 OutboundPacketStream
& operator<<( const NilType
& rhs
);
96 OutboundPacketStream
& operator<<( const InfinitumType
& rhs
);
97 OutboundPacketStream
& operator<<( int32 rhs
);
100 OutboundPacketStream
& operator<<( int rhs
)
101 { *this << (int32
)rhs
; return *this; }
104 OutboundPacketStream
& operator<<( float rhs
);
105 OutboundPacketStream
& operator<<( char rhs
);
106 OutboundPacketStream
& operator<<( const RgbaColor
& rhs
);
107 OutboundPacketStream
& operator<<( const MidiMessage
& rhs
);
108 OutboundPacketStream
& operator<<( int64 rhs
);
109 OutboundPacketStream
& operator<<( const TimeTag
& rhs
);
110 OutboundPacketStream
& operator<<( double rhs
);
111 OutboundPacketStream
& operator<<( const char* rhs
);
112 OutboundPacketStream
& operator<<( const Symbol
& rhs
);
113 OutboundPacketStream
& operator<<( const Blob
& rhs
);
115 OutboundPacketStream
& operator<<( const ArrayStart
& rhs
);
116 OutboundPacketStream
& operator<<( const ArrayEnd
& rhs
);
120 char *BeginElement( char *beginPtr
);
121 void EndElement( char *endPtr
);
123 bool ElementSizeSlotRequired() const;
124 void CheckForAvailableBundleSpace();
125 void CheckForAvailableMessageSpace( const char *addressPattern
);
126 void CheckForAvailableArgumentSpace( long argumentLength
);
131 char *typeTagsCurrent_
; // stored in reverse order
132 char *messageCursor_
;
133 char *argumentCurrent_
;
135 // elementSizePtr_ has two special values: 0 indicates that a bundle
136 // isn't open, and elementSizePtr_==data_ indicates that a bundle is
137 // open but that it doesn't have a size slot (ie the outermost bundle)
138 uint32
*elementSizePtr_
;
140 bool messageIsInProgress_
;
145 #endif /* INCLUDED_OSC_OUTBOUND_PACKET_H */