1 //===-- MICmdArgValPrintValues.cpp ------------------------------*- 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 #include "MICmdArgValPrintValues.h"
12 #include "MICmdArgContext.h"
14 //++ ------------------------------------------------------------------------------------
15 // Details: CMICmdArgValPrintValues constructor.
21 CMICmdArgValPrintValues::CMICmdArgValPrintValues(void)
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmdArgValPrintValues constructor.
29 // Args: vrArgName - (R) Argument's name to search by.
30 // vbMandatory - (R) True = Yes must be present, false = optional argument.
31 // vbHandleByCmd - (R) True = Command processes *this option, false = not handled.
35 CMICmdArgValPrintValues::CMICmdArgValPrintValues(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd)
36 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd)
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmdArgValPrintValues destructor.
48 CMICmdArgValPrintValues::~CMICmdArgValPrintValues(void)
52 //++ ------------------------------------------------------------------------------------
53 // Details: Parse the command's argument options string and try to extract the value *this
54 // argument is looking for.
56 // Args: vwArgContext - (RW) The command's argument options string.
57 // Return: MIstatus::success - Functional succeeded.
58 // MIstatus::failure - Functional failed.
62 CMICmdArgValPrintValues::Validate(CMICmdArgContext &vwArgContext)
64 if (vwArgContext.IsEmpty())
65 return m_bMandatory ? MIstatus::failure : MIstatus::success;
67 const CMIUtilString strArg(vwArgContext.GetArgs()[0]);
68 if (IsArgPrintValues(strArg) && ExtractPrintValues(strArg))
72 m_argValue = GetPrintValues();
73 vwArgContext.RemoveArg(strArg);
74 return MIstatus::success;
77 return MIstatus::failure;
80 //++ ------------------------------------------------------------------------------------
81 // Details: Examine the string and determine if it is a valid string type argument.
83 // Args: vrTxt - (R) Some text.
84 // Return: bool - True = yes valid arg, false = no.
88 CMICmdArgValPrintValues::IsArgPrintValues(const CMIUtilString &vrTxt) const
90 return (CMIUtilString::Compare(vrTxt, "0") || CMIUtilString::Compare(vrTxt, "--no-values") ||
91 CMIUtilString::Compare(vrTxt, "1") || CMIUtilString::Compare(vrTxt, "--all-values") ||
92 CMIUtilString::Compare(vrTxt, "2") || CMIUtilString::Compare(vrTxt, "--simple-values"));
95 //++ ------------------------------------------------------------------------------------
96 // Details: Extract the print-values from the print-values argument.
98 // Args: vrTxt - (R) Some text.
99 // Return: MIstatus::success - Functional succeeded.
100 // MIstatus::failure - Functional failed.
104 CMICmdArgValPrintValues::ExtractPrintValues(const CMIUtilString &vrTxt)
106 if (CMIUtilString::Compare(vrTxt, "0") || CMIUtilString::Compare(vrTxt, "--no-values"))
108 else if (CMIUtilString::Compare(vrTxt, "1") || CMIUtilString::Compare(vrTxt, "--all-values"))
110 else if (CMIUtilString::Compare(vrTxt, "2") || CMIUtilString::Compare(vrTxt, "--simple-values"))
113 return MIstatus::failure;
115 return MIstatus::success;
118 //++ ------------------------------------------------------------------------------------
119 // Details: Retrieve the print-values found in the argument.
122 // Return: MIuint - The print-values.
126 CMICmdArgValPrintValues::GetPrintValues(void) const
128 return m_nPrintValues;