1275072Semaste//===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===//
2275072Semaste//
3275072Semaste//                     The LLVM Compiler Infrastructure
4275072Semaste//
5275072Semaste// This file is distributed under the University of Illinois Open Source
6275072Semaste// License. See LICENSE.TXT for details.
7275072Semaste//
8275072Semaste//===----------------------------------------------------------------------===//
9275072Semaste
10275072Semaste#pragma once
11275072Semaste
12275072Semaste// In-house headers:
13275072Semaste#include "MICmdArgValListBase.h"
14275072Semaste
15275072Semaste// Declarations:
16275072Semasteclass CMICmdArgContext;
17275072Semasteclass CMIUtilString;
18275072Semaste
19275072Semaste//++ ============================================================================
20280031Sdim// Details: MI common code class. Command argument class. Arguments object
21280031Sdim//          needing specialization derived from the CMICmdArgValBase class.
22280031Sdim//          An argument knows what type of argument it is and how it is to
23280031Sdim//          interpret the options (context) string to find and validate a matching
24280031Sdim//          argument and so extract a value from it.
25280031Sdim//          If *this argument has expected options following it the option objects
26280031Sdim//          created to hold each of those option's values belong to *this argument
27280031Sdim//          object and so are deleted when *this object goes out of scope.
28280031Sdim//          Based on the Interpreter pattern.
29275072Semaste//--
30275072Semasteclass CMICmdArgValOptionLong : public CMICmdArgValListBase
31275072Semaste{
32280031Sdim    // Methods:
33280031Sdim  public:
34296417Sdim    /* ctor */ CMICmdArgValOptionLong();
35280031Sdim    /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd);
36280031Sdim    /* ctor */ CMICmdArgValOptionLong(const CMIUtilString &vrArgName, const bool vbMandatory, const bool vbHandleByCmd,
37280031Sdim                                      const ArgValType_e veType, const MIuint vnExpectingNOptions);
38280031Sdim    //
39280031Sdim    bool IsArgLongOption(const CMIUtilString &vrTxt) const;
40296417Sdim    const VecArgObjPtr_t &GetExpectedOptions() const;
41280031Sdim    template <class T1, typename T2> bool GetExpectedOption(T2 &vrwValue) const;
42275072Semaste
43280031Sdim    // Overridden:
44280031Sdim  public:
45280031Sdim    // From CMICmdArgValBase
46296417Sdim    /* dtor */ ~CMICmdArgValOptionLong() override;
47280031Sdim    // From CMICmdArgSet::IArg
48288943Sdim    bool Validate(CMICmdArgContext &vArgContext) override;
49275072Semaste
50280031Sdim    // Methods:
51280031Sdim  protected:
52280031Sdim    bool ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const MIuint nArgIndex);
53275072Semaste
54280031Sdim    // Overrideable:
55280031Sdim  protected:
56280031Sdim    virtual bool IsArgOptionCorrect(const CMIUtilString &vrTxt) const;
57280031Sdim    virtual bool ArgNameMatch(const CMIUtilString &vrTxt) const;
58275072Semaste
59280031Sdim    // Methods:
60280031Sdim  private:
61296417Sdim    void Destroy();
62280031Sdim
63280031Sdim    // Attributes:
64280031Sdim  private:
65280031Sdim    MIuint m_nExpectingNOptions;         // The number of options expected to read following *this argument
66280031Sdim    VecArgObjPtr_t m_vecArgsExpected;    // The option objects holding the value extracted following *this argument
67280031Sdim    ArgValType_e m_eExpectingOptionType; // The type of options expected to read following *this argument
68275072Semaste};
69275072Semaste
70275072Semaste//++ ------------------------------------------------------------------------------------
71280031Sdim// Details: Retrieve the first argument or option value from the list of 1 or more options
72280031Sdim//          parsed from the command's options string.
73280031Sdim// Type:    Template method.
74280031Sdim// Args:    vrwValue    - (W) Templated type return value.
75280031Sdim//          T1          - The argument value's class type of the data hold in the list of options.
76280031Sdim//          T2          - The type pf the variable which holds the value wanted.
77280031Sdim// Return:  MIstatus::success - Functional succeeded.
78280031Sdim//          MIstatus::failure - Functional failed. List of object was empty.
79280031Sdim// Throws:  None.
80275072Semaste//--
81280031Sdimtemplate <class T1, typename T2>
82280031Sdimbool
83280031SdimCMICmdArgValOptionLong::GetExpectedOption(T2 &vrwValue) const
84275072Semaste{
85280031Sdim    const VecArgObjPtr_t &rVecOptions(GetExpectedOptions());
86280031Sdim    VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
87280031Sdim    if (it2 != rVecOptions.end())
88280031Sdim    {
89280031Sdim        const T1 *pOption = static_cast<T1 *>(*it2);
90280031Sdim        vrwValue = pOption->GetValue();
91280031Sdim        return MIstatus::success;
92280031Sdim    }
93275072Semaste
94280031Sdim    return MIstatus::failure;
95275072Semaste}
96