Index: trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp
===================================================================
--- trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp	(revision 872)
+++ trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp	(revision 1313)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
- * Copyright (c) 2010-2014, ITU/ISO/IEC
+ * Copyright (c) 2010-2015, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -46,12 +46,15 @@
   {
     assert( right.empty( ) );
-    
+
     for( ; ; )
     {
       assert( left.good( ) );
-      
+
       double bitrate;
       left >> bitrate;
-      if( left.fail( ) ) break;
+      if( left.fail( ) )
+      {
+        break;
+      }
       if( bitrate <= ( double )0.0 )
       {
@@ -62,6 +65,9 @@
         right.push_back( bitrate );
       }
-      if( !left.good( ) ) break;
-      
+      if( !left.good( ) )
+      {
+        break;
+      }
+
       if( left.peek( ) == ' ' )
       {
@@ -74,5 +80,5 @@
     }
   }
-  
+
   /// Makes a next guess for a single Lambda-modifier based on only one previous guess
   /// \param initialAdjustmentParameter The proportionality to use between the target bitrate and the previous guess
@@ -88,5 +94,5 @@
     assert( ( double )0.0 < previousPoint.lambdaModifier );
     assert( ( double )0.0 < previousPoint.bitrate );
-    
+
     double extrapolated( previousPoint.lambdaModifier * targetBitrate / previousPoint.bitrate );
     return previousPoint.lambdaModifier + initialAdjustmentParameter * ( extrapolated - previousPoint.lambdaModifier );
@@ -102,5 +108,5 @@
   assert( point1.lambdaModifier != point2.lambdaModifier );
   assert( point1.bitrate != point2.bitrate );
-  
+
   // Calculate and return the result
   double denominator( point1.bitrate - point2.bitrate );
@@ -119,7 +125,7 @@
   assert( interDampeningFactor <= ( double )1.0 );
   assert( !pointList.empty( ) );
-  
+
   double preliminaryResult;
-  
+
   if( 1 == pointList.size( ) )  // If there is only one prevous point, then we cannot interpolate, so we call incrementLambdaModifier
   {
@@ -132,5 +138,5 @@
     ++i;
     Point point2 = *i;
-    
+
     // If the slope is either horizontal or vertical, we cannot interpolate
     if( point1.lambdaModifier == point2.lambdaModifier || point1.bitrate == point2.bitrate )
@@ -143,7 +149,7 @@
     }
   }
-  
+
   double previousResult( pointList.back( ).lambdaModifier );
-  
+
   // Apply "intra dampening"
   {
@@ -159,5 +165,5 @@
     }
   }
-  
+
   // Apply "inter dampening factor".  If necessary, reduce the factor until a positive result is acheived.
   double result;
@@ -180,5 +186,5 @@
     return result;
   }
-  
+
   /// Calculates the inter dampening factor based
   /// \param parameter The inter dampening parameter which determines how severely the inter dampening factor is affected by Lambda-modifier changes at previous temporal layers
@@ -202,5 +208,5 @@
   assert( !targetBitrateVector.empty( ) );
   assert( !metaLogEntryList.empty( ) );
-  
+
   double cumulativeDelta( 0.0 );
   std::vector< double > resultVector;
@@ -212,6 +218,9 @@
     pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
     ++j;
-    if( j != metaLogEntryList.rend( ) ) pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
-    
+    if( j != metaLogEntryList.rend( ) )
+    {
+      pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
+    }
+
     // Calculate the new Lambda-modifier guess and add it to the result vector
     const double newLambdaModifier( guessLambdaModifier(
@@ -221,10 +230,10 @@
         interDampeningFactor( 50.0, cumulativeDelta ) ) );
     resultVector.push_back( newLambdaModifier );
-    
+
     // Increment the cumulativeDelta
     const double oldLambdaModifier( pointList.back( ).lambdaModifier );
     cumulativeDelta += std::abs( newLambdaModifier - oldLambdaModifier ) / oldLambdaModifier;
   }
-  
+
   return resultVector;
 }
@@ -240,7 +249,10 @@
     while( i.good( ) && character != i.get( ) )
       ;
-    if( !i.good( ) ) throw MetaLogParseException( );
-  }
-  
+    if( !i.good( ) )
+    {
+      throw MetaLogParseException( );
+    }
+  }
+
   /// Parses a Lambda-modifier map
   /// \param right The map to write the output to
@@ -250,25 +262,61 @@
     {
       assert( left.good( ) );
-      
+
       // Ignore the "-LM"
-      if( '-' != left.get( ) ) left.setstate( std::istream::failbit );
-      if( !left.good( ) ) break;
-      if( 'L' != left.get( ) ) left.setstate( std::istream::failbit );
-      if( !left.good( ) ) break;
-      if( 'M' != left.get( ) ) left.setstate( std::istream::failbit );
-      if( !left.good( ) ) break;
-      
+      if( '-' != left.get( ) )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( !left.good( ) )
+      {
+        break;
+      }
+      if( 'L' != left.get( ) )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( !left.good( ) )
+      {
+        break;
+      }
+      if( 'M' != left.get( ) )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( !left.good( ) )
+      {
+        break;
+      }
+
       // Parse the index
       long indexLong;
       left >> indexLong;
-      if( !left.good( ) ) break;
-      if( indexLong < std::numeric_limits< unsigned char >::min( ) ) left.setstate( std::istream::failbit );
-      if( std::numeric_limits< unsigned char >::max( ) < indexLong ) left.setstate( std::istream::failbit );
-      if( !left.good( ) ) break;
+      if( !left.good( ) )
+      {
+        break;
+      }
+      if( indexLong < std::numeric_limits< unsigned char >::min( ) )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( std::numeric_limits< unsigned char >::max( ) < indexLong )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( !left.good( ) )
+      {
+        break;
+      }
       unsigned char index( ( unsigned char )indexLong );
-      
-      if( ' ' != left.get( ) ) left.setstate( std::istream::failbit );
-      if( !left.good( ) ) break;
-      
+
+      if( ' ' != left.get( ) )
+      {
+        left.setstate( std::istream::failbit );
+      }
+      if( !left.good( ) )
+      {
+        break;
+      }
+
       // Parse the Lambda-modifier
       double lambdaModifier;
@@ -282,6 +330,9 @@
         right[ index ] = lambdaModifier;
       }
