1 //===-- MICmdArgValListOfN.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 "MICmdArgValListOfN.h"
12 #include "MICmdArgContext.h"
13 #include "MICmdArgValFile.h"
14 #include "MICmdArgValNumber.h"
15 #include "MICmdArgValOptionLong.h"
16 #include "MICmdArgValOptionShort.h"
17 #include "MICmdArgValString.h"
18 #include "MICmdArgValThreadGrp.h"
21 //------------------------------------------------------------------------------------
22 // Details: CMICmdArgValListOfN constructor.
28 CMICmdArgValListOfN::CMICmdArgValListOfN() {}
31 //------------------------------------------------------------------------------------
32 // Details: CMICmdArgValListOfN constructor.
34 // Args: vrArgName - (R) Argument's name to search by.
35 // vbMandatory - (R) True = Yes must be present, false = optional
37 // vbHandleByCmd - (R) True = Command processes *this option, false =
39 // veType - (R) The type of argument to look for and create
40 // argument object of a certain type.
44 CMICmdArgValListOfN::CMICmdArgValListOfN(const CMIUtilString &vrArgName,
45 const bool vbMandatory,
46 const bool vbHandleByCmd,
47 const ArgValType_e veType)
48 : CMICmdArgValListBase(vrArgName, vbMandatory, vbHandleByCmd, veType) {}
51 //------------------------------------------------------------------------------------
52 // Details: CMICmdArgValListOfN destructor.
58 CMICmdArgValListOfN::~CMICmdArgValListOfN() {}
61 //------------------------------------------------------------------------------------
62 // Details: Parse the command's argument options string and try to extract the
64 // arguments based on the argument object type to look for.
66 // Args: vwArgContext - (RW) The command's argument options string.
67 // Return: MIstatus::success - Functional succeeded.
68 // MIstatus::failure - Functional failed.
71 bool CMICmdArgValListOfN::Validate(CMICmdArgContext &vwArgContext) {
72 if (m_eArgType >= eArgValType_count) {
73 m_eArgType = eArgValType_invalid;
74 return MIstatus::failure;
77 if (vwArgContext.IsEmpty())
78 return m_bMandatory ? MIstatus::failure : MIstatus::success;
80 const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
81 if (IsListOfN(rArg) && CreateList(rArg)) {
84 vwArgContext.RemoveArg(rArg);
85 return MIstatus::success;
87 return MIstatus::failure;
91 //------------------------------------------------------------------------------------
92 // Details: Create list of argument objects each holding a value extract from
96 // Args: vrTxt - (R) Some options text.
97 // Return: bool - True = yes valid arg, false = no.
100 bool CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt) {
101 CMIUtilString::VecString_t vecOptions;
102 if ((m_eArgType == eArgValType_StringQuoted) ||
103 (m_eArgType == eArgValType_StringQuotedNumber) ||
104 (m_eArgType == eArgValType_StringQuotedNumberPath) ||
105 (m_eArgType == eArgValType_StringAnything)) {
106 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
107 return MIstatus::failure;
108 } else if (vrTxt.Split(" ", vecOptions) == 0)
109 return MIstatus::failure;
111 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
112 while (it != vecOptions.end()) {
113 const CMIUtilString &rOption = *it;
114 CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType);
115 if (pOption != nullptr)
116 m_argValue.push_back(pOption);
118 return MIstatus::failure;
124 return MIstatus::success;
128 //------------------------------------------------------------------------------------
129 // Details: Examine the string and determine if it is a valid string type
132 // Args: vrTxt - (R) Some text.
133 // Return: bool - True = yes valid arg, false = no.
136 bool CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const {
137 CMIUtilString::VecString_t vecOptions;
138 if ((m_eArgType == eArgValType_StringQuoted) ||
139 (m_eArgType == eArgValType_StringQuotedNumber) ||
140 (m_eArgType == eArgValType_StringQuotedNumberPath) ||
141 (m_eArgType == eArgValType_StringAnything)) {
142 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
144 } else if (vrTxt.Split(" ", vecOptions) == 0)
147 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
148 while (it != vecOptions.end()) {
149 const CMIUtilString &rOption = *it;
150 if (!IsExpectedCorrectType(rOption, m_eArgType))
161 //------------------------------------------------------------------------------------
162 // Details: Retrieve the list of CMICmdArgValBase derived option objects found
164 // *this long option argument. For example "list-thread-groups [
166 // where 1 is the list of expected option to follow.
169 // Return: CMICmdArgValListBase::VecArgObjPtr_t & - List of options.
172 const CMICmdArgValListBase::VecArgObjPtr_t &
173 CMICmdArgValListOfN::GetExpectedOptions() const {