]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/tools/lldb-mi/MICmdArgValBase.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / tools / lldb-mi / MICmdArgValBase.h
1 //===-- MICmdArgValBase.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 #include "MICmdArgSet.h"
12 #include "MIUtilString.h"
13
14 //++
15 //============================================================================
16 // Details: MI common code class. Command argument base class. Arguments objects
17 //          needing specialization derived from *this class. An argument knows
18 //          what type of argument it is and how it is to interpret the options
19 //          (context) string to find and validate a matching argument and so
20 //          extract a value from it.
21 //          Argument objects are added to the CMICmdArgSet container object.
22 //          Once added the container they belong to that contain and will be
23 //          deleted when the container goes out of scope. Allocate argument
24 //          objects on the heap and pass in to the Add().
25 //          Note the code is written such that a command will produce an error
26 //          should it be presented with arguments or options it does not
27 //          understand.
28 //          A command can recognise an option or argument then ignore if it
29 //          wishes (a warning is sent to the MI's Log file). This is so it is
30 //          hardwired to fail and catch arguments or options that presented by
31 //          different driver clients.
32 //          Based on the Interpreter pattern.
33 //--
34 class CMICmdArgValBase : public CMICmdArgSet::IArg {
35   // Methods:
36 public:
37   CMICmdArgValBase();
38   CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory,
39                    const bool vbHandleByCmd);
40
41   // Overrideable:
42   ~CMICmdArgValBase() override = default;
43
44   // Overridden:
45   // From CMICmdArgSet::IArg
46   bool GetFound() const override;
47   bool GetIsHandledByCmd() const override;
48   bool GetIsMandatory() const override;
49   bool GetIsMissingOptions() const override;
50   const CMIUtilString &GetName() const override;
51   bool GetValid() const override;
52   bool Validate(CMICmdArgContext &vwArgContext) override;
53
54   // Attributes:
55 protected:
56   bool
57       m_bFound; // True = yes found in arguments options text, false = not found
58   bool m_bValid; // True = yes argument parsed and valid, false = not valid
59   bool
60       m_bMandatory; // True = yes arg must be present, false = optional argument
61   CMIUtilString m_strArgName;
62   bool m_bHandled; // True = Command processes *this option, false = not handled
63   bool m_bIsMissingOptions; // True = Command needs more information, false = ok
64 };
65
66 //++
67 //============================================================================
68 // Details: MI common code class. Templated command argument base class.
69 //--
70 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase {
71   // Methods:
72 public:
73   CMICmdArgValBaseTemplate() = default;
74   CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName,
75                            const bool vbMandatory, const bool vbHandleByCmd);
76   //
77   const T &GetValue() const;
78
79   // Overrideable:
80   ~CMICmdArgValBaseTemplate() override = default;
81
82   // Attributes:
83 protected:
84   T m_argValue;
85 };
86
87 //++
88 // Details: CMICmdArgValBaseTemplate constructor.
89 // Type:    Method.
90 // Args:    vrArgName       - (R) Argument's name to search by.
91 //          vbMandatory     - (R) True = Yes must be present, false = optional
92 //          argument.
93 //          vbHandleByCmd   - (R) True = Command processes *this option, false =
94 //          not handled.
95 // Return:  None.
96 // Throws:  None.
97 //--
98 template <class T>
99 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(
100     const CMIUtilString &vrArgName, const bool vbMandatory,
101     const bool vbHandleByCmd)
102     : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd) {}
103
104 //++
105 // Details: Retrieve the value the argument parsed from the command's argument /
106 // options
107 //          text string.
108 // Type:    Method.
109 // Args:    None.
110 // Return:  Template type & - The arg value of *this object.
111 // Throws:  None.
112 //--
113 template <class T> const T &CMICmdArgValBaseTemplate<T>::GetValue() const {
114   return m_argValue;
115 }