1 //===-- MICmdArgValBase.h ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
11 #include "MICmdArgSet.h"
12 #include "MIUtilString.h"
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
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.
34 class CMICmdArgValBase : public CMICmdArgSet::IArg {
38 CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory,
39 const bool vbHandleByCmd);
42 ~CMICmdArgValBase() override = default;
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;
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
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
67 //============================================================================
68 // Details: MI common code class. Templated command argument base class.
70 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase {
73 CMICmdArgValBaseTemplate() = default;
74 CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName,
75 const bool vbMandatory, const bool vbHandleByCmd);
77 const T &GetValue() const;
80 ~CMICmdArgValBaseTemplate() override = default;
88 // Details: CMICmdArgValBaseTemplate constructor.
90 // Args: vrArgName - (R) Argument's name to search by.
91 // vbMandatory - (R) True = Yes must be present, false = optional
93 // vbHandleByCmd - (R) True = Command processes *this option, false =
99 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(
100 const CMIUtilString &vrArgName, const bool vbMandatory,
101 const bool vbHandleByCmd)
102 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd) {}
105 // Details: Retrieve the value the argument parsed from the command's argument /
110 // Return: Template type & - The arg value of *this object.
113 template <class T> const T &CMICmdArgValBaseTemplate<T>::GetValue() const {