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, const ArgValType_e veType )
71 : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd )
72 , m_eArgType( veType )
76 //++ ------------------------------------------------------------------------------------
77 // Details: CMICmdArgValListBase destructor.
83 CMICmdArgValListBase::~CMICmdArgValListBase( void )
89 //++ ------------------------------------------------------------------------------------
90 // Details: Tear down resources used by *this object.
96 void CMICmdArgValListBase::Destroy( void )
99 VecArgObjPtr_t::const_iterator it = m_argValue.begin();
100 while( it != m_argValue.end() )
102 CMICmdArgValBase * pArgObj = *it;
111 //++ ------------------------------------------------------------------------------------
112 // Details: Create an CMICmdArgValBase derived object matching the type specified
113 // and put the option or argument's value inside it.
115 // Args: vrTxt - (R) Text version the option or argument.
116 // veType - (R) The type of argument or option object to create.
117 // Return: CMICmdArgValBase * - Option object holding the value.
118 // - NULL = Functional failed.
121 CMICmdArgValBase * CMICmdArgValListBase::CreationObj( const CMIUtilString & vrTxt, const ArgValType_e veType ) const
123 CMICmdArgValBase * pOptionObj = nullptr;
126 case eArgValType_File:
127 pOptionObj = new CMICmdArgValFile();
129 case eArgValType_Consume:
130 pOptionObj = new CMICmdArgValConsume();
132 case eArgValType_Number:
133 pOptionObj = new CMICmdArgValNumber();
135 case eArgValType_OptionLong:
136 pOptionObj = new CMICmdArgValOptionLong();
138 case eArgValType_OptionShort:
139 pOptionObj = new CMICmdArgValOptionShort();
141 case eArgValType_String:
142 pOptionObj = new CMICmdArgValString();
144 case eArgValType_StringQuoted:
145 pOptionObj = new CMICmdArgValString( true, false, false );
147 case eArgValType_StringQuotedNumber:
148 pOptionObj = new CMICmdArgValString( true, true, false );
150 case eArgValType_StringQuotedNumberPath:
151 pOptionObj = new CMICmdArgValString( true, true, true );
153 case eArgValType_StringAnything:
154 pOptionObj = new CMICmdArgValString( true );
156 case eArgValType_ThreadGrp:
157 pOptionObj = new CMICmdArgValThreadGrp();
163 CMICmdArgContext argCntxt( vrTxt );
164 if( !pOptionObj->Validate( argCntxt ) )
170 //++ ------------------------------------------------------------------------------------
171 // Details: Validate the option or argument is the correct type.
173 // Args: vrTxt - (R) Text version the option or argument.
174 // veType - (R) The type of value to expect.
175 // Return: bool - True = Yes expected type present, False = no.
178 bool CMICmdArgValListBase::IsExpectedCorrectType( const CMIUtilString & vrTxt, const ArgValType_e veType ) const
183 case eArgValType_File:
184 bValid = CMICmdArgValFile().IsFilePath( vrTxt );
186 case eArgValType_Consume:
187 bValid = CMICmdArgValConsume().IsOk();
189 case eArgValType_Number:
190 bValid = CMICmdArgValNumber().IsArgNumber( vrTxt );
192 case eArgValType_OptionLong:
193 bValid = CMICmdArgValOptionLong().IsArgLongOption( vrTxt );
195 case eArgValType_OptionShort:
196 bValid = CMICmdArgValOptionShort().IsArgShortOption( vrTxt );
198 case eArgValType_String:
199 bValid = CMICmdArgValString().IsStringArg( vrTxt );
201 case eArgValType_StringQuoted:
202 bValid = CMICmdArgValString( true, false, false ).IsStringArg( vrTxt );
204 case eArgValType_StringQuotedNumber:
205 bValid = CMICmdArgValString( true, true, false ).IsStringArg( vrTxt );
207 case eArgValType_StringQuotedNumberPath:
208 bValid = CMICmdArgValString( true, true, true ).IsStringArg( vrTxt );
210 case eArgValType_StringAnything:
211 bValid = CMICmdArgValString( true ).IsStringArg( vrTxt );
213 case eArgValType_ThreadGrp:
214 bValid = CMICmdArgValThreadGrp().IsArgThreadGrp( vrTxt );