1 //===-- Platform.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 //===----------------------------------------------------------------------===//
11 // File: MICmdArgValBase.h
13 // Overview: CMICmdArgValBase interface.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
25 #include "MIUtilString.h"
26 #include "MICmdArgSet.h"
28 //++ ============================================================================
29 // Details: MI common code class. Command argument base class. Arguments objects
30 // needing specialization derived from *this class. An argument knows
31 // what type of argument it is and how it is to interpret the options
32 // (context) string to find and validate a matching argument and so
33 // extract a value from it.
34 // Argument objects are added to the CMICmdArgSet container object.
35 // Once added the container they belong to that contain and will be
36 // deleted when the container goes out of scope. Allocate argument
37 // objects on the heap and pass in to the Add().
38 // Note the code is written such that a command will produce an error
39 // should it be presented with arguments or options it does not understand.
40 // A command can recognise an option or argument then ignore if it
41 // wishes (a warning is sent to the MI's Log file). This is so it is
42 // hardwired to fail and catch arguments or options that presented by
43 // different driver clients.
44 // Based on the Interpreter pattern.
46 // Authors: Illya Rudkin 14/04/2014.
49 class CMICmdArgValBase : public CMICmdArgSet::IArg
53 /* ctor */ CMICmdArgValBase(void);
54 /* ctor */ CMICmdArgValBase(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
58 /* dtor */ virtual ~CMICmdArgValBase(void);
62 // From CMICmdArgSet::IArg
63 virtual bool GetFound(void) const;
64 virtual bool GetIsHandledByCmd(void) const;
65 virtual bool GetIsMandatory(void) const;
66 virtual bool GetIsMissingOptions(void) const;
67 virtual const CMIUtilString &GetName(void) const;
68 virtual bool GetValid(void) const;
69 virtual bool Validate(CMICmdArgContext &vwArgContext);
73 bool m_bFound; // True = yes found in arguments options text, false = not found
74 bool m_bValid; // True = yes argument parsed and valid, false = not valid
75 bool m_bMandatory; // True = yes arg must be present, false = optional argument
76 CMIUtilString m_strArgName;
77 bool m_bHandled; // True = Command processes *this option, false = not handled
78 bool m_bIsMissingOptions; // True = Command needs more information, false = ok
81 //++ ============================================================================
82 // Details: MI common code class. Templated command argument base class.
84 // Authors: Illya Rudkin 14/04/2014.
87 template <class T> class CMICmdArgValBaseTemplate : public CMICmdArgValBase
91 /* ctor */ CMICmdArgValBaseTemplate(void);
92 /* ctor */ CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
94 const T &GetValue(void) const;
98 /* dtor */ virtual ~CMICmdArgValBaseTemplate(void);
105 //++ ------------------------------------------------------------------------------------
106 // Details: CMICmdArgValBaseTemplate constructor.
112 template <class T> CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(void)
116 //++ ------------------------------------------------------------------------------------
117 // Details: CMICmdArgValBaseTemplate constructor.
119 // Args: vrArgName - (R) Argument's name to search by.
120 // vbMandatory - (R) True = Yes must be present, false = optional argument.
121 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
126 CMICmdArgValBaseTemplate<T>::CMICmdArgValBaseTemplate(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
127 : CMICmdArgValBase(vrArgName, vbMandatory, vbHandleByCmd)
131 //++ ------------------------------------------------------------------------------------
132 // Details: CMICmdArgValBaseTemplate destructor.
133 // Type: Overrideable.
138 template <class T> CMICmdArgValBaseTemplate<T>::~CMICmdArgValBaseTemplate(void)
142 //++ ------------------------------------------------------------------------------------
143 // Details: Retrieve the value the argument parsed from the command's argument / options
147 // Return: Template type & - The arg value of *this object.
152 CMICmdArgValBaseTemplate<T>::GetValue(void) const