]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValListOfN.h
MFV r353613: 10731 zfs: NULL pointer errors
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValListOfN.h
1 //===-- MICmdArgValListOfN.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 // Third party headers:
12 #include <vector>
13
14 // In-house headers:
15 #include "MICmdArgValListBase.h"
16
17 // Declarations:
18 class CMICmdArgContext;
19
20 //++
21 //============================================================================
22 // Details: MI common code class. Command argument class. Arguments object
23 //          needing specialization derived from the CMICmdArgValBase class.
24 //          An argument knows what type of argument it is and how it is to
25 //          interpret the options (context) string to find and validate a
26 //          matching
27 //          argument and so extract a value from it .
28 //          The CMICmdArgValBase objects added to *this ListOfN container belong
29 //          to this container and will be deleted when *this object goes out of
30 //          scope.
31 //          To parse arguments like 'thread-id ...' i.e. 1 10 12 13 ...
32 //          If vbMandatory argument is true it takes on the (...)+ specification
33 //          otherwise assumed to be (...)* specification.
34 //          Based on the Interpreter pattern.
35 //--
36 class CMICmdArgValListOfN : public CMICmdArgValListBase {
37   // Methods:
38 public:
39   /* ctor */ CMICmdArgValListOfN();
40   /* ctor */ CMICmdArgValListOfN(const CMIUtilString &vrArgName,
41                                  const bool vbMandatory,
42                                  const bool vbHandleByCmd,
43                                  const ArgValType_e veType);
44   //
45   const VecArgObjPtr_t &GetExpectedOptions() const;
46   template <class T1, typename T2>
47   bool GetExpectedOption(T2 &vrwValue,
48                          const VecArgObjPtr_t::size_type vnAt = 0) const;
49
50   // Overridden:
51 public:
52   // From CMICmdArgValBase
53   /* dtor */ ~CMICmdArgValListOfN() override;
54   // From CMICmdArgSet::IArg
55   bool Validate(CMICmdArgContext &vArgContext) override;
56
57   // Methods:
58 private:
59   bool IsListOfN(const CMIUtilString &vrTxt) const;
60   bool CreateList(const CMIUtilString &vrTxt);
61 };
62
63 //++
64 // Details: Retrieve the first argument or option value from the list of 1 or
65 // more options
66 //          parsed from the command's options string.
67 // Type:    Template method.
68 // Args:    vrwValue    - (W) Templated type return value.
69 //          vnAt        - (R) Value at the specific position.
70 //          T1          - The argument value's class type of the data hold in
71 //          the list of options.
72 //          T2          - The type pf the variable which holds the value wanted.
73 // Return:  MIstatus::success - Functional succeeded.
74 //          MIstatus::failure - Functional failed. List of object was empty.
75 // Throws:  None.
76 //--
77 template <class T1, typename T2>
78 bool CMICmdArgValListOfN::GetExpectedOption(
79     T2 &vrwValue, const VecArgObjPtr_t::size_type vnAt) const {
80   const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
81   if (rVecOptions.size() <= vnAt)
82     return MIstatus::failure;
83
84   VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin() + vnAt;
85   if (it2 != rVecOptions.end()) {
86     const T1 *pOption = static_cast<T1 *>(*it2);
87     vrwValue = pOption->GetValue();
88     return MIstatus::success;
89   }
90
91   return MIstatus::failure;
92 }