1 //===-- MICmdArgValNumber.cpp -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // File: MICmdArgValNumber.cpp
13 // Overview: CMICmdArgValNumber implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdArgValNumber.h"
24 #include "MICmdArgContext.h"
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmdArgValNumber constructor.
33 CMICmdArgValNumber::CMICmdArgValNumber( void )
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmdArgValNumber constructor.
41 // Args: vrArgName - (R) Argument's name to search by.
42 // vbMandatory - (R) True = Yes must be present, false = optional argument.
43 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
47 CMICmdArgValNumber::CMICmdArgValNumber( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd )
48 : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd )
53 //++ ------------------------------------------------------------------------------------
54 // Details: CMICmdArgValNumber destructor.
60 CMICmdArgValNumber::~CMICmdArgValNumber( void )
64 //++ ------------------------------------------------------------------------------------
65 // Details: Parse the command's argument options string and try to extract the value *this
66 // argument is looking for.
68 // Args: vwArgContext - (RW) The command's argument options string.
69 // Return: MIstatus::success - Functional succeeded.
70 // MIstatus::failure - Functional failed.
73 bool CMICmdArgValNumber::Validate( CMICmdArgContext & vwArgContext )
75 if( vwArgContext.IsEmpty() )
76 return MIstatus::success;
78 if( vwArgContext.GetNumberArgsPresent() == 1 )
80 const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() );
81 if( IsArgNumber( rArg ) && ExtractNumber( rArg ) )
85 m_argValue = GetNumber();
86 vwArgContext.RemoveArg( rArg );
87 return MIstatus::success;
90 return MIstatus::failure;
93 // More than one option...
94 const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() );
95 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
96 while( it != vecOptions.end() )
98 const CMIUtilString & rArg( *it );
99 if( IsArgNumber( rArg ) && ExtractNumber( rArg ) )
103 if( vwArgContext.RemoveArg( rArg ) )
106 m_argValue = GetNumber();
107 return MIstatus::success;
110 return MIstatus::failure;
117 return MIstatus::failure;
120 //++ ------------------------------------------------------------------------------------
121 // Details: Examine the string and determine if it is a valid string type argument.
123 // Args: vrTxt - (R) Some text.
124 // Return: bool - True = yes valid arg, false = no.
127 bool CMICmdArgValNumber::IsArgNumber( const CMIUtilString & vrTxt ) const
129 // Look for --someLongOption
130 if( std::string::npos != vrTxt.find( "--" ) )
133 return vrTxt.IsNumber();
136 //++ ------------------------------------------------------------------------------------
137 // Details: Extract the thread group number from the thread group argument.
139 // Args: vrTxt - (R) Some text.
140 // Return: MIstatus::success - Functional succeeded.
141 // MIstatus::failure - Functional failed.
144 bool CMICmdArgValNumber::ExtractNumber( const CMIUtilString & vrTxt )
147 bool bOk = vrTxt.ExtractNumber( nNumber );
150 m_nNumber = static_cast< MIint >( nNumber );
156 //++ ------------------------------------------------------------------------------------
157 // Details: Retrieve the thread group ID found in the argument.
160 // Return: MIuint - Thread group ID.
163 MIint64 CMICmdArgValNumber::GetNumber( void ) const