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 #include "MICmdArgSet.h"
13 #include "MIUtilString.h"
14
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
28 // understand.
29 // A command can recognise an option or argument then ignore if it
30 // wishes (a warning is sent to the MI's Log file). This is so it is
31 // hardwired to fail and catch arguments or options that presented by
32 // different driver clients.
33 // Based on the Interpreter pattern.
34 //--
35 class CMICmdArgValBase : public CMICmdArgSet::IArg {
36 // Methods:
37 public:
38 CMICmdArgValBase();
39 CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory,
40 const bool vbHandleByCmd);
41
42 // Overrideable:
43 ~CMICmdArgValBase() override = default;
44
45 // Overridden:
46 // From CMICmdArgSet::IArg
47 bool GetFound() const override;
48 bool GetIsHandledByCmd() const override;
49 bool GetIsMandatory() const override;
50 bool GetIsMissingOptions() const override;
51 const CMIUtilString &GetName() const override;
52 bool GetValid() const override;
53 bool Validate(CMICmdArgContext &vwArgContext) override;
54
55 // Attributes:
56 protected:
57 bool
58 m_bFound; // True = yes found in arguments options text, false = not found
59 bool m_bValid; // True = yes argument parsed and valid, false = not valid
60 bool
61 m_bMandatory; // True = yes arg must be present, false = optional argument
62 CMIUtilString m_strArgName;
63 bool m_bHandled; // True = Command processes *this option, false = not handled
64 bool m_bIsMissingOptions; // True = Command needs more information, false = ok
65 };
66
67 //++
68 //============================================================================
69 // Details: MI common code class. Templated command argument base class.
70 //--
71 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase {
72 // Methods:
73 public:
74 CMICmdArgValBaseTemplate() = default;
75 CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName,
76 const bool vbMandatory, const bool vbHandleByCmd);
77 //
78 const T &GetValue() const;
79
80 // Overrideable:
81 ~CMICmdArgValBaseTemplate() override = default;
82
83 // Attributes:
84 protected:
85 T m_argValue;
86 };
87
88 //++
89 //------------------------------------------------------------------------------------
90 // Details: CMICmdArgValBaseTemplate constructor.
91 // Type: Method.
92 // Args: vrArgName - (R) Argument's name to search by.
93 // vbMandatory - (R) True = Yes must be present, false = optional
94 // argument.
95 // vbHandleByCmd - (R) True = Command processes *this option, false =
96 // not handled.
97 // Return: None.
98 // Throws: None.
99 //--
100 template <class T>
CMICmdArgValBaseTemplate(const CMIUtilString & vrArgName,const bool vbMandatory,const bool vbHandleByCmd)101 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(
102 const CMIUtilString &vrArgName, const bool vbMandatory,
103 const bool vbHandleByCmd)
104 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd) {}
105
106 //++
107 //------------------------------------------------------------------------------------
108 // Details: Retrieve the value the argument parsed from the command's argument /
109 // options
110 // text string.
111 // Type: Method.
112 // Args: None.
113 // Return: Template type & - The arg value of *this object.
114 // Throws: None.
115 //--
GetValue()116 template <class T> const T &CMICmdArgValBaseTemplate<T>::GetValue() const {
117 return m_argValue;
118 }
119