1 //===-- MICmdArgValListBase.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: MICmdArgValListBase.cpp
13 // Overview: CMICmdArgValListBase implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdArgValListBase.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"
31 #include "MICmdArgValConsume.h"
33 //++ ------------------------------------------------------------------------------------
34 // Details: CMICmdArgValListBase constructor.
40 CMICmdArgValListBase::CMICmdArgValListBase(void)
41 : m_eArgType(eArgValType_invalid)
45 //++ ------------------------------------------------------------------------------------
46 // Details: CMICmdArgValListBase constructor.
48 // Args: vrArgName - (R) Argument's name to search by.
49 // vbMandatory - (R) True = Yes must be present, false = optional argument.
50 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
54 CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
55 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
56 , m_eArgType(eArgValType_invalid)
60 //++ ------------------------------------------------------------------------------------
61 // Details: CMICmdArgValListBase constructor.
63 // Args: vrArgName - (R) Argument's name to search by.
64 // vbMandatory - (R) True = Yes must be present, false = optional argument.
65 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
66 // veType - (R) The type of argument to look for and create argument object of a certain type.
70 CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
71 const ArgValType_e veType)
72 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
77 //++ ------------------------------------------------------------------------------------
78 // Details: CMICmdArgValListBase destructor.
84 CMICmdArgValListBase::~CMICmdArgValListBase(void)
90 //++ ------------------------------------------------------------------------------------
91 // Details: Tear down resources used by *this object.
98 CMICmdArgValListBase::Destroy(void)
101 VecArgObjPtr_t::const_iterator it = m_argValue.begin();
102 while (it != m_argValue.end())
104 CMICmdArgValBase *pArgObj = *it;
113 //++ ------------------------------------------------------------------------------------
114 // Details: Create an CMICmdArgValBase derived object matching the type specified
115 // and put the option or argument's value inside it.
117 // Args: vrTxt - (R) Text version the option or argument.
118 // veType - (R) The type of argument or option object to create.
119 // Return: CMICmdArgValBase * - Option object holding the value.
120 // - NULL = Functional failed.
124 CMICmdArgValListBase::CreationObj(const CMIUtilString &vrTxt, const ArgValType_e veType) const
126 CMICmdArgValBase *pOptionObj = nullptr;
129 case eArgValType_File:
130 pOptionObj = new CMICmdArgValFile();
132 case eArgValType_Consume:
133 pOptionObj = new CMICmdArgValConsume();
135 case eArgValType_Number:
136 pOptionObj = new CMICmdArgValNumber();
138 case eArgValType_OptionLong:
139 pOptionObj = new CMICmdArgValOptionLong();
141 case eArgValType_OptionShort:
142 pOptionObj = new CMICmdArgValOptionShort();
144 case eArgValType_String:
145 pOptionObj = new CMICmdArgValString();
147 case eArgValType_StringQuoted:
148 pOptionObj = new CMICmdArgValString(true, false, false);
150 case eArgValType_StringQuotedNumber:
151 pOptionObj = new CMICmdArgValString(true, true, false);
153 case eArgValType_StringQuotedNumberPath:
154 pOptionObj = new CMICmdArgValString(true, true, true);
156 case eArgValType_StringAnything:
157 pOptionObj = new CMICmdArgValString(true);
159 case eArgValType_ThreadGrp:
160 pOptionObj = new CMICmdArgValThreadGrp();
166 CMICmdArgContext argCntxt(vrTxt);
167 if (!pOptionObj->Validate(argCntxt))
173 //++ ------------------------------------------------------------------------------------
174 // Details: Validate the option or argument is the correct type.
176 // Args: vrTxt - (R) Text version the option or argument.
177 // veType - (R) The type of value to expect.
178 // Return: bool - True = Yes expected type present, False = no.
182 CMICmdArgValListBase::IsExpectedCorrectType(const CMIUtilString &vrTxt, const ArgValType_e veType) const
187 case eArgValType_File:
188 bValid = CMICmdArgValFile().IsFilePath(vrTxt);
190 case eArgValType_Consume:
191 bValid = CMICmdArgValConsume().IsOk();
193 case eArgValType_Number:
194 bValid = CMICmdArgValNumber().IsArgNumber(vrTxt);
196 case eArgValType_OptionLong:
197 bValid = CMICmdArgValOptionLong().IsArgLongOption(vrTxt);
199 case eArgValType_OptionShort:
200 bValid = CMICmdArgValOptionShort().IsArgShortOption(vrTxt);
202 case eArgValType_String:
203 bValid = CMICmdArgValString().IsStringArg(vrTxt);
205 case eArgValType_StringQuoted:
206 bValid = CMICmdArgValString(true, false, false).IsStringArg(vrTxt);
208 case eArgValType_StringQuotedNumber:
209 bValid = CMICmdArgValString(true, true, false).IsStringArg(vrTxt);
211 case eArgValType_StringQuotedNumberPath:
212 bValid = CMICmdArgValString(true, true, true).IsStringArg(vrTxt);
214 case eArgValType_StringAnything:
215 bValid = CMICmdArgValString(true).IsStringArg(vrTxt);
217 case eArgValType_ThreadGrp:
218 bValid = CMICmdArgValThreadGrp().IsArgThreadGrp(vrTxt);