+/*
+ Copy builder. Given a source object instance (soi), create a copy.
+ Creating a copy should be avoided as it can be SLOW!
+*/
+Message::Message( const Message& soi ) {
+ int payload_size;
+
+ mrc = soi.mrc;
+ payload_size = rmr_payload_size( soi.mbuf ); // rmr can handle a nil pointer
+ mbuf = rmr_realloc_payload( soi.mbuf, payload_size, RMR_COPY, RMR_CLONE );
+}
+
+/*
+ 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& 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.
+*/
+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& 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;
+}
+
+