1 //===-- MICmdArgValBase.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "MICmdArgSet.h"
13 #include "MIUtilString.h"
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
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.
35 class CMICmdArgValBase : public CMICmdArgSet::IArg {
39 CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory,
40 const bool vbHandleByCmd);
43 ~CMICmdArgValBase() override = default;
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;
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
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
68 //============================================================================
69 // Details: MI common code class. Templated command argument base class.
71 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase {
74 CMICmdArgValBaseTemplate() = default;
75 CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName,
76 const bool vbMandatory, const bool vbHandleByCmd);
78 const T &GetValue() const;
81 ~CMICmdArgValBaseTemplate() override = default;
89 //------------------------------------------------------------------------------------
90 // Details: CMICmdArgValBaseTemplate constructor.
92 // Args: vrArgName - (R) Argument's name to search by.
93 // vbMandatory - (R) True = Yes must be present, false = optional
95 // vbHandleByCmd - (R) True = Command processes *this option, false =
101 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(
102 const CMIUtilString &vrArgName, const bool vbMandatory,
103 const bool vbHandleByCmd)
104 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd) {}
107 //------------------------------------------------------------------------------------
108 // Details: Retrieve the value the argument parsed from the command's argument /
113 // Return: Template type & - The arg value of *this object.
116 template <class T> const T &CMICmdArgValBaseTemplate<T>::GetValue() const {