1 //===-- MICmdArgValThreadGrp.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 #include "MICmdArgValThreadGrp.h"
12 #include "MICmdArgContext.h"
15 //------------------------------------------------------------------------------------
16 // Details: CMICmdArgValThreadGrp constructor.
22 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp() : m_nThreadGrp(0) {}
25 //------------------------------------------------------------------------------------
26 // Details: CMICmdArgValThreadGrp constructor.
28 // Args: vrArgName - (R) Argument's name to search by.
29 // vbMandatory - (R) True = Yes must be present, false = optional
31 // vbHandleByCmd - (R) True = Command processes *this option, false =
36 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp(const CMIUtilString &vrArgName,
37 const bool vbMandatory,
38 const bool vbHandleByCmd)
39 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd),
43 //------------------------------------------------------------------------------------
44 // Details: CMICmdArgValThreadGrp destructor.
50 CMICmdArgValThreadGrp::~CMICmdArgValThreadGrp() {}
53 //------------------------------------------------------------------------------------
54 // Details: Parse the command's argument options string and try to extract the
56 // argument is looking for.
58 // Args: vwArgContext - (RW) The command's argument options string.
59 // Return: MIstatus::success - Functional succeeded.
60 // MIstatus::failure - Functional failed.
63 bool CMICmdArgValThreadGrp::Validate(CMICmdArgContext &vwArgContext) {
64 if (vwArgContext.IsEmpty())
65 return m_bMandatory ? MIstatus::failure : MIstatus::success;
67 if (vwArgContext.GetNumberArgsPresent() == 1) {
68 const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
69 if (IsArgThreadGrp(rArg) && ExtractNumber(rArg)) {
72 m_argValue = GetNumber();
73 vwArgContext.RemoveArg(rArg);
74 return MIstatus::success;
76 return MIstatus::failure;
79 // More than one option...
80 const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
81 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
82 while (it != vecOptions.end()) {
83 const CMIUtilString &rArg(*it);
84 if (IsArgThreadGrp(rArg) && ExtractNumber(rArg)) {
87 if (vwArgContext.RemoveArg(rArg)) {
89 m_argValue = GetNumber();
90 return MIstatus::success;
92 return MIstatus::failure;
99 return MIstatus::failure;
103 //------------------------------------------------------------------------------------
104 // Details: Examine the string and determine if it is a valid string type
107 // Args: vrTxt - (R) Some text.
108 // Return: bool - True = yes valid arg, false = no.
111 bool CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const {
112 // Look for i1 i2 i3....
113 const MIint nPos = vrTxt.find('i');
117 const CMIUtilString strNum = vrTxt.substr(1);
118 if (!strNum.IsNumber())
125 //------------------------------------------------------------------------------------
126 // Details: Extract the thread group number from the thread group argument.
128 // Args: vrTxt - (R) Some text.
129 // Return: MIstatus::success - Functional succeeded.
130 // MIstatus::failure - Functional failed.
133 bool CMICmdArgValThreadGrp::ExtractNumber(const CMIUtilString &vrTxt) {
134 const CMIUtilString strNum = vrTxt.substr(1);
136 bool bOk = strNum.ExtractNumber(nNumber);
138 m_nThreadGrp = static_cast<MIuint>(nNumber);
145 //------------------------------------------------------------------------------------
146 // Details: Retrieve the thread group ID found in the argument.
149 // Return: MIuint - Thread group ID.
152 MIuint CMICmdArgValThreadGrp::GetNumber() const { return m_nThreadGrp; }