Listing 5: ExtendedCommands.cpp

#include <iostream>  
#include <string>      
#include "ExtendedCommands.h"

namespace out_of_band_example
{

ExtendedCommands::ExtendedCommands(int argc, char* argv[])
  : tools::CommandLine( argc, argv )
{ }

ExtendedCommands::~ExtendedCommands()
{ }

bool
ExtendedCommands::GetOption( const std::string& optionName,
       const std::string& alternateName,
       std::string& optionValue,
       const std::string&  defaultValue ) const
{
  bool found = false;

  if( Exists(optionName) )
  {  
    optionValue = GetByName( optionName );
    found = true;
  }
  else if( alternateName.length() > 0  && Exists(alternateName) )
  {  
    optionValue = GetByName( alternateName );
    found = true;
  }
  else if( defaultValue.length() > 0)
  {  
    optionValue = defaultValue;
    found = true;  // "Found" the default value.
  }
  return found;
}

std::string
ExtendedCommands::SynthesizeOptionString
                    (  const std::string& optionName,
                       const std::string& alternateName,
                       const std::string& defaultValue ) const
{
  std::string optionValue;
  std::string result;

  if( GetOption( optionName, alternateName, optionValue,
                 defaultValue) )
  {  
    result =  std::string(" -") + optionName + " ";
    if( optionValue.length() > 0 )
    {
      result += "\"" + optionValue + "\"";
    }
  }
  return result;
}

} // end of the out_of_band_example namespace

— End of Listing —