]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValBase.h
Update LLDB snapshot to upstream r241361
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValBase.h
1 //===-- CMICmdArgValBase.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 // In-house headers:
13 #include "MIUtilString.h"
14 #include "MICmdArgSet.h"
15
16 //++ ============================================================================
17 // Details: MI common code class. Command argument base class. Arguments objects
18 //          needing specialization derived from *this class. An argument knows
19 //          what type of argument it is and how it is to interpret the options
20 //          (context) string to find and validate a matching argument and so
21 //          extract a value from it.
22 //          Argument objects are added to the CMICmdArgSet container object.
23 //          Once added the container they belong to that contain and will be
24 //          deleted when the container goes out of scope. Allocate argument
25 //          objects on the heap and pass in to the Add().
26 //          Note the code is written such that a command will produce an error
27 //          should it be presented with arguments or options it does not 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 // Gotchas: None.
34 // Authors: Illya Rudkin 14/04/2014.
35 // Changes: None.
36 //--
37 class CMICmdArgValBase : public CMICmdArgSet::IArg
38 {
39     // Methods:
40   public:
41     /* ctor */ CMICmdArgValBase(void);
42     /* ctor */ CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
43
44     // Overrideable:
45   public:
46     /* dtor */ virtual ~CMICmdArgValBase(void);
47
48     // Overridden:
49   public:
50     // From CMICmdArgSet::IArg
51     virtual bool GetFound(void) const;
52     virtual bool GetIsHandledByCmd(void) const;
53     virtual bool GetIsMandatory(void) const;
54     virtual bool GetIsMissingOptions(void) const;
55     virtual const CMIUtilString &GetName(void) const;
56     virtual bool GetValid(void) const;
57     virtual bool Validate(CMICmdArgContext &vwArgContext);
58
59     // Attributes:
60   protected:
61     bool m_bFound;     // True = yes found in arguments options text, false = not found
62     bool m_bValid;     // True = yes argument parsed and valid, false = not valid
63     bool m_bMandatory; // True = yes arg must be present, false = optional argument
64     CMIUtilString m_strArgName;
65     bool m_bHandled;          // True = Command processes *this option, false = not handled
66     bool m_bIsMissingOptions; // True = Command needs more information, false = ok
67 };
68
69 //++ ============================================================================
70 // Details: MI common code class. Templated command argument base class.
71 // Gotchas: None.
72 // Authors: Illya Rudkin 14/04/2014.
73 // Changes: None.
74 //--
75 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase
76 {
77     // Methods:
78   public:
79     /* ctor */ CMICmdArgValBaseTemplate(void);
80     /* ctor */ CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
81     //
82     const T &GetValue(void) const;
83
84     // Overrideable:
85   public:
86     /* dtor */ virtual ~CMICmdArgValBaseTemplate(void);
87
88     // Attributes:
89   protected:
90     T m_argValue;
91 };
92
93 //++ ------------------------------------------------------------------------------------
94 // Details: CMICmdArgValBaseTemplate constructor.
95 // Type:    Method.
96 // Args:    None.
97 // Return:  None.
98 // Throws:  None.
99 //--
100 template <class T> CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(void)
101 {
102 }
103
104 //++ ------------------------------------------------------------------------------------
105 // Details: CMICmdArgValBaseTemplate constructor.
106 // Type:    Method.
107 // Args:    vrArgName       - (R) Argument's name to search by.
108 //          vbMandatory     - (R) True = Yes must be present, false = optional argument.
109 //          vbHandleByCmd   - (R) True = Command processes *this option, false = not handled.
110 // Return:  None.
111 // Throws:  None.
112 //--
113 template <class T>
114 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
115     : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd)
116 {
117 }
118
119 //++ ------------------------------------------------------------------------------------
120 // Details: CMICmdArgValBaseTemplate destructor.
121 // Type:    Overrideable.
122 // Args:    None.
123 // Return:  None.
124 // Throws:  None.
125 //--
126 template <class T> CMICmdArgValBaseTemplate<T>::~CMICmdArgValBaseTemplate(void)
127 {
128 }
129
130 //++ ------------------------------------------------------------------------------------
131 // Details: Retrieve the value the argument parsed from the command's argument / options
132 //          text string.
133 // Type:    Method.
134 // Args:    None.
135 // Return:  Template type & - The arg value of *this object.
136 // Throws:  None.
137 //--
138 template <class T>
139 const T &
140 CMICmdArgValBaseTemplate<T>::GetValue(void) const
141 {
142     return m_argValue;
143 }