1 //===-- MICmdArgValOptionLong.h ---------------------------------*- 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 //===----------------------------------------------------------------------===//
13 #include "MICmdArgValListBase.h"
16 class CMICmdArgContext;
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
26 // argument and so extract a value from it.
27 // If *this argument has expected options following it the option
29 // created to hold each of those option's values belong to *this
31 // object and so are deleted when *this object goes out of scope.
32 // Based on the Interpreter pattern.
34 class CMICmdArgValOptionLong : public CMICmdArgValListBase {
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);
47 bool IsArgLongOption(const CMIUtilString &vrTxt) const;
48 const VecArgObjPtr_t &GetExpectedOptions() const;
49 template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
53 // From CMICmdArgValBase
54 /* dtor */ ~CMICmdArgValOptionLong() override;
55 // From CMICmdArgSet::IArg
56 bool Validate(CMICmdArgContext &vArgContext) override;
60 bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
64 virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
65 virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
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
82 //------------------------------------------------------------------------------------
83 // Details: Retrieve the first argument or option value from the list of 1 or
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.
95 template <class T1, typename T2>
96 bool 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;
105 return MIstatus::failure;