1 //===-- MICmdArgValOptionShort.cpp ------------------------------*- 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 // In-house headers:
11 #include "MICmdArgValOptionShort.h"
12 #include "MICmdArgContext.h"
13
14 //++
15 //------------------------------------------------------------------------------------
16 // Details: CMICmdArgValOptionShort constructor.
17 // Type: Method.
18 // Args: None.
19 // Return: None.
20 // Throws: None.
21 //--
CMICmdArgValOptionShort()22 CMICmdArgValOptionShort::CMICmdArgValOptionShort() {}
23
24 //++
25 //------------------------------------------------------------------------------------
26 // Details: CMICmdArgValOptionShort constructor.
27 // Type: Method.
28 // Args: vrArgName - (R) Argument's name to search by.
29 // vbMandatory - (R) True = Yes must be present, false = optional
30 // argument.
31 // vbHandleByCmd - (R) True = Command processes *this option, false =
32 // not handled.
33 // Return: None.
34 // Throws: None.
35 //--
CMICmdArgValOptionShort(const CMIUtilString & vrArgName,const bool vbMandatory,const bool vbHandleByCmd)36 CMICmdArgValOptionShort::CMICmdArgValOptionShort(const CMIUtilString &vrArgName,
37 const bool vbMandatory,
38 const bool vbHandleByCmd)
39 : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd) {}
40
41 //++
42 //------------------------------------------------------------------------------------
43 // Details: CMICmdArgValOptionLong constructor.
44 // Type: Method.
45 // Args: vrArgName - (R) Argument's name to search by.
46 // vbMandatory - (R) True = Yes must be present, false =
47 // optional argument.
48 // vbHandleByCmd - (R) True = Command processes *this option,
49 // false = not handled.
50 // veType - (R) The type of argument to look for and
51 // create argument object of a certain type.
52 // vnExpectingNOptions - (R) The number of options expected to read
53 // following *this argument.
54 // Return: None.
55 // Throws: None.
56 //--
CMICmdArgValOptionShort(const CMIUtilString & vrArgName,const bool vbMandatory,const bool vbHandleByCmd,const ArgValType_e veType,const MIuint vnExpectingNOptions)57 CMICmdArgValOptionShort::CMICmdArgValOptionShort(
58 const CMIUtilString &vrArgName, const bool vbMandatory,
59 const bool vbHandleByCmd, const ArgValType_e veType,
60 const MIuint vnExpectingNOptions)
61 : CMICmdArgValOptionLong(vrArgName, vbMandatory, vbHandleByCmd, veType,
62 vnExpectingNOptions) {}
63
64 //++
65 //------------------------------------------------------------------------------------
66 // Details: CMICmdArgValOptionShort destructor.
67 // Type: Overridden.
68 // Args: None.
69 // Return: None.
70 // Throws: None.
71 //--
~CMICmdArgValOptionShort()72 CMICmdArgValOptionShort::~CMICmdArgValOptionShort() {}
73
74 //++
75 //------------------------------------------------------------------------------------
76 // Details: Examine the string and determine if it is a valid short type option
77 // argument.
78 // Type: Method.
79 // Args: vrTxt - (R) Some text.
80 // Return: bool - True = yes valid arg, false = no.
81 // Throws: None.
82 //--
IsArgShortOption(const CMIUtilString & vrTxt) const83 bool CMICmdArgValOptionShort::IsArgShortOption(
84 const CMIUtilString &vrTxt) const {
85 // Look for --someLongOption
86 MIint nPos = vrTxt.find("--");
87 if (nPos == 0)
88 return false;
89
90 // Look for -f short option
91 nPos = vrTxt.find('-');
92 if (nPos != 0)
93 return false;
94
95 if (vrTxt.length() > 2)
96 return false;
97
98 return true;
99 }
100
101 //++
102 //------------------------------------------------------------------------------------
103 // Details: Examine the string and determine if it is a valid short type option
104 // argument.
105 // Long type argument looks like -f some short option.
106 // Type: Overridden.
107 // Args: vrTxt - (R) Some text.
108 // Return: bool - True = yes valid arg, false = no.
109 // Throws: None.
110 //--
IsArgOptionCorrect(const CMIUtilString & vrTxt) const111 bool CMICmdArgValOptionShort::IsArgOptionCorrect(
112 const CMIUtilString &vrTxt) const {
113 return IsArgShortOption(vrTxt);
114 }
115
116 //++
117 //------------------------------------------------------------------------------------
118 // Details: Does the argument name of the argument being parsed ATM match the
119 // name of
120 // *this argument object.
121 // Type: Overridden.
122 // Args: vrTxt - (R) Some text.
123 // Return: bool - True = yes arg name matched, false = no.
124 // Throws: None.
125 //--
ArgNameMatch(const CMIUtilString & vrTxt) const126 bool CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const {
127 const CMIUtilString strArg = vrTxt.substr(1);
128 return (strArg == GetName());
129 }
130