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