]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdArgValOptionLong.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdArgValOptionLong.h
1 //===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #pragma once
10
11 // In-house headers:
12 #include "MICmdArgValListBase.h"
13
14 // Declarations:
15 class CMICmdArgContext;
16 class CMIUtilString;
17
18 //++
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
24 //          matching
25 //          argument and so extract a value from it.
26 //          If *this argument has expected options following it the option
27 //          objects
28 //          created to hold each of those option's values belong to *this
29 //          argument
30 //          object and so are deleted when *this object goes out of scope.
31 //          Based on the Interpreter pattern.
32 //--
33 class CMICmdArgValOptionLong : public CMICmdArgValListBase {
34   // Methods:
35 public:
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);
45   //
46   bool IsArgLongOption(const CMIUtilString &vrTxt) const;
47   const VecArgObjPtr_t &GetExpectedOptions() const;
48   template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
49
50   // Overridden:
51 public:
52   // From CMICmdArgValBase
53   /* dtor */ ~CMICmdArgValOptionLong() override;
54   // From CMICmdArgSet::IArg
55   bool Validate(CMICmdArgContext &vArgContext) override;
56
57   // Methods:
58 protected:
59   bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
60
61   // Overrideable:
62 protected:
63   virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
64   virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
65
66   // Methods:
67 private:
68   void Destroy();
69
70   // Attributes:
71 private:
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
78 };
79
80 //++
81 // Details: Retrieve the first argument or option value from the list of 1 or
82 // more options
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.
91 // Throws:  None.
92 //--
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;
101   }
102
103   return MIstatus::failure;
104 }