1 //===-- MICmdArgValListOfN.h ------------------------------------*- 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 //===----------------------------------------------------------------------===//
11 // Third party headers:
15 #include "MICmdArgValListBase.h"
18 class CMICmdArgContext;
21 //============================================================================
22 // Details: MI common code class. Command argument class. Arguments object
23 // needing specialization derived from the CMICmdArgValBase class.
24 // An argument knows what type of argument it is and how it is to
25 // interpret the options (context) string to find and validate a
27 // argument and so extract a value from it .
28 // The CMICmdArgValBase objects added to *this ListOfN container belong
29 // to this container and will be deleted when *this object goes out of
31 // To parse arguments like 'thread-id ...' i.e. 1 10 12 13 ...
32 // If vbMandatory argument is true it takes on the (...)+ specification
33 // otherwise assumed to be (...)* specification.
34 // Based on the Interpreter pattern.
36 class CMICmdArgValListOfN : public CMICmdArgValListBase {
39 /* ctor */ CMICmdArgValListOfN();
40 /* ctor */ CMICmdArgValListOfN(const CMIUtilString &vrArgName,
41 const bool vbMandatory,
42 const bool vbHandleByCmd,
43 const ArgValType_e veType);
45 const VecArgObjPtr_t &GetExpectedOptions() const;
46 template <class T1, typename T2>
47 bool GetExpectedOption(T2 &vrwValue,
48 const VecArgObjPtr_t::size_type vnAt = 0) const;
52 // From CMICmdArgValBase
53 /* dtor */ ~CMICmdArgValListOfN() override;
54 // From CMICmdArgSet::IArg
55 bool Validate(CMICmdArgContext &vArgContext) override;
59 bool IsListOfN(const CMIUtilString &vrTxt) const;
60 bool CreateList(const CMIUtilString &vrTxt);
64 // Details: Retrieve the first argument or option value from the list of 1 or
66 // parsed from the command's options string.
67 // Type: Template method.
68 // Args: vrwValue - (W) Templated type return value.
69 // vnAt - (R) Value at the specific position.
70 // T1 - The argument value's class type of the data hold in
71 // the list of options.
72 // T2 - The type pf the variable which holds the value wanted.
73 // Return: MIstatus::success - Functional succeeded.
74 // MIstatus::failure - Functional failed. List of object was empty.
77 template <class T1, typename T2>
78 bool CMICmdArgValListOfN::GetExpectedOption(
79 T2 &vrwValue, const VecArgObjPtr_t::size_type vnAt) const {
80 const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
81 if (rVecOptions.size() <= vnAt)
82 return MIstatus::failure;
84 VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin() + vnAt;
85 if (it2 != rVecOptions.end()) {
86 const T1 *pOption = static_cast<T1 *>(*it2);
87 vrwValue = pOption->GetValue();
88 return MIstatus::success;
91 return MIstatus::failure;