Acoustic Touch Recognition
OscOutboundPacketStream.h
Go to the documentation of this file.
1 /*
2  oscpack -- Open Sound Control (OSC) packet manipulation library
3  http://www.rossbencina.com/code/oscpack
4 
5  Copyright (c) 2004-2013 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  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26 
27 /*
28  The text above constitutes the entire oscpack license; however,
29  the oscpack developer(s) also make the following non-binding requests:
30 
31  Any person wishing to distribute modifications to the Software is
32  requested to send the modifications to the original developer so that
33  they can be incorporated into the canonical version. It is also
34  requested that these non-binding requests be included whenever the
35  above license is reproduced.
36 */
37 #ifndef INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H
38 #define INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H
39 
40 #include <cstring> // size_t
41 
42 #include "oscpack/osc/OscTypes.h"
44 
45 
46 namespace osc{
47 
49 public:
50  OutOfBufferMemoryException( const char *w="out of buffer memory" )
51  : Exception( w ) {}
52 };
53 
55 public:
57  const char *w="call to EndBundle when bundle is not in progress" )
58  : Exception( w ) {}
59 };
60 
62 public:
64  const char *w="opening or closing bundle or message while message is in progress" )
65  : Exception( w ) {}
66 };
67 
69 public:
71  const char *w="call to EndMessage when message is not in progress" )
72  : Exception( w ) {}
73 };
74 
75 
77 public:
78  OutboundPacketStream( char *buffer, std::size_t capacity );
80 
81  void Clear();
82 
83  std::size_t Capacity() const;
84 
85  // invariant: size() is valid even while building a message.
86  std::size_t Size() const;
87 
88  const char *Data() const;
89 
90  // indicates that all messages have been closed with a matching EndMessage
91  // and all bundles have been closed with a matching EndBundle
92  bool IsReady() const;
93 
94  bool IsMessageInProgress() const;
95  bool IsBundleInProgress() const;
96 
99 
102 
103  OutboundPacketStream& operator<<( bool rhs );
104  OutboundPacketStream& operator<<( const NilType& rhs );
107 
108 #if !(defined(__x86_64__) || defined(_M_X64))
110  { *this << (int32)rhs; return *this; }
111 #endif
112 
113  OutboundPacketStream& operator<<( float rhs );
114  OutboundPacketStream& operator<<( char rhs );
118  OutboundPacketStream& operator<<( const TimeTag& rhs );
119  OutboundPacketStream& operator<<( double rhs );
120  OutboundPacketStream& operator<<( const char* rhs );
121  OutboundPacketStream& operator<<( const Symbol& rhs );
122  OutboundPacketStream& operator<<( const Blob& rhs );
123 
126 
127 private:
128 
129  char *BeginElement( char *beginPtr );
130  void EndElement( char *endPtr );
131 
132  bool ElementSizeSlotRequired() const;
133  void CheckForAvailableBundleSpace();
134  void CheckForAvailableMessageSpace( const char *addressPattern );
135  void CheckForAvailableArgumentSpace( std::size_t argumentLength );
136 
137  char *data_;
138  char *end_;
139 
140  char *typeTagsCurrent_; // stored in reverse order
143 
144  // elementSizePtr_ has two special values: 0 indicates that a bundle
145  // isn't open, and elementSizePtr_==data_ indicates that a bundle is
146  // open but that it doesn't have a size slot (ie the outermost bundle)
148 
150 };
151 
152 } // namespace osc
153 
154 #endif /* INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H */
Definition: OscOutboundPacketStream.h:76
char * messageCursor_
Definition: OscOutboundPacketStream.h:141
Definition: OscTypes.h:169
char * end_
Definition: OscOutboundPacketStream.h:138
Definition: OscOutboundPacketStream.h:54
long long int64
Definition: OscTypes.h:57
Definition: OscOutboundPacketStream.h:48
char * typeTagsCurrent_
Definition: OscOutboundPacketStream.h:140
Definition: OscTypes.h:183
Definition: OscOutboundPacketStream.h:68
MessageInProgressException(const char *w="opening or closing bundle or message while message is in progress")
Definition: OscOutboundPacketStream.h:63
char * argumentCurrent_
Definition: OscOutboundPacketStream.h:142
Definition: OscTypes.h:137
Definition: OscTypes.h:232
OutOfBufferMemoryException(const char *w="out of buffer memory")
Definition: OscOutboundPacketStream.h:50
bool messageIsInProgress_
Definition: OscOutboundPacketStream.h:149
OutboundPacketStream & operator<<(int rhs)
Definition: OscOutboundPacketStream.h:109
Definition: OscTypes.h:160
Definition: OscTypes.h:178
Definition: OscTypes.h:150
Definition: OscTypes.h:210
BundleNotInProgressException(const char *w="call to EndBundle when bundle is not in progress")
Definition: OscOutboundPacketStream.h:56
Definition: OscTypes.h:201
signed long int32
Definition: OscTypes.h:71
char * data_
Definition: OscOutboundPacketStream.h:137
Definition: MessageMappingOscPacketListener.h:47
MessageNotInProgressException(const char *w="call to EndMessage when message is not in progress")
Definition: OscOutboundPacketStream.h:70
Definition: OscTypes.h:219
Definition: OscTypes.h:155
Definition: OscOutboundPacketStream.h:61
Definition: OscException.h:44
std::ostream & operator<<(std::ostream &os, const ReceivedPacket &p)
Definition: OscPrintReceivedElements.cpp:248
unsigned long uint32
Definition: OscTypes.h:72
uint32 * elementSizePtr_
Definition: OscOutboundPacketStream.h:147
Definition: OscTypes.h:192
Definition: OscTypes.h:227