1 //===-- CMICmdArgValBase.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 //===----------------------------------------------------------------------===//
13 #include "MIUtilString.h"
14 #include "MICmdArgSet.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 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.
34 // Authors: Illya Rudkin 14/04/2014.
37 class CMICmdArgValBase : public CMICmdArgSet::IArg
41 /* ctor */ CMICmdArgValBase(void);
42 /* ctor */ CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
46 /* dtor */ virtual ~CMICmdArgValBase(void);
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);
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
69 //++ ============================================================================
70 // Details: MI common code class. Templated command argument base class.
72 // Authors: Illya Rudkin 14/04/2014.
75 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase
79 /* ctor */ CMICmdArgValBaseTemplate(void);
80 /* ctor */ CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
82 const T &GetValue(void) const;
86 /* dtor */ virtual ~CMICmdArgValBaseTemplate(void);
93 //++ ------------------------------------------------------------------------------------
94 // Details: CMICmdArgValBaseTemplate constructor.
100 template <class T> CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(void)
104 //++ ------------------------------------------------------------------------------------
105 // Details: CMICmdArgValBaseTemplate constructor.
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.
114 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
115 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd)
119 //++ ------------------------------------------------------------------------------------
120 // Details: CMICmdArgValBaseTemplate destructor.
121 // Type: Overrideable.
126 template <class T> CMICmdArgValBaseTemplate<T>::~CMICmdArgValBaseTemplate(void)
130 //++ ------------------------------------------------------------------------------------
131 // Details: Retrieve the value the argument parsed from the command's argument / options
135 // Return: Template type & - The arg value of *this object.
140 CMICmdArgValBaseTemplate<T>::GetValue(void) const