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