1 //===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #pragma once 11 12 // In-house headers: 13 #include "MICmdArgValListBase.h" 14 15 // Declarations: 16 class CMICmdArgContext; 17 class CMIUtilString; 18 19 //++ 20 //============================================================================ 21 // Details: MI common code class. Command argument class. Arguments object 22 // needing specialization derived from the CMICmdArgValBase class. 23 // An argument knows what type of argument it is and how it is to 24 // interpret the options (context) string to find and validate a 25 // matching 26 // argument and so extract a value from it. 27 // If *this argument has expected options following it the option 28 // objects 29 // created to hold each of those option's values belong to *this 30 // argument 31 // object and so are deleted when *this object goes out of scope. 32 // Based on the Interpreter pattern. 33 //-- 34 class CMICmdArgValOptionLong : public CMICmdArgValListBase { 35 // Methods: 36 public: 37 /* ctor */ CMICmdArgValOptionLong(); 38 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, 39 const bool vbMandatory, 40 const bool vbHandleByCmd); 41 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, 42 const bool vbMandatory, 43 const bool vbHandleByCmd, 44 const ArgValType_e veType, 45 const MIuint vnExpectingNOptions); 46 // 47 bool IsArgLongOption(const CMIUtilString &vrTxt) const; 48 const VecArgObjPtr_t &GetExpectedOptions() const; 49 template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const; 50 51 // Overridden: 52 public: 53 // From CMICmdArgValBase 54 /* dtor */ ~CMICmdArgValOptionLong() override; 55 // From CMICmdArgSet::IArg 56 bool Validate(CMICmdArgContext &vArgContext) override; 57 58 // Methods: 59 protected: 60 bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex); 61 62 // Overrideable: 63 protected: 64 virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const; 65 virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const; 66 67 // Methods: 68 private: 69 void Destroy(); 70 71 // Attributes: 72 private: 73 MIuint m_nExpectingNOptions; // The number of options expected to read 74 // following *this argument 75 VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value 76 // extracted following *this argument 77 ArgValType_e m_eExpectingOptionType; // The type of options expected to read 78 // following *this argument 79 }; 80 81 //++ 82 //------------------------------------------------------------------------------------ 83 // Details: Retrieve the first argument or option value from the list of 1 or 84 // more options 85 // parsed from the command's options string. 86 // Type: Template method. 87 // Args: vrwValue - (W) Templated type return value. 88 // T1 - The argument value's class type of the data hold in 89 // the list of options. 90 // T2 - The type pf the variable which holds the value wanted. 91 // Return: MIstatus::success - Functional succeeded. 92 // MIstatus::failure - Functional failed. List of object was empty. 93 // Throws: None. 94 //-- 95 template <class T1, typename T2> GetExpectedOption(T2 & vrwValue)96bool CMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const { 97 const VecArgObjPtr_t &rVecOptions(GetExpectedOptions()); 98 VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin(); 99 if (it2 != rVecOptions.end()) { 100 const T1 *pOption = static_cast<T1 *>(*it2); 101 vrwValue = pOption->GetValue(); 102 return MIstatus::success; 103 } 104 105 return MIstatus::failure; 106 } 107