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