1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
//===-- MICmdArgValListBase.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// In-house headers:
#include "MICmdArgValListBase.h"
#include "MICmdArgContext.h"
#include "MICmdArgValConsume.h"
#include "MICmdArgValFile.h"
#include "MICmdArgValNumber.h"
#include "MICmdArgValOptionLong.h"
#include "MICmdArgValOptionShort.h"
#include "MICmdArgValString.h"
#include "MICmdArgValThreadGrp.h"
//++
//------------------------------------------------------------------------------------
// Details: CMICmdArgValListBase constructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMICmdArgValListBase::CMICmdArgValListBase()
: m_eArgType(eArgValType_invalid) {}
//++
//------------------------------------------------------------------------------------
// Details: CMICmdArgValListBase constructor.
// Type: Method.
// Args: vrArgName - (R) Argument's name to search by.
// vbMandatory - (R) True = Yes must be present, false = optional
// argument.
// vbHandleByCmd - (R) True = Command processes *this option, false =
// not handled.
// Return: None.
// Throws: None.
//--
CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName,
const bool vbMandatory,
const bool vbHandleByCmd)
: CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd),
m_eArgType(eArgValType_invalid) {}
//++
//------------------------------------------------------------------------------------
// Details: CMICmdArgValListBase constructor.
// Type: Method.
// Args: vrArgName - (R) Argument's name to search by.
// vbMandatory - (R) True = Yes must be present, false = optional
// argument.
// vbHandleByCmd - (R) True = Command processes *this option, false =
// not handled.
// veType - (R) The type of argument to look for and create
// argument object of a certain type.
// Return: None.
// Throws: None.
//--
CMICmdArgValListBase::CMICmdArgValListBase(const CMIUtilString &vrArgName,
const bool vbMandatory,
const bool vbHandleByCmd,
const ArgValType_e veType)
: CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd),
m_eArgType(veType) {}
//++
//------------------------------------------------------------------------------------
// Details: CMICmdArgValListBase destructor.
// Type: Overridden.
// Args: None.
// Return: None.
// Throws: None.
//--
CMICmdArgValListBase::~CMICmdArgValListBase() {
// Tidy up
Destroy();
}
//++
//------------------------------------------------------------------------------------
// Details: Tear down resources used by *this object.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
void CMICmdArgValListBase::Destroy() {
// Tidy up
VecArgObjPtr_t::const_iterator it = m_argValue.begin();
while (it != m_argValue.end()) {
CMICmdArgValBase *pArgObj = *it;
delete pArgObj;
// Next
++it;
}
m_argValue.clear();
}
//++
//------------------------------------------------------------------------------------
// Details: Create an CMICmdArgValBase derived object matching the type
// specified
// and put the option or argument's value inside it.
// Type: Method.
// Args: vrTxt - (R) Text version the option or argument.
// veType - (R) The type of argument or option object to create.
// Return: CMICmdArgValBase * - Option object holding the value.
// - NULL = Functional failed.
// Throws: None.
//--
CMICmdArgValBase *
CMICmdArgValListBase::CreationObj(const CMIUtilString &vrTxt,
const ArgValType_e veType) const {
CMICmdArgValBase *pOptionObj = nullptr;
switch (veType) {
case eArgValType_File:
pOptionObj = new CMICmdArgValFile();
break;
case eArgValType_Consume:
pOptionObj = new CMICmdArgValConsume();
break;
case eArgValType_Number:
pOptionObj = new CMICmdArgValNumber();
break;
case eArgValType_OptionLong:
pOptionObj = new CMICmdArgValOptionLong();
break;
case eArgValType_OptionShort:
pOptionObj = new CMICmdArgValOptionShort();
break;
case eArgValType_String:
pOptionObj = new CMICmdArgValString();
break;
case eArgValType_StringQuoted:
pOptionObj = new CMICmdArgValString(true, false, false);
break;
case eArgValType_StringQuotedNumber:
pOptionObj = new CMICmdArgValString(true, true, false);
break;
case eArgValType_StringQuotedNumberPath:
pOptionObj = new CMICmdArgValString(true, true, true);
break;
case eArgValType_StringAnything:
pOptionObj = new CMICmdArgValString(true);
break;
case eArgValType_ThreadGrp:
pOptionObj = new CMICmdArgValThreadGrp();
break;
default:
return nullptr;
}
CMICmdArgContext argCntxt(vrTxt);
if (!pOptionObj->Validate(argCntxt))
return nullptr;
return pOptionObj;
}
//++
//------------------------------------------------------------------------------------
// Details: Validate the option or argument is the correct type.
// Type: Method.
// Args: vrTxt - (R) Text version the option or argument.
// veType - (R) The type of value to expect.
// Return: bool - True = Yes expected type present, False = no.
// Throws: None.
//--
bool CMICmdArgValListBase::IsExpectedCorrectType(
const CMIUtilString &vrTxt, const ArgValType_e veType) const {
bool bValid = false;
switch (veType) {
case eArgValType_File:
bValid = CMICmdArgValFile().IsFilePath(vrTxt);
break;
case eArgValType_Consume:
bValid = CMICmdArgValConsume().IsOk();
break;
case eArgValType_Number:
bValid = CMICmdArgValNumber().IsArgNumber(vrTxt);
break;
case eArgValType_OptionLong:
bValid = CMICmdArgValOptionLong().IsArgLongOption(vrTxt);
break;
case eArgValType_OptionShort:
bValid = CMICmdArgValOptionShort().IsArgShortOption(vrTxt);
break;
case eArgValType_String:
bValid = CMICmdArgValString().IsStringArg(vrTxt);
break;
case eArgValType_StringQuoted:
bValid = CMICmdArgValString(true, false, false).IsStringArg(vrTxt);
break;
case eArgValType_StringQuotedNumber:
bValid = CMICmdArgValString(true, true, false).IsStringArg(vrTxt);
break;
case eArgValType_StringQuotedNumberPath:
bValid = CMICmdArgValString(true, true, true).IsStringArg(vrTxt);
break;
case eArgValType_StringAnything:
bValid = CMICmdArgValString(true).IsStringArg(vrTxt);
break;
case eArgValType_ThreadGrp:
bValid = CMICmdArgValThreadGrp().IsArgThreadGrp(vrTxt);
break;
default:
return false;
}
return bValid;
}
|