1 //===-- MICmdArgValPrintValues.cpp ------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "MICmdArgValPrintValues.h"
11 #include "MICmdArgContext.h"
14 // Details: CMICmdArgValPrintValues constructor.
20 CMICmdArgValPrintValues::CMICmdArgValPrintValues() : m_nPrintValues(0) {}
23 // Details: CMICmdArgValPrintValues constructor.
25 // Args: vrArgName - (R) Argument's name to search by.
26 // vbMandatory - (R) True = Yes must be present, false = optional
28 // vbHandleByCmd - (R) True = Command processes *this option, false =
33 CMICmdArgValPrintValues::CMICmdArgValPrintValues(const CMIUtilString &vrArgName,
34 const bool vbMandatory,
35 const bool vbHandleByCmd)
36 : CMICmdArgValBaseTemplate(vrArgName, vbMandatory, vbHandleByCmd),
40 // Details: CMICmdArgValPrintValues destructor.
46 CMICmdArgValPrintValues::~CMICmdArgValPrintValues() {}
49 // Details: Parse the command's argument options string and try to extract the
51 // argument is looking for.
53 // Args: vwArgContext - (RW) The command's argument options string.
54 // Return: MIstatus::success - Functional succeeded.
55 // MIstatus::failure - Functional failed.
58 bool CMICmdArgValPrintValues::Validate(CMICmdArgContext &vwArgContext) {
59 if (vwArgContext.IsEmpty())
60 return m_bMandatory ? MIstatus::failure : MIstatus::success;
62 const CMIUtilString strArg(vwArgContext.GetArgs()[0]);
63 if (IsArgPrintValues(strArg) && ExtractPrintValues(strArg)) {
66 m_argValue = GetPrintValues();
67 vwArgContext.RemoveArg(strArg);
68 return MIstatus::success;
71 return MIstatus::failure;
75 // Details: Examine the string and determine if it is a valid string type
78 // Args: vrTxt - (R) Some text.
79 // Return: bool - True = yes valid arg, false = no.
82 bool CMICmdArgValPrintValues::IsArgPrintValues(
83 const CMIUtilString &vrTxt) const {
84 return (CMIUtilString::Compare(vrTxt, "0") ||
85 CMIUtilString::Compare(vrTxt, "--no-values") ||
86 CMIUtilString::Compare(vrTxt, "1") ||
87 CMIUtilString::Compare(vrTxt, "--all-values") ||
88 CMIUtilString::Compare(vrTxt, "2") ||
89 CMIUtilString::Compare(vrTxt, "--simple-values"));
93 // Details: Extract the print-values from the print-values argument.
95 // Args: vrTxt - (R) Some text.
96 // Return: MIstatus::success - Functional succeeded.
97 // MIstatus::failure - Functional failed.
100 bool CMICmdArgValPrintValues::ExtractPrintValues(const CMIUtilString &vrTxt) {
101 if (CMIUtilString::Compare(vrTxt, "0") ||
102 CMIUtilString::Compare(vrTxt, "--no-values"))
104 else if (CMIUtilString::Compare(vrTxt, "1") ||
105 CMIUtilString::Compare(vrTxt, "--all-values"))
107 else if (CMIUtilString::Compare(vrTxt, "2") ||
108 CMIUtilString::Compare(vrTxt, "--simple-values"))
111 return MIstatus::failure;
113 return MIstatus::success;
117 // Details: Retrieve the print-values found in the argument.
120 // Return: MIuint - The print-values.
123 MIuint CMICmdArgValPrintValues::GetPrintValues() const {
124 return m_nPrintValues;