-Message::Message( void* mrc, int payload_len ) {
- this->mrc = mrc;
- this->mbuf = rmr_alloc_msg( mrc, payload_len );
+/*
+ Assignment operator. Simiolar to the copycat, but "this" object exists and
+ may have data that needs to be released prior to making a copy of the soi.
+*/
+Message& xapp::Message::operator=( const Message& soi ) {
+ int payload_size;
+
+ if( this != &soi ) { // cannot do self assignment
+ if( mbuf != NULL ) {
+ rmr_free_msg( mbuf ); // release the old one so we don't leak
+ }
+
+ payload_size = rmr_payload_size( soi.mbuf ); // rmr can handle a nil pointer
+ mrc = soi.mrc;
+ mbuf = rmr_realloc_payload( soi.mbuf, payload_size, RMR_COPY, RMR_CLONE );
+ }
+
+ return *this;
+}
+
+/*
+ Move builder. Given a source object instance (soi), move the information from
+ the soi ensuring that the destriction of the soi doesn't trash things from
+ under us.
+*/
+xapp::Message::Message( Message&& soi ) :
+ mrc( soi.mrc ),
+ mbuf( soi.mbuf )
+{
+ soi.mrc = NULL; // prevent closing of RMR stuff on soi destroy
+ soi.mbuf = NULL;
+}
+
+/*
+ Move Assignment operator. Move the message data to the existing object
+ ensure the object reference is cleaned up, and ensuring that the source
+ object references are removed.
+*/
+Message& xapp::Message::operator=( Message&& soi ) {
+ if( this != &soi ) { // cannot do self assignment
+ if( mbuf != NULL ) {
+ rmr_free_msg( mbuf ); // release the old one so we don't leak
+ }
+
+ mrc = soi.mrc;
+ mbuf = soi.mbuf;
+
+ soi.mrc = NULL;
+ soi.mbuf = NULL;
+ }
+
+ return *this;