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 // File: MICmdArgValListOfN.cpp
13 // Overview: CMICmdArgValListOfN implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdArgValListOfN.h"
24 #include "MICmdArgContext.h"
25 #include "MICmdArgValFile.h"
26 #include "MICmdArgValNumber.h"
27 #include "MICmdArgValOptionLong.h"
28 #include "MICmdArgValOptionShort.h"
29 #include "MICmdArgValString.h"
30 #include "MICmdArgValThreadGrp.h"
32 //++ ------------------------------------------------------------------------------------
33 // Details: CMICmdArgValListOfN constructor.
39 CMICmdArgValListOfN::CMICmdArgValListOfN(void)
43 //++ ------------------------------------------------------------------------------------
44 // Details: CMICmdArgValListOfN constructor.
46 // Args: vrArgName - (R) Argument's name to search by.
47 // vbMandatory - (R) True = Yes must be present, false = optional argument.
48 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
49 // veType - (R) The type of argument to look for and create argument object of a certain type.
53 CMICmdArgValListOfN::CMICmdArgValListOfN(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
54 const ArgValType_e veType)
55 : CMICmdArgValListBase(vrArgName, vbMandatory, vbHandleByCmd, veType)
59 //++ ------------------------------------------------------------------------------------
60 // Details: CMICmdArgValListOfN destructor.
66 CMICmdArgValListOfN::~CMICmdArgValListOfN(void)
70 //++ ------------------------------------------------------------------------------------
71 // Details: Parse the command's argument options string and try to extract the list of
72 // arguments based on the argument object type to look for.
74 // Args: vwArgContext - (RW) The command's argument options string.
75 // Return: MIstatus::success - Functional succeeded.
76 // MIstatus::failure - Functional failed.
80 CMICmdArgValListOfN::Validate(CMICmdArgContext &vwArgContext)
82 if (m_eArgType >= eArgValType_count)
84 m_eArgType = eArgValType_invalid;
85 return MIstatus::failure;
88 if (vwArgContext.IsEmpty())
89 return MIstatus::success;
91 const CMIUtilString &rArg(vwArgContext.GetArgsLeftToParse());
92 if (IsListOfN(rArg) && CreateList(rArg))
96 vwArgContext.RemoveArg(rArg);
97 return MIstatus::success;
100 return MIstatus::failure;
103 //++ ------------------------------------------------------------------------------------
104 // Details: Create list of argument objects each holding a value extract from the command
107 // Args: vrTxt - (R) Some options text.
108 // Return: bool - True = yes valid arg, false = no.
112 CMICmdArgValListOfN::CreateList(const CMIUtilString &vrTxt)
114 CMIUtilString::VecString_t vecOptions;
115 if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
116 (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
118 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
119 return MIstatus::failure;
121 else if (vrTxt.Split(" ", vecOptions) == 0)
122 return MIstatus::failure;
124 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
125 while (it != vecOptions.end())
127 const CMIUtilString &rOption = *it;
128 CMICmdArgValBase *pOption = CreationObj(rOption, m_eArgType);
129 if (pOption != nullptr)
130 m_argValue.push_back(pOption);
132 return MIstatus::failure;
138 return MIstatus::success;
141 //++ ------------------------------------------------------------------------------------
142 // Details: Examine the string and determine if it is a valid string type argument.
144 // Args: vrTxt - (R) Some text.
145 // Return: bool - True = yes valid arg, false = no.
149 CMICmdArgValListOfN::IsListOfN(const CMIUtilString &vrTxt) const
151 CMIUtilString::VecString_t vecOptions;
152 if ((m_eArgType == eArgValType_StringQuoted) || (m_eArgType == eArgValType_StringQuotedNumber) ||
153 (m_eArgType == eArgValType_StringQuotedNumberPath) || (m_eArgType == eArgValType_StringAnything))
155 if (vrTxt.SplitConsiderQuotes(" ", vecOptions) == 0)
158 else if (vrTxt.Split(" ", vecOptions) == 0)
161 CMIUtilString::VecString_t::const_iterator it = vecOptions.begin();
162 while (it != vecOptions.end())
164 const CMIUtilString &rOption = *it;
165 if (!IsExpectedCorrectType(rOption, m_eArgType))
175 //++ ------------------------------------------------------------------------------------
176 // Details: Retrieve the list of CMICmdArgValBase derived option objects found following
177 // *this long option argument. For example "list-thread-groups [ --recurse 1 ]"
178 // where 1 is the list of expected option to follow.
181 // Return: CMICmdArgValListBase::VecArgObjPtr_t & - List of options.
184 const CMICmdArgValListBase::VecArgObjPtr_t &
185 CMICmdArgValListOfN::GetExpectedOptions(void) const