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"
20 //++ ------------------------------------------------------------------------------------
21 // Details: CMICmdArgValListOfN constructor.
27 CMICmdArgValListOfN::CMICmdArgValListOfN(void)
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 argument.
36 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
37 // veType - (R) The type of argument to look for and create argument object of a certain type.
41 CMICmdArgValListOfN::CMICmdArgValListOfN(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
42 const ArgValType_e veType)
43 : CMICmdArgValListBase(vrArgName, vbMandatory, vbHandleByCmd, veType)
47 //++ ------------------------------------------------------------------------------------
48 // Details: CMICmdArgValListOfN destructor.
54 CMICmdArgValListOfN::~CMICmdArgValListOfN(void)
58 //++ ------------------------------------------------------------------------------------
59 // Details: Parse the command's argument options string and try to extract the list of
60 // arguments based on the argument object type to look for.
62 // Args: vwArgContext - (RW) The command's argument options string.
63 // Return: MIstatus::success - Functional succeeded.
64 // MIstatus::failure - Functional failed.
68 CMICmdArgValListOfN::Validate(CMICmdArgContext &vwArgContext)
70 if (m_eArgType >= eArgValType_count)
72 m_eArgType = eArgValType_invalid;
73 return MIstatus::failure;
76 if (vwArgContext.IsEmpty())
77 return m_bMandatory ? MIstatus::failure : MIstatus::success;
79 const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
80 if (IsListOfN(rArg) && CreateList(rArg))
84 vwArgContext.RemoveArg(rArg);
85 return MIstatus::success;
88 return MIstatus::failure;
91 //++ ------------------------------------------------------------------------------------
92 // Details: Create list of argument objects each holding a value extract from the command
95 // Args: vrTxt - (R) Some options text.
96 // Return: bool - True = yes valid arg, false = no.
100 CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt)
102 CMIUtilString::VecString_t vecOptions;
103 if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
104 (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
106 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
107 return MIstatus::failure;
109 else if (vrTxt.Split(" ", vecOptions) == 0)
110 return MIstatus::failure;
112 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
113 while (it != vecOptions.end())
115 const CMIUtilString &rOption = *it;
116 CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType);
117 if (pOption != nullptr)
118 m_argValue.push_back(pOption);
120 return MIstatus::failure;
126 return MIstatus::success;
129 //++ ------------------------------------------------------------------------------------
130 // Details: Examine the string and determine if it is a valid string type argument.
132 // Args: vrTxt - (R) Some text.
133 // Return: bool - True = yes valid arg, false = no.
137 CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const
139 CMIUtilString::VecString_t vecOptions;
140 if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
141 (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
143 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
146 else if (vrTxt.Split(" ", vecOptions) == 0)
149 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
150 while (it != vecOptions.end())
152 const CMIUtilString &rOption = *it;
153 if (!IsExpectedCorrectType(rOption, m_eArgType))
163 //++ ------------------------------------------------------------------------------------
164 // Details: Retrieve the list of CMICmdArgValBase derived option objects found following
165 // *this long option argument. For example "list-thread-groups [ --recurse 1 ]"
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(void) const