Example #1
0
// ****************************************************************************
//
//  Function Name:	RNumberDialog::CreateGraphicsList
//
//  Description:		Create '|' delimited string of graphics names
//
//  Returns:			void
//
//  Exceptions:		None
//
// ****************************************************************************
void RNumberDialog::CreateGraphicsList( RMBCString& rList )
{
    //
    // Only allocate memory for the collection searcher once..
    if( m_pGraphicCollectionSearcher == NULL || m_fRebuiltGraphicArrays )
    {
        // We rebuilt the graphic arrays, so we have to recreate the searcher.
        if (m_pGraphicCollectionSearcher != NULL)
        {
            delete m_pGraphicCollectionSearcher;
        }
        m_pGraphicCollectionSearcher = new 	RCollectionSearcher<RNumberGraphicSearchCollection>(m_rCollectionArray);
    }
    // Find all the graphics
    RSearchResultArray* pResultArray = m_pGraphicCollectionSearcher->SearchCollections();

    // Now iterate through all the graphics and insert them into
    // the string
    RSearchResultIterator resultIter( pResultArray->Start() );
    RSearchResultIterator resultIterEnd( pResultArray->End() );

    // The index has to start at 1 because the None selection is at zero
    for (int nIdx = 1; resultIter != resultIterEnd; resultIter++, nIdx++ )
    {
        rList += RMBCString( (LPSTR)(*resultIter).namePtr );
        rList += RMBCString( kListFieldSeperator );

        //
        // Keep track of graphics and their indexes...
        m_cGraphicMap.SetAt( (*resultIter).id, (*resultIter) );
        m_cGraphicArray.SetAtGrow( nIdx, (*resultIter) );
    }
}
void guessLambdaModifiers(
    std::ostream& o,
    std::istream& initialAdjustmentParameterIstream,
    std::istream& targetsIstream,
    std::istream& metaLogIstream )
{
  // Parse the initialAdjustmentParameter
  double initialAdjustmentParameter;
  initialAdjustmentParameterIstream >> initialAdjustmentParameter;
  if( initialAdjustmentParameterIstream.fail( ) || initialAdjustmentParameterIstream.good( ) )
  {
    throw InitialAdjustmentParameterParseException( );
  }
  
  // Parse the targets
  std::vector< double > targetVector;
  parseBitrateVector( targetsIstream, targetVector );
  if( targetVector.empty( ) || targetsIstream.fail( ) || targetsIstream.good( ) ) throw TargetsParseException( );
  
  // Parse the metalog
  std::list< MetaLogEntry< std::map< unsigned char, double > > > metaLogEntryList;
  do
  {
    // Parse the Lambda-modifiers
    MetaLogEntry< std::map< unsigned char, double > > entry;
    parseLambdaModifierMap( metaLogIstream, entry.lambdaModifiers );
    if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
    
    // Skip the ';'
    if( ';' != metaLogIstream.get( ) ) throw MetaLogParseException( );
    if( !metaLogIstream.good( ) ) throw MetaLogParseException( );
    
    // Parse the bitrates
    parseBitrateVector( metaLogIstream, entry.bitrateVector );
    if( metaLogIstream.fail( ) ) throw MetaLogParseException( );
    metaLogEntryList.push_back( entry );
    
    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
  
  // 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( );
  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( );
  }
  
  // Initialize simplifiedMetaLogEntryList
  std::list< MetaLogEntry< std::vector< double > > > simplifiedMetaLogEntryList;
  for( std::list< MetaLogEntry< std::map< unsigned char, double > > >::const_iterator i( metaLogEntryList.begin( ) );
      i != metaLogEntryList.end( );
      ++i )
  {
    simplifiedMetaLogEntryList.push_back( MetaLogEntry< std::vector< double > >( ) );
    for( std::map< unsigned char, double >::const_iterator j( i->lambdaModifiers.begin( ) ); j != i->lambdaModifiers.end( ); ++j )
    {
      simplifiedMetaLogEntryList.back( ).lambdaModifiers.push_back( j->second );
    }
    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( ) );
  std::vector< double >::const_iterator resultIter( resultVector.begin( ) );
  do
  {
    if( indexIter != firstIndexSet.begin( ) ) o << " ";
    o << "-LM" << ( long )( *indexIter ) << " ";
    o.setf( std::ostream::fixed, std::ostream::floatfield );
    o.precision( 7 );
    o << ( *resultIter );
    
    ++indexIter;
    ++resultIter;
  } while( indexIter != firstIndexSet.end( ) );
  assert( resultIter == resultVector.end( ) );  // The index set and the result vector should be the same size
}