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