1 //===-- MICmdArgValOptionLong.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: MICmdArgValOptionLong.h
13 // Overview: CMICmdArgValOptionLong interface.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
25 #include "MICmdArgValListBase.h"
28 class CMICmdArgContext;
31 //++ ============================================================================
32 // Details: MI common code class. Command argument class. Arguments object
33 // needing specialization derived from the CMICmdArgValBase class.
34 // An argument knows what type of argument it is and how it is to
35 // interpret the options (context) string to find and validate a matching
36 // argument and so extract a value from it.
37 // If *this argument has expected options following it the option objects
38 // created to hold each of those option's values belong to *this argument
39 // object and so are deleted when *this object goes out of scope.
40 // Based on the Interpreter pattern.
42 // Authors: Illya Rudkin 16/04/2014.
45 class CMICmdArgValOptionLong : public CMICmdArgValListBase
49 /* ctor */ CMICmdArgValOptionLong(void);
50 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
51 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
52 const ArgValType_e veType, const MIuint vnExpectingNOptions);
54 bool IsArgLongOption(const CMIUtilString &vrTxt) const;
55 const VecArgObjPtr_t &GetExpectedOptions(void) const;
56 template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
60 // From CMICmdArgValBase
61 /* dtor */ virtual ~CMICmdArgValOptionLong(void);
62 // From CMICmdArgSet::IArg
63 virtual bool Validate(CMICmdArgContext &vArgContext);
67 bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
71 virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
72 virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
80 MIuint m_nExpectingNOptions; // The number of options expected to read following *this argument
81 VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value extracted following *this argument
82 ArgValType_e m_eExpectingOptionType; // The type of options expected to read following *this argument
85 //++ ------------------------------------------------------------------------------------
86 // Details: Retrieve the first argument or option value from the list of 1 or more options
87 // parsed from the command's options string.
88 // Type: Template method.
89 // Args: vrwValue - (W) Templated type return value.
90 // T1 - The argument value's class type of the data hold in the list of options.
91 // T2 - The type pf the variable which holds the value wanted.
92 // Return: MIstatus::success - Functional succeeded.
93 // MIstatus::failure - Functional failed. List of object was empty.
96 template <class T1, typename T2>
98 CMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const
100 const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
101 VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
102 if (it2 != rVecOptions.end())
104 const T1 *pOption = static_cast<T1 *>(*it2);
105 vrwValue = pOption->GetValue();
106 return MIstatus::success;
109 return MIstatus::failure;