rob@76: /* rob@76: oscpack -- Open Sound Control (OSC) packet manipulation library rob@76: http://www.rossbencina.com/code/oscpack rob@76: rob@76: Copyright (c) 2004-2013 Ross Bencina rob@76: rob@76: Permission is hereby granted, free of charge, to any person obtaining rob@76: a copy of this software and associated documentation files rob@76: (the "Software"), to deal in the Software without restriction, rob@76: including without limitation the rights to use, copy, modify, merge, rob@76: publish, distribute, sublicense, and/or sell copies of the Software, rob@76: and to permit persons to whom the Software is furnished to do so, rob@76: subject to the following conditions: rob@76: rob@76: The above copyright notice and this permission notice shall be rob@76: included in all copies or substantial portions of the Software. rob@76: rob@76: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, rob@76: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF rob@76: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. rob@76: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR rob@76: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF rob@76: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION rob@76: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rob@76: */ rob@76: rob@76: /* rob@76: The text above constitutes the entire oscpack license; however, rob@76: the oscpack developer(s) also make the following non-binding requests: rob@76: rob@76: Any person wishing to distribute modifications to the Software is rob@76: requested to send the modifications to the original developer so that rob@76: they can be incorporated into the canonical version. It is also rob@76: requested that these non-binding requests be included whenever the rob@76: above license is reproduced. rob@76: */ rob@76: #ifndef INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H rob@76: #define INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H rob@76: rob@76: #include // size_t rob@76: rob@76: #include "OscTypes.h" rob@76: #include "OscException.h" rob@76: rob@76: rob@76: namespace osc{ rob@76: rob@76: class OutOfBufferMemoryException : public Exception{ rob@76: public: rob@76: OutOfBufferMemoryException( const char *w="out of buffer memory" ) rob@76: : Exception( w ) {} rob@76: }; rob@76: rob@76: class BundleNotInProgressException : public Exception{ rob@76: public: rob@76: BundleNotInProgressException( rob@76: const char *w="call to EndBundle when bundle is not in progress" ) rob@76: : Exception( w ) {} rob@76: }; rob@76: rob@76: class MessageInProgressException : public Exception{ rob@76: public: rob@76: MessageInProgressException( rob@76: const char *w="opening or closing bundle or message while message is in progress" ) rob@76: : Exception( w ) {} rob@76: }; rob@76: rob@76: class MessageNotInProgressException : public Exception{ rob@76: public: rob@76: MessageNotInProgressException( rob@76: const char *w="call to EndMessage when message is not in progress" ) rob@76: : Exception( w ) {} rob@76: }; rob@76: rob@76: rob@76: class OutboundPacketStream{ rob@76: public: rob@76: OutboundPacketStream( char *buffer, std::size_t capacity ); rob@76: ~OutboundPacketStream(); rob@76: rob@76: void Clear(); rob@76: rob@76: std::size_t Capacity() const; rob@76: rob@76: // invariant: size() is valid even while building a message. rob@76: std::size_t Size() const; rob@76: rob@76: const char *Data() const; rob@76: rob@76: // indicates that all messages have been closed with a matching EndMessage rob@76: // and all bundles have been closed with a matching EndBundle rob@76: bool IsReady() const; rob@76: rob@76: bool IsMessageInProgress() const; rob@76: bool IsBundleInProgress() const; rob@76: rob@76: OutboundPacketStream& operator<<( const BundleInitiator& rhs ); rob@76: OutboundPacketStream& operator<<( const BundleTerminator& rhs ); rob@76: rob@76: OutboundPacketStream& operator<<( const BeginMessage& rhs ); rob@76: OutboundPacketStream& operator<<( const MessageTerminator& rhs ); rob@76: rob@76: OutboundPacketStream& operator<<( bool rhs ); rob@76: OutboundPacketStream& operator<<( const NilType& rhs ); rob@76: OutboundPacketStream& operator<<( const InfinitumType& rhs ); rob@76: OutboundPacketStream& operator<<( int32 rhs ); rob@76: rob@76: #if !(defined(__x86_64__) || defined(_M_X64)) rob@76: OutboundPacketStream& operator<<( int rhs ) rob@76: { *this << (int32)rhs; return *this; } rob@76: #endif rob@76: rob@76: OutboundPacketStream& operator<<( float rhs ); rob@76: OutboundPacketStream& operator<<( char rhs ); rob@76: OutboundPacketStream& operator<<( const RgbaColor& rhs ); rob@76: OutboundPacketStream& operator<<( const MidiMessage& rhs ); rob@76: OutboundPacketStream& operator<<( int64 rhs ); rob@76: OutboundPacketStream& operator<<( const TimeTag& rhs ); rob@76: OutboundPacketStream& operator<<( double rhs ); rob@76: OutboundPacketStream& operator<<( const char* rhs ); rob@76: OutboundPacketStream& operator<<( const Symbol& rhs ); rob@76: OutboundPacketStream& operator<<( const Blob& rhs ); rob@76: rob@76: OutboundPacketStream& operator<<( const ArrayInitiator& rhs ); rob@76: OutboundPacketStream& operator<<( const ArrayTerminator& rhs ); rob@76: rob@76: private: rob@76: rob@76: char *BeginElement( char *beginPtr ); rob@76: void EndElement( char *endPtr ); rob@76: rob@76: bool ElementSizeSlotRequired() const; rob@76: void CheckForAvailableBundleSpace(); rob@76: void CheckForAvailableMessageSpace( const char *addressPattern ); rob@76: void CheckForAvailableArgumentSpace( std::size_t argumentLength ); rob@76: rob@76: char *data_; rob@76: char *end_; rob@76: rob@76: char *typeTagsCurrent_; // stored in reverse order rob@76: char *messageCursor_; rob@76: char *argumentCurrent_; rob@76: rob@76: // elementSizePtr_ has two special values: 0 indicates that a bundle rob@76: // isn't open, and elementSizePtr_==data_ indicates that a bundle is rob@76: // open but that it doesn't have a size slot (ie the outermost bundle) rob@76: uint32 *elementSizePtr_; rob@76: rob@76: bool messageIsInProgress_; rob@76: }; rob@76: rob@76: } // namespace osc rob@76: rob@76: #endif /* INCLUDED_OSCPACK_OSCOUTBOUNDPACKETSTREAM_H */