Completing Faustine by adding following primitives : float, power, &, |, xor, >=...
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / architecture / osclib / oscpack / osc / OscOutboundPacketStream.h
1 /*
2 oscpack -- Open Sound Control packet manipulation library
3 http://www.audiomulch.com/~rossb/oscpack
4
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
6
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:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
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.
21
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.
29 */
30 #ifndef INCLUDED_OSCOUTBOUNDPACKET_H
31 #define INCLUDED_OSCOUTBOUNDPACKET_H
32
33 #include "OscTypes.h"
34 #include "OscException.h"
35
36
37 namespace osc{
38
39 class OutOfBufferMemoryException : public Exception{
40 public:
41 OutOfBufferMemoryException( const char *w="out of buffer memory" )
42 : Exception( w ) {}
43 };
44
45 class BundleNotInProgressException : public Exception{
46 public:
47 BundleNotInProgressException(
48 const char *w="call to EndBundle when bundle is not in progress" )
49 : Exception( w ) {}
50 };
51
52 class MessageInProgressException : public Exception{
53 public:
54 MessageInProgressException(
55 const char *w="opening or closing bundle or message while message is in progress" )
56 : Exception( w ) {}
57 };
58
59 class MessageNotInProgressException : public Exception{
60 public:
61 MessageNotInProgressException(
62 const char *w="call to EndMessage when message is not in progress" )
63 : Exception( w ) {}
64 };
65
66
67 class OutboundPacketStream{
68 public:
69 OutboundPacketStream( char *buffer, unsigned long capacity );
70 ~OutboundPacketStream();
71
72 void Clear();
73
74 unsigned int Capacity() const;
75
76 // invariant: size() is valid even while building a message.
77 unsigned int Size() const;
78
79 const char *Data() const;
80
81 // indicates that all messages have been closed with a matching EndMessage
82 // and all bundles have been closed with a matching EndBundle
83 bool IsReady() const;
84
85 bool IsMessageInProgress() const;
86 bool IsBundleInProgress() const;
87
88 OutboundPacketStream& operator<<( const BundleInitiator& rhs );
89 OutboundPacketStream& operator<<( const BundleTerminator& rhs );
90
91 OutboundPacketStream& operator<<( const BeginMessage& rhs );
92 OutboundPacketStream& operator<<( const MessageTerminator& rhs );
93
94 OutboundPacketStream& operator<<( bool rhs );
95 OutboundPacketStream& operator<<( const NilType& rhs );
96 OutboundPacketStream& operator<<( const InfinitumType& rhs );
97 OutboundPacketStream& operator<<( int32 rhs );
98
99 #ifndef x86_64
100 OutboundPacketStream& operator<<( int rhs )
101 { *this << (int32)rhs; return *this; }
102 #endif
103
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 );
114
115 private:
116
117 char *BeginElement( char *beginPtr );
118 void EndElement( char *endPtr );
119
120 bool ElementSizeSlotRequired() const;
121 void CheckForAvailableBundleSpace();
122 void CheckForAvailableMessageSpace( const char *addressPattern );
123 void CheckForAvailableArgumentSpace( long argumentLength );
124
125 char *data_;
126 char *end_;
127
128 char *typeTagsCurrent_; // stored in reverse order
129 char *messageCursor_;
130 char *argumentCurrent_;
131
132 // elementSizePtr_ has two special values: 0 indicates that a bundle
133 // isn't open, and elementSizePtr_==data_ indicates that a bundle is
134 // open but that it doesn't have a size slot (ie the outermost bundle)
135 uint32 *elementSizePtr_;
136
137 bool messageIsInProgress_;
138 };
139
140 } // namespace osc
141
142 #endif /* INCLUDED_OSC_OUTBOUND_PACKET_H */