]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdArgValOptionLong.h
Merge ^/head r275118 through r275209.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdArgValOptionLong.h
1 //===-- 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
10 //++
11 // File:                MICmdArgValOptionLong.h
12 //
13 // Overview:    CMICmdArgValOptionLong interface.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 #pragma once
23
24 // In-house headers:
25 #include "MICmdArgValListBase.h"
26
27 // Declarations:
28 class CMICmdArgContext;
29 class CMIUtilString;
30
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.
41 // Gotchas:     None.
42 // Authors:     Illya Rudkin 16/04/2014.
43 // Changes:     None.
44 //--
45 class CMICmdArgValOptionLong : public CMICmdArgValListBase
46 {
47 // Methods:
48 public:
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, const ArgValType_e veType, const MIuint vnExpectingNOptions );
52         //
53         bool                                    IsArgLongOption( const CMIUtilString & vrTxt ) const;
54         const VecArgObjPtr_t &  GetExpectedOptions( void ) const;
55         template< class T1, typename T2 >
56                 bool                            GetExpectedOption( T2 & vrwValue ) const;
57         
58 // Overridden:
59 public:
60         // From CMICmdArgValBase
61         /* dtor */ virtual ~CMICmdArgValOptionLong( void );
62         // From CMICmdArgSet::IArg
63         virtual bool    Validate( CMICmdArgContext & vArgContext );
64
65 // Methods:
66 protected:
67         bool    ExtractExpectedOptions( CMICmdArgContext & vrwTxt, const MIuint nArgIndex );
68
69 // Overrideable:
70 protected:
71         virtual bool IsArgOptionCorrect( const CMIUtilString & vrTxt ) const;
72         virtual bool ArgNameMatch( const CMIUtilString & vrTxt ) const;
73
74 // Methods:
75 private:
76         void    Destroy( void );
77
78 // Attributes:
79 private:
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
83 };
84
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.
94 // Throws:      None.
95 //--
96 template< class T1, typename T2 >
97 bool CMICmdArgValOptionLong::GetExpectedOption( T2 & vrwValue ) const
98 {
99         const VecArgObjPtr_t & rVecOptions( GetExpectedOptions() );
100         VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin();
101         if( it2 != rVecOptions.end() )
102         {
103                 const T1 * pOption = static_cast< T1 * >( *it2 );
104                 vrwValue = pOption->GetValue();
105                 return MIstatus::success;
106         }
107
108         return MIstatus::failure;
109 }