AVR Z-LINKŪ


ParameterParser Class Reference


Detailed Description

Class to parse and store command line parameters for this application.

Definition at line 56 of file createhex.cpp.

Public Member Functions

const std::string & GetFilename () const
const std::vector< byte > & GetMACAddress () const
std::string GetMACAddressString () const
 ParameterParser (size_t argc, const char **argv)
 ~ParameterParser ()

Private Member Functions

std::string CreateHexString (const std::vector< byte > &byteVector) const
std::vector< byteParseHexString (const std::string &hexString) const

Private Attributes

std::string m_filename
std::vector< bytem_MACAddress


Constructor & Destructor Documentation

ParameterParser::ParameterParser ( size_t  argc,
const char **  argv 
)

Ctor taking the argc and argv parameters typically given to any main() function.

Definition at line 128 of file createhex.cpp.

References m_filename, m_MACAddress, and ParseHexString().

00129 {
00130         // Check that argument count is valid.
00131         if( argc != 3 ) {
00132                 std::cout << "Parameters:\n"
00133                         "  filename     - Filename for resulting Intel HEX file\n"
00134                         "  macaddress   - Hex representation of the MAC address (32 hex digits)\n"
00135                         << std::endl;
00136                 throw std::runtime_error( "Not exactly 2 parameters" );
00137         }
00138 
00139         //
00140         // Create strings or string streams from argument character arrays.
00141         // 
00142         std::string arg1( argv[1] ); // Filename
00143         std::string arg2( argv[2] ); // MAC Address
00144 
00145         //
00146         // Copy string arguments and parse non-string arguments.
00147         // 
00148         m_filename = arg1;
00149         
00150         m_MACAddress = ParseHexString( arg2 );
00151         
00152         //
00153         // Check argument validity.
00154         // 
00155         if( m_MACAddress.size() != 16 ) {
00156                 throw std::runtime_error( "MAC address has invalid length" );
00157         }
00158 }

Here is the call graph for this function:

ParameterParser::~ParameterParser (  )  [inline]

Definition at line 70 of file createhex.cpp.

00070 {}


Member Function Documentation

std::string ParameterParser::CreateHexString ( const std::vector< byte > &  byteVector  )  const [private]

Creates an HEX string from a vector of data bytes. Space between every two digits, ie. byte.

Definition at line 108 of file createhex.cpp.

Referenced by GetMACAddressString().

00109 {
00110         std::ostringstream oss;
00111         oss << std::setfill('0') << std::hex;
00112 
00113         // Add all byte last byte with spaces in between.
00114         for( size_t idx = 0; idx < byteVector.size() - 1; ++idx ) {
00115                 oss << std::setw(2) << byteVector.at( idx ) << ' ';
00116         }
00117 
00118         // Add last byte.
00119         if( byteVector.size() > 0 ) {
00120                 oss << std::setw(2) << byteVector.at( byteVector.size()-1 );
00121         }
00122 
00123         return oss.str();
00124 }

const std::string& ParameterParser::GetFilename (  )  const [inline]

Definition at line 75 of file createhex.cpp.

References m_filename.

Referenced by CreateHEXFile(), and main().

00075 { return m_filename; }

const std::vector< byte >& ParameterParser::GetMACAddress (  )  const [inline]

Definition at line 76 of file createhex.cpp.

References m_MACAddress.

Referenced by CreateHEXFile(), and GetMACAddressString().

00076 { return m_MACAddress; }

std::string ParameterParser::GetMACAddressString (  )  const [inline]

Definition at line 78 of file createhex.cpp.

References CreateHexString(), and GetMACAddress().

Referenced by main().

00078 { return CreateHexString( GetMACAddress() ); }

Here is the call graph for this function:

std::vector< byte > ParameterParser::ParseHexString ( const std::string &  hexString  )  const [private]

Parses an unformatted HEX number string. Must be pairs of HEX digits, ie. bytes.

Definition at line 83 of file createhex.cpp.

Referenced by ParameterParser().

00084 {
00085         // String must be even number of hex digits.
00086         if( hexString.size() % 2 != 0 ) {
00087                 throw std::runtime_error( "Hex string does not have even character count" );
00088         }
00089 
00090         //
00091         // Parse hex digit pairs and insert into byte vector.
00092         // 
00093         std::vector< byte > bytes;
00094         for( size_t idx = 0; idx < hexString.size(); idx += 2 ) {
00095                 std::istringstream iss( hexString.substr( idx, 2 ) );
00096                 byte data;
00097                 iss >> std::hex >> data;
00098                 if( !iss ) {
00099                         throw std::runtime_error( "Error parsing hex string \"" + hexString + "\"" );
00100                 }
00101                 bytes.push_back( data );
00102         }
00103         return bytes;
00104 }


Field Documentation

std::string ParameterParser::m_filename [private]

Stores filename parameter.

Definition at line 59 of file createhex.cpp.

Referenced by GetFilename(), and ParameterParser().

std::vector< byte > ParameterParser::m_MACAddress [private]

Stores MAC address.

Definition at line 60 of file createhex.cpp.

Referenced by GetMACAddress(), and ParameterParser().

@DOC_TITLE@
Generated on Sun Oct 29 18:12:00 2006 for AVR414 User's Guide - ATAVRRZ502 - Accessory Kit (PC Tools - HEXMaker) by doxygen 1.4.7