blob: 9d074fc07459412910082d512586defee63eaeed [file] [log] [blame]
Deepak Panickal6f9c4682014-05-16 10:51:01 +00001//===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Deepak Panickal6f9c4682014-05-16 10:51:01 +000010#pragma once
11
12// In-house headers:
13#include "MICmdArgValListBase.h"
14
15// Declarations:
16class CMICmdArgContext;
17class CMIUtilString;
18
19//++ ============================================================================
Zachary Turner1d6af022014-11-17 18:06:21 +000020// Details: MI common code class. Command argument class. Arguments object
21// needing specialization derived from the CMICmdArgValBase class.
22// An argument knows what type of argument it is and how it is to
23// interpret the options (context) string to find and validate a matching
24// argument and so extract a value from it.
25// If *this argument has expected options following it the option objects
26// created to hold each of those option's values belong to *this argument
27// object and so are deleted when *this object goes out of scope.
28// Based on the Interpreter pattern.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000029//--
30class CMICmdArgValOptionLong : public CMICmdArgValListBase
31{
Zachary Turner1d6af022014-11-17 18:06:21 +000032 // Methods:
33 public:
Bruce Mitchenere2453af2015-08-04 10:24:20 +000034 /* ctor */ CMICmdArgValOptionLong();
Zachary Turner1d6af022014-11-17 18:06:21 +000035 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
36 /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
37 const ArgValType_e veType, const MIuint vnExpectingNOptions);
38 //
39 bool IsArgLongOption(const CMIUtilString &vrTxt) const;
Bruce Mitchenere2453af2015-08-04 10:24:20 +000040 const VecArgObjPtr_t &GetExpectedOptions() const;
Zachary Turner1d6af022014-11-17 18:06:21 +000041 template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000042
Zachary Turner1d6af022014-11-17 18:06:21 +000043 // Overridden:
44 public:
45 // From CMICmdArgValBase
Bruce Mitchenere2453af2015-08-04 10:24:20 +000046 /* dtor */ ~CMICmdArgValOptionLong() override;
Zachary Turner1d6af022014-11-17 18:06:21 +000047 // From CMICmdArgSet::IArg
Bruce Mitchener88205302015-07-06 15:48:55 +000048 bool Validate(CMICmdArgContext &vArgContext) override;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000049
Zachary Turner1d6af022014-11-17 18:06:21 +000050 // Methods:
51 protected:
52 bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
Deepak Panickal6f9c4682014-05-16 10:51:01 +000053
Zachary Turner1d6af022014-11-17 18:06:21 +000054 // Overrideable:
55 protected:
56 virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
57 virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000058
Zachary Turner1d6af022014-11-17 18:06:21 +000059 // Methods:
60 private:
Bruce Mitchenere2453af2015-08-04 10:24:20 +000061 void Destroy();
Zachary Turner1d6af022014-11-17 18:06:21 +000062
63 // Attributes:
64 private:
65 MIuint m_nExpectingNOptions; // The number of options expected to read following *this argument
66 VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value extracted following *this argument
67 ArgValType_e m_eExpectingOptionType; // The type of options expected to read following *this argument
Deepak Panickal6f9c4682014-05-16 10:51:01 +000068};
69
70//++ ------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000071// Details: Retrieve the first argument or option value from the list of 1 or more options
72// parsed from the command's options string.
73// Type: Template method.
74// Args: vrwValue - (W) Templated type return value.
75// T1 - The argument value's class type of the data hold in the list of options.
76// T2 - The type pf the variable which holds the value wanted.
77// Return: MIstatus::success - Functional succeeded.
78// MIstatus::failure - Functional failed. List of object was empty.
79// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000080//--
Zachary Turner1d6af022014-11-17 18:06:21 +000081template <class T1, typename T2>
82bool
83CMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const
Deepak Panickal6f9c4682014-05-16 10:51:01 +000084{
Zachary Turner1d6af022014-11-17 18:06:21 +000085 const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
86 VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
87 if (it2 != rVecOptions.end())
88 {
89 const T1 *pOption = static_cast<T1 *>(*it2);
90 vrwValue = pOption->GetValue();
91 return MIstatus::success;
92 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +000093
Zachary Turner1d6af022014-11-17 18:06:21 +000094 return MIstatus::failure;
Deepak Panickal6f9c4682014-05-16 10:51:01 +000095}