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 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
16 #include "MICmdArgSet.h"
17 #include "MIUtilString.h"
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
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.
39 class CMICmdArgValBase : public CMICmdArgSet::IArg {
43 CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory,
44 const bool vbHandleByCmd);
47 ~CMICmdArgValBase() override = default;
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;
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
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
72 //============================================================================
73 // Details: MI common code class. Templated command argument base class.
75 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase {
78 CMICmdArgValBaseTemplate() = default;
79 CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName,
80 const bool vbMandatory, const bool vbHandleByCmd);
82 const T &GetValue() const;
85 ~CMICmdArgValBaseTemplate() override = default;
93 //------------------------------------------------------------------------------------
94 // Details: CMICmdArgValBaseTemplate constructor.
96 // Args: vrArgName - (R) Argument's name to search by.
97 // vbMandatory - (R) True = Yes must be present, false = optional
99 // vbHandleByCmd - (R) True = Command processes *this option, false =
105 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(
106 const CMIUtilString &vrArgName, const bool vbMandatory,
107 const bool vbHandleByCmd)
108 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd) {}
111 //------------------------------------------------------------------------------------
112 // Details: Retrieve the value the argument parsed from the command's argument /
117 // Return: Template type & - The arg value of *this object.
120 template <class T> const T &CMICmdArgValBaseTemplate<T>::GetValue() const {