-      if( !left.good( ) ) break;
-      
+      if( !left.good( ) )
+      {
+        break;
+      }
+
       // If we peek and see a space, then there should be more Lambda-modifiers to parse.  Otherwise, we are finished.
       if( left.peek( ) == ' ' )
@@ -295,5 +346,5 @@
     }
   }
-  
+
   /// Extracts the indexes from the given maps
   /// \return The set of indexes
@@ -322,10 +373,13 @@
     throw InitialAdjustmentParameterParseException( );
   }
-  
+
   // Parse the targets
   std::vector< double > targetVector;
   parseBitrateVector( targetsIstream, targetVector );
-  if( targetVector.empty( ) || targetsIstream.fail( ) || targetsIstream.good( ) ) throw TargetsParseException( );
-  
+  if( targetVector.empty( ) || targetsIstream.fail( ) || targetsIstream.good( ) )
+  {
+    throw TargetsParseException( );
+  }
+
   // Parse the metalog
   std::list< MetaLogEntry< std::map< unsigned char, double > > > metaLogEntryList;
@@ -335,32 +389,62 @@
     MetaLogEntry< std::map< unsigned char, double > > entry;
     parseLambdaModifierMap( metaLogIstream, entry.lambdaModifiers );
-    if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
-    
+    if( !metaLogIstream.good( ) )
+    {
+      throw MetaLogParseException( );
+    }
+
     // Skip the ';'
-    if( ';' != metaLogIstream.get( ) ) throw MetaLogParseException( );
-    if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
-    
+    if( ';' != metaLogIstream.get( ) )
+    {
+      throw MetaLogParseException( );
+    }
+    if( !metaLogIstream.good( ) )
+    {
+      throw MetaLogParseException( );
+    }
+
     // Parse the bitrates
     parseBitrateVector( metaLogIstream, entry.bitrateVector );
-    if( metaLogIstream.fail( ) ) throw MetaLogParseException( );
+    if( metaLogIstream.fail( ) )
+    {
+      throw MetaLogParseException( );
+    }
     metaLogEntryList.push_back( entry );
-    
-    if( !metaLogIstream.good( ) ) break;
-    if( metaLogIstream.get( ) != '\n' ) throw MetaLogParseException( );
+
+    if( !metaLogIstream.good( ) )
+    {
+      break;
+    }
+    if( metaLogIstream.get( ) != '\n' )
+    {
+      throw MetaLogParseException( );
+    }
     metaLogIstream.peek( );
   } while( metaLogIstream.good( ) );
-  if( metaLogEntryList.empty( ) ) throw MetaLogParseException( );  // The meta-log should not be empty
-  
+  if( metaLogEntryList.empty( ) )
+  {
+    throw MetaLogParseException( );  // The meta-log should not be empty
+  }
+
   // Initialize firstIndexVector and check that the sizes and indexes match
   std::set< unsigned char > firstIndexSet( indexSetFromMap( metaLogEntryList.front( ).lambdaModifiers ) );
-  if( firstIndexSet.size( ) != targetVector.size( ) ) throw MismatchedIndexesException( );
+  if( firstIndexSet.size( ) != targetVector.size( ) )
+  {
+    throw MismatchedIndexesException( );
+  }
   for( std::list< MetaLogEntry< std::map< unsigned char, double > > >::const_iterator i( metaLogEntryList.begin( ) );
       i != metaLogEntryList.end( );
       ++i )
   {
-    if( indexSetFromMap( i->lambdaModifiers ) != firstIndexSet ) throw MismatchedIndexesException( );
-    if( i->bitrateVector.size( ) != targetVector.size( ) ) throw MismatchedIndexesException( );
-  }
-  
+    if( indexSetFromMap( i->lambdaModifiers ) != firstIndexSet )
+    {
+      throw MismatchedIndexesException( );
+    }
+    if( i->bitrateVector.size( ) != targetVector.size( ) )
+    {
+      throw MismatchedIndexesException( );
+    }
+  }
+
   // Initialize simplifiedMetaLogEntryList
   std::list< MetaLogEntry< std::vector< double > > > simplifiedMetaLogEntryList;
@@ -376,8 +460,8 @@
     simplifiedMetaLogEntryList.back( ).bitrateVector = i->bitrateVector;
   }
-  
+
   // Run the calculations
   std::vector< double > resultVector( guessLambdaModifiers( initialAdjustmentParameter, targetVector, simplifiedMetaLogEntryList ) );
-  
+
   // Output the results
   std::set< unsigned char >::const_iterator indexIter( firstIndexSet.begin( ) );
@@ -385,10 +469,13 @@
   do
   {
-    if( indexIter != firstIndexSet.begin( ) ) o << " ";
+    if( indexIter != firstIndexSet.begin( ) )
+    {
+      o << " ";
+    }
     o << "-LM" << ( long )( *indexIter ) << " ";
     o.setf( std::ostream::fixed, std::ostream::floatfield );
     o.precision( 7 );
     o << ( *resultIter );
-    
+
     ++indexIter;
     ++resultIter;
