Fixing some asserts with wrong ranges and reworking some comments
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 21 Aug 2011 00:16:25 +0000 (21:16 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 21 Aug 2011 00:16:25 +0000 (21:16 -0300)
src/host/messagepayload.cpp

index bcb522d..1626301 100644 (file)
@@ -81,8 +81,12 @@ MessagePayload& MessagePayload::operator=( const MessagePayload &other )
 }
 
 /**
- * @brief The element access operator to provide access syntax like regular
- * arrays.
+ * @brief Array Subscript Operator.
+ *
+ * The element access operator to provide access syntax like regular
+ * arrays. This version is used when this object is constant.
+ *
+ * @return A non-modifiable reference to the object indexed by the offset.
  */
 const uint8_t& MessagePayload::operator[]( size_t offset ) const
 {
@@ -92,8 +96,12 @@ const uint8_t& MessagePayload::operator[]( size_t offset ) const
 }
 
 /**
- * @brief The element access operator to provide access syntax like regular
- * arrays.
+ * @brief Array Subscript Operator.
+ *
+ * The element access operator to provide access syntax like regular
+ * arrays. This version is used by non-const objects.
+ *
+ * @return A modifiable reference to the object indexed by the offset.
  */
 uint8_t& MessagePayload::operator[]( size_t offset )
 {
@@ -109,7 +117,7 @@ uint8_t& MessagePayload::operator[]( size_t offset )
  * @param right_byte the index of the right byte
  *
  * @return a concatenation of the byte indexed by left_byte with the byte
- * indexed by right_byte
+ * indexed by right_byte.
  */
 uint16_t MessagePayload::decode16(
         const int left_byte,
@@ -119,7 +127,7 @@ uint16_t MessagePayload::decode16(
     BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( left_byte < right_byte );
-    BOOST_ASSERT( ( right_byte - left_byte ) == sizeof(uint16_t) );
+    BOOST_ASSERT( ( ( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) );
 
     uint32_t value = static_cast<uint16_t>( Payload[ left_byte ] << 8 );
     value += static_cast<uint16_t>( Payload[ right_byte ] );
@@ -145,10 +153,10 @@ void MessagePayload::encode16(
         const uint16_t value
 )
 {
-    BOOST_ASSERT( ( 0 < left_byte ) && ( left_byte < static_cast<int>(PayloadSizeInBytes) ) );
-    BOOST_ASSERT( ( 0 < right_byte ) && ( right_byte < static_cast<int>(PayloadSizeInBytes) ) );
+    BOOST_ASSERT( ( 0 <= left_byte ) && ( left_byte < static_cast<int>(PayloadSizeInBytes) ) );
+    BOOST_ASSERT( ( 0 <= right_byte ) && ( right_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( left_byte < right_byte );
-    BOOST_ASSERT( ( right_byte - left_byte ) == sizeof(uint16_t) );
+    BOOST_ASSERT( ( ( right_byte - left_byte ) + 1 ) == sizeof(uint16_t) );
 
     Payload[ left_byte ] = static_cast<uint8_t>( value >> 8 );
     Payload[ right_byte ] = static_cast<uint8_t>( value & 0xFF );
@@ -171,7 +179,7 @@ uint32_t MessagePayload::decode32(
     BOOST_ASSERT( ( 0 <= first_byte ) && ( first_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( ( 0 <= last_byte ) && ( last_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( first_byte < last_byte );
-    BOOST_ASSERT( ( last_byte - first_byte ) == sizeof(uint32_t) );
+    BOOST_ASSERT( ( ( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) );
 
     int current_byte = first_byte;
 
@@ -205,7 +213,7 @@ void MessagePayload::encode32(
     BOOST_ASSERT( ( 0 < first_byte ) && ( first_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( ( 0 < last_byte ) && ( last_byte < static_cast<int>(PayloadSizeInBytes) ) );
     BOOST_ASSERT( first_byte < last_byte );
-    BOOST_ASSERT( ( last_byte - first_byte ) == sizeof(uint32_t) );
+    BOOST_ASSERT( ( ( last_byte - first_byte ) + 1 ) == sizeof(uint32_t) );
 
     int current_byte = first_byte;