1 //===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 #include "MICmdArgValListBase.h"
15 class CMICmdArgContext;
19 //============================================================================
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
25 // argument and so extract a value from it.
26 // If *this argument has expected options following it the option
28 // created to hold each of those option's values belong to *this
30 // object and so are deleted when *this object goes out of scope.
31 // Based on the Interpreter pattern.
33 class CMICmdArgValOptionLong : public CMICmdArgValListBase {
36 /* ctor */ CMICmdArgValOptionLong();
37 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName,
38 const bool vbMandatory,
39 const bool vbHandleByCmd);
40 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName,
41 const bool vbMandatory,
42 const bool vbHandleByCmd,
43 const ArgValType_e veType,
44 const MIuint vnExpectingNOptions);
46 bool IsArgLongOption(const CMIUtilString &vrTxt) const;
47 const VecArgObjPtr_t &GetExpectedOptions() const;
48 template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
52 // From CMICmdArgValBase
53 /* dtor */ ~CMICmdArgValOptionLong() override;
54 // From CMICmdArgSet::IArg
55 bool Validate(CMICmdArgContext &vArgContext) override;
59 bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
63 virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
64 virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
72 MIuint m_nExpectingNOptions; // The number of options expected to read
73 // following *this argument
74 VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value
75 // extracted following *this argument
76 ArgValType_e m_eExpectingOptionType; // The type of options expected to read
77 // following *this argument
81 // Details: Retrieve the first argument or option value from the list of 1 or
83 // parsed from the command's options string.
84 // Type: Template method.
85 // Args: vrwValue - (W) Templated type return value.
86 // T1 - The argument value's class type of the data hold in
87 // the list of options.
88 // T2 - The type pf the variable which holds the value wanted.
89 // Return: MIstatus::success - Functional succeeded.
90 // MIstatus::failure - Functional failed. List of object was empty.
93 template <class T1, typename T2>
94 bool CMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const {
95 const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
96 VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
97 if (it2 != rVecOptions.end()) {
98 const T1 *pOption = static_cast<T1 *>(*it2);
99 vrwValue = pOption->GetValue();
100 return MIstatus::success;
103 return MIstatus::failure;