qcommandline 0.2.0
[qcommandline:qcommandline.git] / doc / html / qcommandline_8cpp-source.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>QCommandLine: /home/iksaif/dev/.priv/QCommandLine/src/qcommandline.cpp Source File</title>
4 <link href="tabs.css" rel="stylesheet" type="text/css">
5 <link href="doxygen.css" rel="stylesheet" type="text/css">
6 </head><body>
7 <!-- Generated by Doxygen 1.5.8 -->
8 <script type="text/javascript">
9 <!--
10 function changeDisplayState (e){
11   var num=this.id.replace(/[^[0-9]/g,'');
12   var button=this.firstChild;
13   var sectionDiv=document.getElementById('dynsection'+num);
14   if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
15     sectionDiv.style.display='block';
16     button.src='open.gif';
17   }else{
18     sectionDiv.style.display='none';
19     button.src='closed.gif';
20   }
21 }
22 function initDynSections(){
23   var divs=document.getElementsByTagName('div');
24   var sectionCounter=1;
25   for(var i=0;i<divs.length-1;i++){
26     if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
27       var header=divs[i];
28       var section=divs[i+1];
29       var button=header.firstChild;
30       if (button!='IMG'){
31         divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
32         button=document.createElement('img');
33         divs[i].insertBefore(button,divs[i].firstChild);
34       }
35       header.style.cursor='pointer';
36       header.onclick=changeDisplayState;
37       header.id='dynheader'+sectionCounter;
38       button.src='closed.gif';
39       section.id='dynsection'+sectionCounter;
40       section.style.display='none';
41       section.style.marginLeft='14px';
42       sectionCounter++;
43     }
44   }
45 }
46 window.onload = initDynSections;
47 -->
48 </script>
49 <div class="navigation" id="top">
50   <div class="tabs">
51     <ul>
52       <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
53       <li><a href="annotated.html"><span>Classes</span></a></li>
54       <li class="current"><a href="files.html"><span>Files</span></a></li>
55     </ul>
56   </div>
57   <div class="tabs">
58     <ul>
59       <li><a href="files.html"><span>File&nbsp;List</span></a></li>
60     </ul>
61   </div>
62 <h1>/home/iksaif/dev/.priv/QCommandLine/src/qcommandline.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;QtCore/QCoreApplication&gt;</span>
63 <a name="l00002"></a>00002 <span class="preprocessor">#include &lt;QtCore/QQueue&gt;</span>
64 <a name="l00003"></a>00003 <span class="preprocessor">#include &lt;QtCore/QVariant&gt;</span>
65 <a name="l00004"></a>00004 <span class="preprocessor">#include &lt;QtCore/QFileInfo&gt;</span>
66 <a name="l00005"></a>00005 <span class="preprocessor">#include &lt;QDebug&gt;</span>
67 <a name="l00006"></a>00006 <span class="preprocessor">#include &lt;iostream&gt;</span>
68 <a name="l00007"></a>00007 
69 <a name="l00008"></a>00008 <span class="preprocessor">#include "qcommandline.h"</span>
70 <a name="l00009"></a>00009 
71 <a name="l00010"></a>00010 <span class="keyword">const</span> <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> <a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">QCommandLine::helpEntry</a> = { <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>, QLatin1Char(<span class="charliteral">'h'</span>), QLatin1String(<span class="stringliteral">"help"</span>), tr(<span class="stringliteral">"Display this help and exit"</span>), <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a> };
72 <a name="l00011"></a>00011 
73 <a name="l00012"></a>00012 <span class="keyword">const</span> <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> <a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">QCommandLine::versionEntry</a> = { <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>, QLatin1Char(<span class="charliteral">'V'</span>), QLatin1String(<span class="stringliteral">"version"</span>), tr(<span class="stringliteral">"Display version and exit"</span>), <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a> };
74 <a name="l00013"></a>00013 
75 <a name="l00014"></a><a class="code" href="class_q_command_line.html#8f963cc405a270710f07e5fbf06aaf84">00014</a> <a class="code" href="class_q_command_line.html#8f963cc405a270710f07e5fbf06aaf84">QCommandLine::QCommandLine</a>(QObject * parent)
76 <a name="l00015"></a>00015   : QObject(parent), d(new QCommandLinePrivate)
77 <a name="l00016"></a>00016 {
78 <a name="l00017"></a>00017   <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">setArguments</a>(QCoreApplication::instance()-&gt;<a class="code" href="class_q_command_line.html#36b72d4561ea65ab1cfa264ceba36059">arguments</a>());
79 <a name="l00018"></a>00018 }
80 <a name="l00019"></a>00019 
81 <a name="l00020"></a><a class="code" href="class_q_command_line.html#40b6e26938326485de3a134b58bc9b48">00020</a> <a class="code" href="class_q_command_line.html#8f963cc405a270710f07e5fbf06aaf84">QCommandLine::QCommandLine</a>(<span class="keyword">const</span> QCoreApplication &amp; app,
82 <a name="l00021"></a>00021                            <span class="keyword">const</span> QCommandLineConfig &amp; config,
83 <a name="l00022"></a>00022                            QObject * parent)
84 <a name="l00023"></a>00023   : QObject(parent), d(new QCommandLinePrivate)
85 <a name="l00024"></a>00024 {
86 <a name="l00025"></a>00025   <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">setArguments</a>(app.arguments());
87 <a name="l00026"></a>00026   <a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">setConfig</a>(config);
88 <a name="l00027"></a>00027   <a class="code" href="class_q_command_line.html#e9e2caa1e1fad4e2c9936512690eeb71">enableHelp</a>(<span class="keyword">true</span>);
89 <a name="l00028"></a>00028   <a class="code" href="class_q_command_line.html#7098ede5a8994819b1fdd81703a052c5">enableVersion</a>(<span class="keyword">true</span>);
90 <a name="l00029"></a>00029 }
91 <a name="l00030"></a>00030 
92 <a name="l00031"></a><a class="code" href="class_q_command_line.html#2319b50c8e8afa42605d2c97cfeac922">00031</a> <a class="code" href="class_q_command_line.html#8f963cc405a270710f07e5fbf06aaf84">QCommandLine::QCommandLine</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[],
93 <a name="l00032"></a>00032                            <span class="keyword">const</span> QCommandLineConfig &amp; config,
94 <a name="l00033"></a>00033                            QObject * parent)
95 <a name="l00034"></a>00034   : QObject(parent), d(new QCommandLinePrivate)
96 <a name="l00035"></a>00035 {
97 <a name="l00036"></a>00036   <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">setArguments</a>(argc, argv);
98 <a name="l00037"></a>00037   <a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">setConfig</a>(config);
99 <a name="l00038"></a>00038   <a class="code" href="class_q_command_line.html#e9e2caa1e1fad4e2c9936512690eeb71">enableHelp</a>(<span class="keyword">true</span>);
100 <a name="l00039"></a>00039   <a class="code" href="class_q_command_line.html#7098ede5a8994819b1fdd81703a052c5">enableVersion</a>(<span class="keyword">true</span>);
101 <a name="l00040"></a>00040 }
102 <a name="l00041"></a>00041 
103 <a name="l00042"></a><a class="code" href="class_q_command_line.html#d9a3d1065c65623fa1a0291695894470">00042</a> <a class="code" href="class_q_command_line.html#8f963cc405a270710f07e5fbf06aaf84">QCommandLine::QCommandLine</a>(<span class="keyword">const</span> QStringList args,
104 <a name="l00043"></a>00043                            <span class="keyword">const</span> QCommandLineConfig &amp; config,
105 <a name="l00044"></a>00044                            QObject * parent)
106 <a name="l00045"></a>00045   : QObject(parent), d(new QCommandLinePrivate)
107 <a name="l00046"></a>00046 {
108 <a name="l00047"></a>00047   <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">setArguments</a>(args);
109 <a name="l00048"></a>00048   <a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">setConfig</a>(config);
110 <a name="l00049"></a>00049   <a class="code" href="class_q_command_line.html#e9e2caa1e1fad4e2c9936512690eeb71">enableHelp</a>(<span class="keyword">true</span>);
111 <a name="l00050"></a>00050   <a class="code" href="class_q_command_line.html#7098ede5a8994819b1fdd81703a052c5">enableVersion</a>(<span class="keyword">true</span>);
112 <a name="l00051"></a>00051 }
113 <a name="l00052"></a>00052 
114 <a name="l00053"></a><a class="code" href="class_q_command_line.html#561fc922ce13ff8f2e1464617a910433">00053</a> <a class="code" href="class_q_command_line.html#561fc922ce13ff8f2e1464617a910433">QCommandLine::~QCommandLine</a>()
115 <a name="l00054"></a>00054 {
116 <a name="l00055"></a>00055   <span class="keyword">delete</span> d;
117 <a name="l00056"></a>00056 }
118 <a name="l00057"></a>00057 
119 <a name="l00058"></a>00058 <span class="keywordtype">void</span>
120 <a name="l00059"></a><a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">00059</a> <a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">QCommandLine::setConfig</a>(<span class="keyword">const</span> QCommandLineConfig &amp; config)
121 <a name="l00060"></a>00060 {
122 <a name="l00061"></a>00061   d-&gt;config = config;
123 <a name="l00062"></a>00062 }
124 <a name="l00063"></a>00063 
125 <a name="l00064"></a>00064 <span class="keywordtype">void</span>
126 <a name="l00065"></a><a class="code" href="class_q_command_line.html#8d3a6d99e13785913e76afcf3b78a0b7">00065</a> <a class="code" href="class_q_command_line.html#af34ca9d4006861997fe0164ba57d661">QCommandLine::setConfig</a>(<span class="keyword">const</span> <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> config[])
127 <a name="l00066"></a>00066 {
128 <a name="l00067"></a>00067   d-&gt;config.clear();
129 <a name="l00068"></a>00068 
130 <a name="l00069"></a>00069   <span class="keywordflow">while</span> (config-&gt;<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a>) {
131 <a name="l00070"></a>00070     d-&gt;config &lt;&lt; *config;
132 <a name="l00071"></a>00071     config++;
133 <a name="l00072"></a>00072   }
134 <a name="l00073"></a>00073 }
135 <a name="l00074"></a>00074 
136 <a name="l00075"></a>00075 QCommandLineConfig
137 <a name="l00076"></a><a class="code" href="class_q_command_line.html#a63ed64e2d3d8bdafc43f9d025fd91bb">00076</a> <a class="code" href="class_q_command_line.html#a63ed64e2d3d8bdafc43f9d025fd91bb">QCommandLine::config</a>()
138 <a name="l00077"></a>00077 {
139 <a name="l00078"></a>00078   <span class="keywordflow">return</span> d-&gt;config;
140 <a name="l00079"></a>00079 }
141 <a name="l00080"></a>00080 
142 <a name="l00081"></a>00081 <span class="keywordtype">void</span>
143 <a name="l00082"></a><a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">00082</a> <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">QCommandLine::setArguments</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
144 <a name="l00083"></a>00083 {
145 <a name="l00084"></a>00084   d-&gt;args.clear();
146 <a name="l00085"></a>00085   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; argc; i++)
147 <a name="l00086"></a>00086     d-&gt;args.append(QLatin1String(argv[i]));
148 <a name="l00087"></a>00087 }
149 <a name="l00088"></a>00088 
150 <a name="l00089"></a>00089 <span class="keywordtype">void</span>
151 <a name="l00090"></a><a class="code" href="class_q_command_line.html#c11bf85c0de520a9914a3ebc424bf790">00090</a> <a class="code" href="class_q_command_line.html#cddb2efe997b7cb9d007f17703a4d3bd">QCommandLine::setArguments</a>(QStringList args)
152 <a name="l00091"></a>00091 {
153 <a name="l00092"></a>00092   d-&gt;args = args;
154 <a name="l00093"></a>00093 }
155 <a name="l00094"></a>00094 
156 <a name="l00095"></a>00095 QStringList
157 <a name="l00096"></a><a class="code" href="class_q_command_line.html#36b72d4561ea65ab1cfa264ceba36059">00096</a> <a class="code" href="class_q_command_line.html#36b72d4561ea65ab1cfa264ceba36059">QCommandLine::arguments</a>()
158 <a name="l00097"></a>00097 {
159 <a name="l00098"></a>00098   <span class="keywordflow">return</span> d-&gt;args;
160 <a name="l00099"></a>00099 }
161 <a name="l00100"></a>00100 
162 <a name="l00101"></a>00101 <span class="keywordtype">void</span>
163 <a name="l00102"></a><a class="code" href="class_q_command_line.html#e9e2caa1e1fad4e2c9936512690eeb71">00102</a> <a class="code" href="class_q_command_line.html#e9e2caa1e1fad4e2c9936512690eeb71">QCommandLine::enableHelp</a>(<span class="keywordtype">bool</span> enable)
164 <a name="l00103"></a>00103 {
165 <a name="l00104"></a>00104   d-&gt;help = enable;
166 <a name="l00105"></a>00105 }
167 <a name="l00106"></a>00106 
168 <a name="l00107"></a>00107 <span class="keywordtype">bool</span>
169 <a name="l00108"></a><a class="code" href="class_q_command_line.html#7900df6da6ddf5dc656f10fa94cb8b5d">00108</a> <a class="code" href="class_q_command_line.html#7900df6da6ddf5dc656f10fa94cb8b5d">QCommandLine::helpEnabled</a>()
170 <a name="l00109"></a>00109 {
171 <a name="l00110"></a>00110   <span class="keywordflow">return</span> d-&gt;help;
172 <a name="l00111"></a>00111 }
173 <a name="l00112"></a>00112 
174 <a name="l00113"></a>00113 <span class="keywordtype">void</span>
175 <a name="l00114"></a><a class="code" href="class_q_command_line.html#7098ede5a8994819b1fdd81703a052c5">00114</a> <a class="code" href="class_q_command_line.html#7098ede5a8994819b1fdd81703a052c5">QCommandLine::enableVersion</a>(<span class="keywordtype">bool</span> enable)
176 <a name="l00115"></a>00115 {
177 <a name="l00116"></a>00116   d-&gt;version = enable;
178 <a name="l00117"></a>00117 }
179 <a name="l00118"></a>00118 
180 <a name="l00119"></a>00119 <span class="keywordtype">bool</span>
181 <a name="l00120"></a><a class="code" href="class_q_command_line.html#cbfc336dd946e3dd7a495904663b68ab">00120</a> <a class="code" href="class_q_command_line.html#cbfc336dd946e3dd7a495904663b68ab">QCommandLine::versionEnabled</a>()
182 <a name="l00121"></a>00121 {
183 <a name="l00122"></a>00122   <span class="keywordflow">return</span> d-&gt;version;
184 <a name="l00123"></a>00123 }
185 <a name="l00124"></a>00124 
186 <a name="l00125"></a>00125 <span class="keywordtype">bool</span>
187 <a name="l00126"></a><a class="code" href="class_q_command_line.html#f19226c119fb06f220fe6fb81dd5661b">00126</a> <a class="code" href="class_q_command_line.html#f19226c119fb06f220fe6fb81dd5661b">QCommandLine::parse</a>()
188 <a name="l00127"></a>00127 {
189 <a name="l00128"></a>00128   QMap &lt; QString, QCommandLineConfigEntry &gt; conf;
190 <a name="l00129"></a>00129   QMap &lt; QString, QCommandLineConfigEntry &gt; confLong;
191 <a name="l00130"></a>00130   QQueue &lt; QCommandLineConfigEntry &gt; params;
192 <a name="l00131"></a>00131   QMap &lt; QString, QList &lt; QString &gt; &gt; optionsFound;
193 <a name="l00132"></a>00132   QMap &lt; QString, int &gt; switchsFound;
194 <a name="l00133"></a>00133   QStringList options, switchs;
195 <a name="l00134"></a>00134   QStringList args = d-&gt;args;
196 <a name="l00135"></a>00135 
197 <a name="l00136"></a>00136   <span class="keywordtype">bool</span> allparam = <span class="keyword">false</span>;
198 <a name="l00137"></a>00137 
199 <a name="l00138"></a>00138   <span class="keywordflow">foreach</span> (<a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry, d-&gt;config) {
200 <a name="l00139"></a>00139     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> != <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a> &amp;&amp; entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a> == QLatin1Char(<span class="charliteral">'\0'</span>))
201 <a name="l00140"></a>00140       qWarning() &lt;&lt; QLatin1String(<span class="stringliteral">"QCommandLine: Empty shortname detected"</span>);
202 <a name="l00141"></a>00141     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>.isEmpty())
203 <a name="l00142"></a>00142       qWarning() &lt;&lt; QLatin1String(<span class="stringliteral">"QCommandLine: Empty shortname detected"</span>);
204 <a name="l00143"></a>00143     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> != <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a> &amp;&amp; conf.find(entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>) != conf.end())
205 <a name="l00144"></a>00144       qWarning() &lt;&lt; QLatin1String(<span class="stringliteral">"QCommandLine: Duplicated shortname detected "</span>) &lt;&lt; entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>;
206 <a name="l00145"></a>00145     <span class="keywordflow">if</span> (conf.find(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>) != conf.end())
207 <a name="l00146"></a>00146       qWarning() &lt;&lt; QLatin1String(<span class="stringliteral">"QCommandLine: Duplicated longname detected "</span>) &lt;&lt; entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>;
208 <a name="l00147"></a>00147 
209 <a name="l00148"></a>00148     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a>)
210 <a name="l00149"></a>00149       params &lt;&lt; entry;
211 <a name="l00150"></a>00150     <span class="keywordflow">else</span>
212 <a name="l00151"></a>00151       conf[entry.shortName] = entry;
213 <a name="l00152"></a>00152     confLong[entry.longName] = entry;
214 <a name="l00153"></a>00153   }
215 <a name="l00154"></a>00154 
216 <a name="l00155"></a>00155   <span class="keywordflow">if</span> (d-&gt;help) {
217 <a name="l00156"></a>00156     conf[<a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">helpEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>] = <a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">helpEntry</a>;
218 <a name="l00157"></a>00157     confLong[<a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">helpEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>] = <a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">helpEntry</a>;
219 <a name="l00158"></a>00158   }
220 <a name="l00159"></a>00159 
221 <a name="l00160"></a>00160   <span class="keywordflow">if</span> (d-&gt;version) {
222 <a name="l00161"></a>00161     conf[<a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">versionEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>] = <a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">versionEntry</a>;
223 <a name="l00162"></a>00162     confLong[<a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">versionEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>] = <a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">versionEntry</a>;
224 <a name="l00163"></a>00163   }
225 <a name="l00164"></a>00164 
226 <a name="l00165"></a>00165   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i &lt; args.size(); ++i) {
227 <a name="l00166"></a>00166     QString arg = args[i];
228 <a name="l00167"></a>00167     <span class="keywordtype">bool</span> param = <span class="keyword">true</span>, shrt = <span class="keyword">false</span>, stay = <span class="keyword">false</span>, forward = <span class="keyword">false</span>;
229 <a name="l00168"></a>00168 
230 <a name="l00169"></a>00169     <span class="comment">/* A '+' was found, all remaining options are params */</span>
231 <a name="l00170"></a>00170     <span class="keywordflow">if</span> (allparam)
232 <a name="l00171"></a>00171       param = <span class="keyword">true</span>;
233 <a name="l00172"></a>00172     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg.startsWith(QLatin1String(<span class="stringliteral">"--"</span>))) {
234 <a name="l00173"></a>00173       param = <span class="keyword">false</span>;
235 <a name="l00174"></a>00174       shrt = <span class="keyword">false</span>;
236 <a name="l00175"></a>00175       arg = arg.mid(2);
237 <a name="l00176"></a>00176     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (arg.startsWith(QLatin1Char(<span class="charliteral">'-'</span>)) || arg.startsWith(QLatin1Char(<span class="charliteral">'+'</span>))) {
238 <a name="l00177"></a>00177       <span class="keywordflow">if</span> (arg.startsWith(QLatin1Char(<span class="charliteral">'+'</span>)))
239 <a name="l00178"></a>00178         allparam = <span class="keyword">true</span>;
240 <a name="l00179"></a>00179       param = <span class="keyword">false</span>;
241 <a name="l00180"></a>00180       shrt = <span class="keyword">true</span>;
242 <a name="l00181"></a>00181       <span class="comment">/* Handle stacked args like `tar -xzf` */</span>
243 <a name="l00182"></a>00182       <span class="keywordflow">if</span> (arg.size() &gt; 2) {
244 <a name="l00183"></a>00183         args[i] = arg.mid(0, 2);
245 <a name="l00184"></a>00184         args.insert(i + 1, arg.mid(0, 1) + arg.mid(2));
246 <a name="l00185"></a>00185         arg = arg.mid(1, 1);
247 <a name="l00186"></a>00186       } <span class="keywordflow">else</span> {
248 <a name="l00187"></a>00187         arg = arg.mid(1);
249 <a name="l00188"></a>00188       }
250 <a name="l00189"></a>00189     }
251 <a name="l00190"></a>00190 
252 <a name="l00191"></a>00191     <span class="comment">/* Handle params */</span>
253 <a name="l00192"></a>00192     <span class="keywordflow">if</span> (param) {
254 <a name="l00193"></a>00193       <span class="keywordflow">if</span> (!params.size()) {
255 <a name="l00194"></a>00194         emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"Unknown param: %1"</span>).arg(arg));
256 <a name="l00195"></a>00195         <span class="keywordflow">return</span> <span class="keyword">false</span>;
257 <a name="l00196"></a>00196       }
258 <a name="l00197"></a>00197 
259 <a name="l00198"></a>00198       <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> &amp; entry = params.first();
260 <a name="l00199"></a>00199 
261 <a name="l00200"></a>00200       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>) {
262 <a name="l00201"></a>00201         entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = (<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a>) (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; ~<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>);
263 <a name="l00202"></a>00202         entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = (<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a>) (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> | <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a>);
264 <a name="l00203"></a>00203       }
265 <a name="l00204"></a>00204 
266 <a name="l00205"></a>00205       emit <a class="code" href="class_q_command_line.html#f0094fc07e211a49da4ca4897166cb4d">paramFound</a>(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>, arg);
267 <a name="l00206"></a>00206 
268 <a name="l00207"></a>00207       <span class="keywordflow">if</span> (!(entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf25c45f4e4843deac514dd547b96d2258">QCommandLine::Multiple</a>))
269 <a name="l00208"></a>00208         params.dequeue();
270 <a name="l00209"></a>00209 
271 <a name="l00210"></a>00210     } <span class="keywordflow">else</span> { <span class="comment">/* Options and switchs* */</span>
272 <a name="l00211"></a>00211       QString key;
273 <a name="l00212"></a>00212       QString value;
274 <a name="l00213"></a>00213       <span class="keywordtype">int</span> idx = arg.indexOf(QLatin1Char(<span class="charliteral">'='</span>));
275 <a name="l00214"></a>00214 
276 <a name="l00215"></a>00215       <span class="keywordflow">if</span> (idx != -1) {
277 <a name="l00216"></a>00216         key = arg.mid(0, idx);
278 <a name="l00217"></a>00217         value = arg.mid(idx + 1);
279 <a name="l00218"></a>00218       } <span class="keywordflow">else</span> {
280 <a name="l00219"></a>00219         key = arg;
281 <a name="l00220"></a>00220       }
282 <a name="l00221"></a>00221 
283 <a name="l00222"></a>00222       QMap &lt; QString, QCommandLineConfigEntry &gt; &amp; c = shrt ? conf : confLong;
284 <a name="l00223"></a>00223 
285 <a name="l00224"></a>00224       <span class="keywordflow">if</span> (c.find(key) == c.end()) {
286 <a name="l00225"></a>00225         emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"Unknown option: %1"</span>).arg(key));
287 <a name="l00226"></a>00226         <span class="keywordflow">return</span> <span class="keyword">false</span>;
288 <a name="l00227"></a>00227       }
289 <a name="l00228"></a>00228 
290 <a name="l00229"></a>00229       <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> &amp; entry = c[key];
291 <a name="l00230"></a>00230 
292 <a name="l00231"></a>00231       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>) {
293 <a name="l00232"></a>00232         <span class="keywordflow">if</span> (!switchsFound.contains(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>))
294 <a name="l00233"></a>00233           switchs &lt;&lt; entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>;
295 <a name="l00234"></a>00234         if (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf25c45f4e4843deac514dd547b96d2258">QCommandLine::Multiple</a>)
296 <a name="l00235"></a>00235           switchsFound[entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>]++;
297 <a name="l00236"></a>00236         <span class="keywordflow">else</span>
298 <a name="l00237"></a>00237           switchsFound[entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>] = 1;
299 <a name="l00238"></a>00238       } <span class="keywordflow">else</span> {
300 <a name="l00239"></a>00239         <span class="keywordflow">if</span> (stay) {
301 <a name="l00240"></a>00240           emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"Option %1 need a value"</span>).arg(key));
302 <a name="l00241"></a>00241           <span class="keywordflow">return</span> <span class="keyword">false</span>;
303 <a name="l00242"></a>00242         }
304 <a name="l00243"></a>00243 
305 <a name="l00244"></a>00244         <span class="keywordflow">if</span> (idx == -1) {
306 <a name="l00245"></a>00245           <span class="keywordflow">if</span> (i+1 &lt; args.size() &amp;&amp; !args[i+1].startsWith(QLatin1Char(<span class="charliteral">'-'</span>))) {
307 <a name="l00246"></a>00246             value = args[i+1];
308 <a name="l00247"></a>00247             forward = <span class="keyword">true</span>;
309 <a name="l00248"></a>00248           } <span class="keywordflow">else</span> {
310 <a name="l00249"></a>00249             emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"Option %1 need a value"</span>).arg(key));
311 <a name="l00250"></a>00250             <span class="keywordflow">return</span> <span class="keyword">false</span>;
312 <a name="l00251"></a>00251           }
313 <a name="l00252"></a>00252         }
314 <a name="l00253"></a>00253 
315 <a name="l00254"></a>00254         <span class="keywordflow">if</span> (!optionsFound.contains(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>))
316 <a name="l00255"></a>00255           options &lt;&lt; entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>;
317 <a name="l00256"></a>00256         if (!(entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf25c45f4e4843deac514dd547b96d2258">QCommandLine::Multiple</a>))
318 <a name="l00257"></a>00257           optionsFound[entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>].clear();
319 <a name="l00258"></a>00258         optionsFound[entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>].append(value);
320 <a name="l00259"></a>00259       }
321 <a name="l00260"></a>00260 
322 <a name="l00261"></a>00261       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>) {
323 <a name="l00262"></a>00262         entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = (<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a>) (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; ~<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>);
324 <a name="l00263"></a>00263         entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = (<a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a>) (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> | <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a>);
325 <a name="l00264"></a>00264         conf[entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>] = entry;
326 <a name="l00265"></a>00265         confLong[entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>] = entry;
327 <a name="l00266"></a>00266       }
328 <a name="l00267"></a>00267     }
329 <a name="l00268"></a>00268     <span class="comment">/* Stay here, stacked args */</span>
330 <a name="l00269"></a>00269     <span class="keywordflow">if</span> (stay)
331 <a name="l00270"></a>00270       i--;
332 <a name="l00271"></a>00271     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (forward)
333 <a name="l00272"></a>00272       i++;
334 <a name="l00273"></a>00273   }
335 <a name="l00274"></a>00274 
336 <a name="l00275"></a>00275   <span class="keywordflow">foreach</span> (<a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry, params) {
337 <a name="l00276"></a>00276     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>) {
338 <a name="l00277"></a>00277       emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"Param %1 is mandatory"</span>).arg(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>));
339 <a name="l00278"></a>00278       <span class="keywordflow">return</span> <span class="keyword">false</span>;
340 <a name="l00279"></a>00279     }
341 <a name="l00280"></a>00280   }
342 <a name="l00281"></a>00281 
343 <a name="l00282"></a>00282   <span class="keywordflow">foreach</span> (<a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry, conf.values()) {
344 <a name="l00283"></a>00283     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>) {
345 <a name="l00284"></a>00284       QString type;
346 <a name="l00285"></a>00285 
347 <a name="l00286"></a>00286       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>)
348 <a name="l00287"></a>00287         type = tr(<span class="stringliteral">"Switch"</span>);
349 <a name="l00288"></a>00288       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c8b14ef103bb24ae3ff9ef312709968a0">QCommandLine::Option</a>)
350 <a name="l00289"></a>00289         type = tr(<span class="stringliteral">"Option"</span>);
351 <a name="l00290"></a>00290 
352 <a name="l00291"></a>00291       emit <a class="code" href="class_q_command_line.html#3f3de5835579d7e872faee0f96750bd1">parseError</a>(tr(<span class="stringliteral">"%1 %2 is mandatory"</span>).arg(type).arg(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>));
353 <a name="l00292"></a>00292       <span class="keywordflow">return</span> <span class="keyword">false</span>;
354 <a name="l00293"></a>00293     }
355 <a name="l00294"></a>00294   }
356 <a name="l00295"></a>00295 
357 <a name="l00296"></a>00296   <span class="keywordflow">foreach</span> (QString key, switchs) {
358 <a name="l00297"></a>00297     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; switchsFound[key]; i++) {
359 <a name="l00298"></a>00298       <span class="keywordflow">if</span> (d-&gt;help &amp;&amp; key == <a class="code" href="class_q_command_line.html#5576b07bb95326a0edf219b972a39aa6">helpEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>)
360 <a name="l00299"></a>00299         <a class="code" href="class_q_command_line.html#2b85218cabed3e027cfa9a810ede1dac">showHelp</a>();
361 <a name="l00300"></a>00300       <span class="keywordflow">if</span> (d-&gt;version &amp;&amp; key == <a class="code" href="class_q_command_line.html#4bb2308ed7ce991912c95508f21e5350">versionEntry</a>.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>)
362 <a name="l00301"></a>00301         <a class="code" href="class_q_command_line.html#8d79376d5713a8863b9475cc6d749e48">showVersion</a>();
363 <a name="l00302"></a>00302       emit <a class="code" href="class_q_command_line.html#2f2e0a3f4982add67059133dfeb747dd">switchFound</a>(key);
364 <a name="l00303"></a>00303     }
365 <a name="l00304"></a>00304   }
366 <a name="l00305"></a>00305 
367 <a name="l00306"></a>00306   <span class="keywordflow">foreach</span> (QString key, options) {
368 <a name="l00307"></a>00307     <span class="keywordflow">foreach</span> (QString opt, optionsFound[key])
369 <a name="l00308"></a>00308       emit <a class="code" href="class_q_command_line.html#74272ceef76f6ee1f7848aef3315eda9">optionFound</a>(key, opt);
370 <a name="l00309"></a>00309   }  <span class="keywordflow">return</span> <span class="keyword">true</span>;
371 <a name="l00310"></a>00310 }
372 <a name="l00311"></a>00311 
373 <a name="l00312"></a>00312 <span class="keywordtype">void</span>
374 <a name="l00313"></a><a class="code" href="class_q_command_line.html#f49cc8818f6884f3d2c9f55a395bfdb0">00313</a> <a class="code" href="class_q_command_line.html#f49cc8818f6884f3d2c9f55a395bfdb0">QCommandLine::addOption</a>(<span class="keyword">const</span> QChar &amp; shortName,
375 <a name="l00314"></a>00314                         <span class="keyword">const</span> QString &amp; longName,
376 <a name="l00315"></a>00315                         <span class="keyword">const</span> QString &amp; descr,
377 <a name="l00316"></a>00316                         <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a> flags)
378 <a name="l00317"></a>00317 {
379 <a name="l00318"></a>00318   <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry;
380 <a name="l00319"></a>00319 
381 <a name="l00320"></a>00320   entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> = <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c8b14ef103bb24ae3ff9ef312709968a0">QCommandLine::Option</a>;
382 <a name="l00321"></a>00321   entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a> = shortName;
383 <a name="l00322"></a>00322   entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> = longName;
384 <a name="l00323"></a>00323   entry.<a class="code" href="struct_q_command_line_config_entry.html#d6ea57728ea781f6359a30a85ac5887c">descr</a> = descr;
385 <a name="l00324"></a>00324   entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = flags;
386 <a name="l00325"></a>00325   d-&gt;config &lt;&lt; entry;
387 <a name="l00326"></a>00326 }
388 <a name="l00327"></a>00327 
389 <a name="l00328"></a>00328 <span class="keywordtype">void</span>
390 <a name="l00329"></a><a class="code" href="class_q_command_line.html#fc417acc804dae5b8b44386c2fbb731d">00329</a> <a class="code" href="class_q_command_line.html#fc417acc804dae5b8b44386c2fbb731d">QCommandLine::addSwitch</a>(<span class="keyword">const</span> QChar &amp; shortName,
391 <a name="l00330"></a>00330                         <span class="keyword">const</span> QString &amp; longName,
392 <a name="l00331"></a>00331                         <span class="keyword">const</span> QString &amp; descr,
393 <a name="l00332"></a>00332                         <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a> flags)
394 <a name="l00333"></a>00333 {
395 <a name="l00334"></a>00334   <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry;
396 <a name="l00335"></a>00335 
397 <a name="l00336"></a>00336   entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> = <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>;
398 <a name="l00337"></a>00337   entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a> = shortName;
399 <a name="l00338"></a>00338   entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> = longName;
400 <a name="l00339"></a>00339   entry.<a class="code" href="struct_q_command_line_config_entry.html#d6ea57728ea781f6359a30a85ac5887c">descr</a> = descr;
401 <a name="l00340"></a>00340   entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = flags;
402 <a name="l00341"></a>00341   d-&gt;config &lt;&lt; entry;
403 <a name="l00342"></a>00342 }
404 <a name="l00343"></a>00343 
405 <a name="l00344"></a>00344 <span class="keywordtype">void</span>
406 <a name="l00345"></a><a class="code" href="class_q_command_line.html#670851615fee9ba8ba23df2ec27d4a9c">00345</a> <a class="code" href="class_q_command_line.html#670851615fee9ba8ba23df2ec27d4a9c">QCommandLine::addParam</a>(<span class="keyword">const</span> QString &amp; name,
407 <a name="l00346"></a>00346                        <span class="keyword">const</span> QString &amp; descr,
408 <a name="l00347"></a>00347                        <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf">QCommandLine::Flags</a> flags)
409 <a name="l00348"></a>00348 {
410 <a name="l00349"></a>00349   <a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry;
411 <a name="l00350"></a>00350 
412 <a name="l00351"></a>00351   entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> = <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a>;
413 <a name="l00352"></a>00352   entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> = name;
414 <a name="l00353"></a>00353   entry.<a class="code" href="struct_q_command_line_config_entry.html#d6ea57728ea781f6359a30a85ac5887c">descr</a> = descr;
415 <a name="l00354"></a>00354   entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> = flags;
416 <a name="l00355"></a>00355   d-&gt;config &lt;&lt; entry;
417 <a name="l00356"></a>00356 }
418 <a name="l00357"></a>00357 
419 <a name="l00358"></a>00358 <span class="keywordtype">void</span>
420 <a name="l00359"></a><a class="code" href="class_q_command_line.html#5e7f7162973c796320b04659ea5b86df">00359</a> <a class="code" href="class_q_command_line.html#5e7f7162973c796320b04659ea5b86df">QCommandLine::removeOption</a>(<span class="keyword">const</span> QString &amp; name)
421 <a name="l00360"></a>00360 {
422 <a name="l00361"></a>00361   <span class="keywordtype">int</span> i;
423 <a name="l00362"></a>00362 
424 <a name="l00363"></a>00363   <span class="keywordflow">for</span> (i = 0; i &lt; d-&gt;config.size(); ++i) {
425 <a name="l00364"></a>00364     <span class="keywordflow">if</span> (d-&gt;config[i].type == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c8b14ef103bb24ae3ff9ef312709968a0">QCommandLine::Option</a> &amp;&amp;
426 <a name="l00365"></a>00365         (d-&gt;config[i].shortName == name.at(0) || d-&gt;config[i].longName == name)) {
427 <a name="l00366"></a>00366       d-&gt;config.removeAt(i);
428 <a name="l00367"></a>00367       return ;
429 <a name="l00368"></a>00368     }
430 <a name="l00369"></a>00369   }
431 <a name="l00370"></a>00370 }
432 <a name="l00371"></a>00371 
433 <a name="l00372"></a>00372 <span class="keywordtype">void</span>
434 <a name="l00373"></a><a class="code" href="class_q_command_line.html#a597e4ffee134ed2d9e02d17bc2e42a5">00373</a> <a class="code" href="class_q_command_line.html#a597e4ffee134ed2d9e02d17bc2e42a5">QCommandLine::removeSwitch</a>(<span class="keyword">const</span> QString &amp; name)
435 <a name="l00374"></a>00374 {
436 <a name="l00375"></a>00375   <span class="keywordtype">int</span> i;
437 <a name="l00376"></a>00376 
438 <a name="l00377"></a>00377   <span class="keywordflow">for</span> (i = 0; i &lt; d-&gt;config.size(); ++i) {
439 <a name="l00378"></a>00378     <span class="keywordflow">if</span> (d-&gt;config[i].type == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a> &amp;&amp;
440 <a name="l00379"></a>00379         (d-&gt;config[i].shortName == name.at(0) || d-&gt;config[i].longName == name)) {
441 <a name="l00380"></a>00380       d-&gt;config.removeAt(i);
442 <a name="l00381"></a>00381       return ;
443 <a name="l00382"></a>00382     }
444 <a name="l00383"></a>00383   }
445 <a name="l00384"></a>00384 }
446 <a name="l00385"></a>00385 
447 <a name="l00386"></a>00386 <span class="keywordtype">void</span>
448 <a name="l00387"></a><a class="code" href="class_q_command_line.html#b6e8bca88c710d2dde713f92fe92b666">00387</a> <a class="code" href="class_q_command_line.html#b6e8bca88c710d2dde713f92fe92b666">QCommandLine::removeParam</a>(<span class="keyword">const</span> QString &amp; name)
449 <a name="l00388"></a>00388 {
450 <a name="l00389"></a>00389   <span class="keywordtype">int</span> i;
451 <a name="l00390"></a>00390 
452 <a name="l00391"></a>00391   <span class="keywordflow">for</span> (i = 0; i &lt; d-&gt;config.size(); ++i) {
453 <a name="l00392"></a>00392     <span class="keywordflow">if</span> (d-&gt;config[i].type == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a> &amp;&amp;
454 <a name="l00393"></a>00393         (d-&gt;config[i].shortName == name.at(0) || d-&gt;config[i].longName == name)) {
455 <a name="l00394"></a>00394       d-&gt;config.removeAt(i);
456 <a name="l00395"></a>00395       return ;
457 <a name="l00396"></a>00396     }
458 <a name="l00397"></a>00397   }
459 <a name="l00398"></a>00398 }
460 <a name="l00399"></a>00399 
461 <a name="l00400"></a>00400 
462 <a name="l00401"></a>00401 QString
463 <a name="l00402"></a><a class="code" href="class_q_command_line.html#20fefc0901d1602d03e3d5150f5bde5d">00402</a> <a class="code" href="class_q_command_line.html#20fefc0901d1602d03e3d5150f5bde5d">QCommandLine::help</a>(<span class="keywordtype">bool</span> logo)
464 <a name="l00403"></a>00403 {
465 <a name="l00404"></a>00404   QString h;
466 <a name="l00405"></a>00405 
467 <a name="l00406"></a>00406   <span class="keywordflow">if</span> (logo)
468 <a name="l00407"></a>00407     h = <a class="code" href="class_q_command_line.html#7028a586e1deeded4fcfbb637abf6376">version</a>() + QLatin1String(<span class="stringliteral">"\n"</span>);
469 <a name="l00408"></a>00408   h = QLatin1String(<span class="stringliteral">"Usage:\n   "</span>);
470 <a name="l00409"></a>00409   <span class="comment">/* Executable name */</span>
471 <a name="l00410"></a>00410   <span class="keywordflow">if</span> (!d-&gt;args.isEmpty())
472 <a name="l00411"></a>00411     h += QFileInfo(d-&gt;args[0]).baseName();
473 <a name="l00412"></a>00412   <span class="keywordflow">else</span>
474 <a name="l00413"></a>00413     h += QCoreApplication::applicationName();
475 <a name="l00414"></a>00414   h.append(QLatin1String(<span class="stringliteral">" [switchs] [options]"</span>));
476 <a name="l00415"></a>00415   <span class="comment">/* Arguments, short */</span>
477 <a name="l00416"></a>00416   <span class="keywordflow">foreach</span> (<a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry, d-&gt;config) {
478 <a name="l00417"></a>00417     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c8b14ef103bb24ae3ff9ef312709968a0">QCommandLine::Option</a>) {
479 <a name="l00418"></a>00418       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bfd13780f6d768c16ed235f68c751fc844">QCommandLine::Mandatory</a>)
480 <a name="l00419"></a>00419         h.append(QLatin1String(<span class="stringliteral">" --"</span>) + entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> + QLatin1String(<span class="stringliteral">"=&lt;val&gt;"</span>));
481 <a name="l00420"></a>00420     }
482 <a name="l00421"></a>00421     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a>) {
483 <a name="l00422"></a>00422       h.append(QLatin1String(<span class="stringliteral">" "</span>));
484 <a name="l00423"></a>00423       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a>)
485 <a name="l00424"></a>00424         h.append(QLatin1String(<span class="stringliteral">"["</span>));
486 <a name="l00425"></a>00425       h.append(entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>);
487 <a name="l00426"></a>00426       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf25c45f4e4843deac514dd547b96d2258">QCommandLine::Multiple</a>)
488 <a name="l00427"></a>00427         h.append(QLatin1String(<span class="stringliteral">" ["</span>) + entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> + QLatin1String(<span class="stringliteral">" [...]]"</span>));
489 <a name="l00428"></a>00428       <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#2f6ed82d6104ec17009c04f53ef870d6">flags</a> &amp; <a class="code" href="class_q_command_line.html#a6d7f44346a07b8e9bbc19861d7679bf3cb70be5d114404d065112110ebc51e5">QCommandLine::Optional</a>)
490 <a name="l00429"></a>00429         h.append(QLatin1String(<span class="stringliteral">"]"</span>));
491 <a name="l00430"></a>00430     }
492 <a name="l00431"></a>00431   }
493 <a name="l00432"></a>00432   h.append(QLatin1String(<span class="stringliteral">"\n\n"</span>));
494 <a name="l00433"></a>00433 
495 <a name="l00434"></a>00434   h.append(QLatin1String(<span class="stringliteral">"Options:\n"</span>));
496 <a name="l00435"></a>00435 
497 <a name="l00436"></a>00436   QStringList vals;
498 <a name="l00437"></a>00437   QStringList descrs;
499 <a name="l00438"></a>00438   <span class="keywordtype">int</span> max = 0;
500 <a name="l00439"></a>00439 
501 <a name="l00440"></a>00440   <span class="keywordflow">foreach</span> (<a class="code" href="struct_q_command_line_config_entry.html" title="Configuration entry structure.">QCommandLineConfigEntry</a> entry, d-&gt;config) {
502 <a name="l00441"></a>00441     QString val;
503 <a name="l00442"></a>00442 
504 <a name="l00443"></a>00443     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c8b14ef103bb24ae3ff9ef312709968a0">QCommandLine::Option</a>)
505 <a name="l00444"></a>00444       val = QLatin1String(<span class="stringliteral">"-"</span>) + QString(entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>) +
506 <a name="l00445"></a>00445         QLatin1String(<span class="stringliteral">",--"</span>) + entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a> + QLatin1String(<span class="stringliteral">"=&lt;val&gt;"</span>);
507 <a name="l00446"></a>00446     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1c205c5d127bf40b2ee50043e82ba40b3a">QCommandLine::Switch</a>)
508 <a name="l00447"></a>00447       val = QLatin1String(<span class="stringliteral">"-"</span>) + QString(entry.<a class="code" href="struct_q_command_line_config_entry.html#9afa720ba159042097566708fc566b50">shortName</a>) + QLatin1String(<span class="stringliteral">",--"</span>) + entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>;
509 <a name="l00448"></a>00448     <span class="keywordflow">if</span> (entry.<a class="code" href="struct_q_command_line_config_entry.html#a151d2ee04de721f5d7e45050c8102df">type</a> == <a class="code" href="class_q_command_line.html#b7800ba521ac8bc5aa3159d2c5843d1ce94f6d953303e1ef30b772982ae898bd">QCommandLine::Param</a>)
510 <a name="l00449"></a>00449       val = entry.<a class="code" href="struct_q_command_line_config_entry.html#39ed71444b17d75fc0cd8223d36267e6">longName</a>;
511 <a name="l00450"></a>00450 
512 <a name="l00451"></a>00451     <span class="keywordflow">if</span> (val.size() &gt; max)
513 <a name="l00452"></a>00452       max = val.size();
514 <a name="l00453"></a>00453 
515 <a name="l00454"></a>00454     vals.append(val);
516 <a name="l00455"></a>00455     descrs.append(entry.<a class="code" href="struct_q_command_line_config_entry.html#d6ea57728ea781f6359a30a85ac5887c">descr</a> + QLatin1String(<span class="stringliteral">"\n"</span>));
517 <a name="l00456"></a>00456   }
518 <a name="l00457"></a>00457 
519 <a name="l00458"></a>00458   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; vals.size(); ++i) {
520 <a name="l00459"></a>00459     h.append(QLatin1String(<span class="stringliteral">"  "</span>));
521 <a name="l00460"></a>00460     h.append(vals[i]);
522 <a name="l00461"></a>00461     h.append(QString(QLatin1String(<span class="stringliteral">" "</span>)).repeated(max - vals[i].size() + 2));
523 <a name="l00462"></a>00462     h.append(descrs[i]);
524 <a name="l00463"></a>00463   }
525 <a name="l00464"></a>00464 
526 <a name="l00465"></a>00465   h.append(tr(<span class="stringliteral">"\nMandatory arguments to long options are mandatory for short options too.\n"</span>));
527 <a name="l00466"></a>00466 
528 <a name="l00467"></a>00467   <span class="keywordflow">return</span> h;
529 <a name="l00468"></a>00468 }
530 <a name="l00469"></a>00469 
531 <a name="l00470"></a>00470 QString
532 <a name="l00471"></a><a class="code" href="class_q_command_line.html#7028a586e1deeded4fcfbb637abf6376">00471</a> <a class="code" href="class_q_command_line.html#7028a586e1deeded4fcfbb637abf6376">QCommandLine::version</a>()
533 <a name="l00472"></a>00472 {
534 <a name="l00473"></a>00473   QString v;
535 <a name="l00474"></a>00474 
536 <a name="l00475"></a>00475   v = QCoreApplication::applicationName() + QLatin1Char(<span class="charliteral">' '</span>);
537 <a name="l00476"></a>00476   v += QCoreApplication::applicationVersion();
538 <a name="l00477"></a>00477   <span class="keywordflow">if</span> (!QCoreApplication::organizationDomain().isEmpty()
539 <a name="l00478"></a>00478       || !QCoreApplication::organizationName().isEmpty())
540 <a name="l00479"></a>00479     v = v + QLatin1String(<span class="stringliteral">" - "</span>) +
541 <a name="l00480"></a>00480       QCoreApplication::organizationDomain() + QLatin1String(<span class="stringliteral">" "</span>) +
542 <a name="l00481"></a>00481       QCoreApplication::organizationDomain();
543 <a name="l00482"></a>00482   <span class="keywordflow">return</span> v + QLatin1Char(<span class="charliteral">'\n'</span>);
544 <a name="l00483"></a>00483 }
545 <a name="l00484"></a>00484 
546 <a name="l00485"></a>00485 <span class="keywordtype">void</span>
547 <a name="l00486"></a><a class="code" href="class_q_command_line.html#2b85218cabed3e027cfa9a810ede1dac">00486</a> <a class="code" href="class_q_command_line.html#2b85218cabed3e027cfa9a810ede1dac">QCommandLine::showHelp</a>(<span class="keywordtype">bool</span> quit, <span class="keywordtype">int</span> returnCode)
548 <a name="l00487"></a>00487 {
549 <a name="l00488"></a>00488   std::cerr &lt;&lt; qPrintable(<a class="code" href="class_q_command_line.html#20fefc0901d1602d03e3d5150f5bde5d">help</a>());
550 <a name="l00489"></a>00489   <span class="keywordflow">if</span> (quit) {
551 <a name="l00490"></a>00490     <span class="comment">// Can't call QApplication::exit() here, because we may be called before app.exec()</span>
552 <a name="l00491"></a>00491     exit(returnCode);
553 <a name="l00492"></a>00492   }
554 <a name="l00493"></a>00493 }
555 <a name="l00494"></a>00494 
556 <a name="l00495"></a>00495 <span class="keywordtype">void</span>
557 <a name="l00496"></a><a class="code" href="class_q_command_line.html#8d79376d5713a8863b9475cc6d749e48">00496</a> <a class="code" href="class_q_command_line.html#8d79376d5713a8863b9475cc6d749e48">QCommandLine::showVersion</a>(<span class="keywordtype">bool</span> quit, <span class="keywordtype">int</span> returnCode)
558 <a name="l00497"></a>00497 {
559 <a name="l00498"></a>00498   std::cerr &lt;&lt; qPrintable(<a class="code" href="class_q_command_line.html#7028a586e1deeded4fcfbb637abf6376">version</a>());
560 <a name="l00499"></a>00499   <span class="keywordflow">if</span> (quit) {
561 <a name="l00500"></a>00500     exit(returnCode);
562 <a name="l00501"></a>00501   }
563 <a name="l00502"></a>00502 }
564 <a name="l00503"></a>00503 
565 </pre></div></div>
566 <hr size="1"><address style="text-align: right;"><small>Generated on Thu Oct 21 15:13:57 2010 for QCommandLine by&nbsp;
567 <a href="http://www.doxygen.org/index.html">
568 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
569 </body>
570 </html>