Line data Source code
1 : #ifndef OPENDDS_DCPS_MESSAGEBLOCK_H 2 : #define OPENDDS_DCPS_MESSAGEBLOCK_H 3 : 4 : #if !defined (ACE_LACKS_PRAGMA_ONCE) 5 : # pragma once 6 : #endif /* ACE_LACKS_PRAGMA_ONCE */ 7 : 8 : #include "dcps_export.h" 9 : 10 : #include <dds/Versioned_Namespace.h> 11 : 12 : #include <ace/Message_Block.h> 13 : 14 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 15 : 16 : namespace OpenDDS { 17 : namespace DCPS { 18 : 19 : class OpenDDS_Dcps_Export MessageBlock { 20 : public: 21 : /// construct a MessageBlock that references the existing amb's ACE_Data_Block 22 : explicit MessageBlock(const ACE_Message_Block& amb); 23 : 24 : /// construct a MessageBlock with 'size' bytes allocated but not used (wr_ptr_ is 0) 25 : explicit MessageBlock(size_t size); 26 : 27 : /// construct a MessageBlock that points to external data, doesn't allocate or copy 28 : MessageBlock(const char* data, size_t size); 29 : 30 : ~MessageBlock(); 31 : 32 : MessageBlock(const MessageBlock& rhs); 33 : MessageBlock& operator=(const MessageBlock& rhs); 34 : #ifdef ACE_HAS_CPP11 35 : MessageBlock(MessageBlock&& rhs); 36 : MessageBlock& operator=(MessageBlock&& rhs); 37 : #endif 38 : 39 : void swap(MessageBlock& rhs); 40 : 41 69 : ACE_Data_Block* duplicate_data() const { return data_->duplicate(); } 42 : 43 1345 : char* base() const { return data_->base(); } 44 : 45 1275 : char* rd_ptr() const { return base() + rd_ptr_; } 46 4 : void read(size_t diff) { rd_ptr_ += diff; } 47 : void unread(size_t diff) { rd_ptr_ -= diff; } 48 : 49 69 : char* wr_ptr() const { return base() + wr_ptr_; } 50 2 : void write(size_t diff) { wr_ptr_ += diff; } 51 : void unwrite(size_t diff) { wr_ptr_ -= diff; } 52 : 53 2498 : size_t len() const { return wr_ptr_ - rd_ptr_; } 54 : 55 : private: 56 : ACE_Data_Block* data_; 57 : size_t rd_ptr_; 58 : size_t wr_ptr_; 59 : }; 60 : 61 : void swap(MessageBlock& lhs, MessageBlock& rhs); 62 : 63 : } // DCPS 64 : } // OPENDDS 65 : 66 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 67 : 68 : #endif /* OPENDDS_DCPS_MESSAGEBLOCK_H */