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 // File: MICmdArgValThreadGrp.cpp
13 // Overview: CMICmdArgValThreadGrp implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdArgValThreadGrp.h"
24 #include "MICmdArgContext.h"
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmdArgValThreadGrp constructor.
33 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp(void)
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmdArgValThreadGrp 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 CMICmdArgValThreadGrp::CMICmdArgValThreadGrp(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
48 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
53 //++ ------------------------------------------------------------------------------------
54 // Details: CMICmdArgValThreadGrp destructor.
60 CMICmdArgValThreadGrp::~CMICmdArgValThreadGrp(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.
74 CMICmdArgValThreadGrp::Validate(CMICmdArgContext &vwArgContext)
76 if (vwArgContext.IsEmpty())
77 return MIstatus::success;
79 if (vwArgContext.GetNumberArgsPresent() == 1)
81 const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
82 if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
86 m_argValue = GetNumber();
87 vwArgContext.RemoveArg(rArg);
88 return MIstatus::success;
91 return MIstatus::failure;
94 // More than one option...
95 const CMIUtilString::VecString_t vecOptions(vwArgContext.GetArgs());
96 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
97 while (it != vecOptions.end())
99 const CMIUtilString &rArg(*it);
100 if (IsArgThreadGrp(rArg) && ExtractNumber(rArg))
104 if (vwArgContext.RemoveArg(rArg))
107 m_argValue = GetNumber();
108 return MIstatus::success;
111 return MIstatus::failure;
118 return MIstatus::failure;
121 //++ ------------------------------------------------------------------------------------
122 // Details: Examine the string and determine if it is a valid string type argument.
124 // Args: vrTxt - (R) Some text.
125 // Return: bool - True = yes valid arg, false = no.
129 CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
131 // Look for i1 i2 i3....
132 const MIint nPos = vrTxt.find_first_of("i");
136 const CMIUtilString strNum = vrTxt.substr(1).c_str();
137 if (!strNum.IsNumber())
143 //++ ------------------------------------------------------------------------------------
144 // Details: Extract the thread group number from the thread group argument.
146 // Args: vrTxt - (R) Some text.
147 // Return: MIstatus::success - Functional succeeded.
148 // MIstatus::failure - Functional failed.
152 CMICmdArgValThreadGrp::ExtractNumber(const CMIUtilString &vrTxt)
154 const CMIUtilString strNum = vrTxt.substr(1).c_str();
156 bool bOk = strNum.ExtractNumber(nNumber);
159 m_nThreadGrp = static_cast<MIuint>(nNumber);
165 //++ ------------------------------------------------------------------------------------
166 // Details: Retrieve the thread group ID found in the argument.
169 // Return: MIuint - Thread group ID.
173 CMICmdArgValThreadGrp::GetNumber(void) const