summaryrefslogtreecommitdiff
path: root/tclap-1.2.1/docs/html/XorHandler_8h_source.html
blob: 271f7a2d355af8ce8ee5800fc220c22b3c98ea73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>tclap: XorHandler.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.0 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>XorHandler.h</h1><a href="XorHandler_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">/****************************************************************************** </span>
<a name="l00003"></a>00003 <span class="comment"> * </span>
<a name="l00004"></a>00004 <span class="comment"> *  file:  XorHandler.h</span>
<a name="l00005"></a>00005 <span class="comment"> * </span>
<a name="l00006"></a>00006 <span class="comment"> *  Copyright (c) 2003, Michael E. Smoot .</span>
<a name="l00007"></a>00007 <span class="comment"> *  Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.</span>
<a name="l00008"></a>00008 <span class="comment"> *  All rights reverved.</span>
<a name="l00009"></a>00009 <span class="comment"> * </span>
<a name="l00010"></a>00010 <span class="comment"> *  See the file COPYING in the top directory of this distribution for</span>
<a name="l00011"></a>00011 <span class="comment"> *  more information.</span>
<a name="l00012"></a>00012 <span class="comment"> *  </span>
<a name="l00013"></a>00013 <span class="comment"> *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS </span>
<a name="l00014"></a>00014 <span class="comment"> *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, </span>
<a name="l00015"></a>00015 <span class="comment"> *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL </span>
<a name="l00016"></a>00016 <span class="comment"> *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER </span>
<a name="l00017"></a>00017 <span class="comment"> *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING </span>
<a name="l00018"></a>00018 <span class="comment"> *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER </span>
<a name="l00019"></a>00019 <span class="comment"> *  DEALINGS IN THE SOFTWARE.  </span>
<a name="l00020"></a>00020 <span class="comment"> *  </span>
<a name="l00021"></a>00021 <span class="comment"> *****************************************************************************/</span> 
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">#ifndef TCLAP_XORHANDLER_H</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define TCLAP_XORHANDLER_H</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;<a class="code" href="Arg_8h.html">tclap/Arg.h</a>&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">namespace </span>TCLAP {
<a name="l00033"></a>00033 
<a name="l00038"></a><a class="code" href="classTCLAP_1_1XorHandler.html">00038</a> <span class="keyword">class </span><a class="code" href="classTCLAP_1_1XorHandler.html" title="This class handles lists of Arg&amp;#39;s that are to be XOR&amp;#39;d on the command line...">XorHandler</a>
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040     <span class="keyword">protected</span>:
<a name="l00041"></a>00041 
<a name="l00045"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1">00045</a>         std::vector&lt; std::vector&lt;Arg*&gt; &gt; <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047     <span class="keyword">public</span>:
<a name="l00048"></a>00048 
<a name="l00052"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a195391f50b7fe5eb939c2f6d236f571e">00052</a>         <a class="code" href="classTCLAP_1_1XorHandler.html#a195391f50b7fe5eb939c2f6d236f571e" title="Constructor.">XorHandler</a>( ) : <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>(std::vector&lt; std::vector&lt;<a class="code" href="classTCLAP_1_1Arg.html" title="A virtual base class that defines the essential data for all arguments.">Arg</a>*&gt; &gt;()) {}
<a name="l00053"></a>00053 
<a name="l00058"></a>00058         <span class="keywordtype">void</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a76f156bf36a8aede334801aa242f31b9" title="Add a list of Arg*&amp;#39;s that will be orred together.">add</a>( std::vector&lt;Arg*&gt;&amp; ors );
<a name="l00059"></a>00059             
<a name="l00067"></a>00067         <span class="keywordtype">int</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a3df7722e4c4c5d331de69fc902336b00" title="Checks whether the specified Arg is in one of the xor lists and if it does match...">check</a>( <span class="keyword">const</span> <a class="code" href="classTCLAP_1_1Arg.html" title="A virtual base class that defines the essential data for all arguments.">Arg</a>* a );
<a name="l00068"></a>00068 
<a name="l00072"></a>00072         std::string <a class="code" href="classTCLAP_1_1XorHandler.html#aca185a80e9df6e4250a230fa5aec7891" title="Returns the XOR specific short usage.">shortUsage</a>();
<a name="l00073"></a>00073 
<a name="l00078"></a>00078         <span class="keywordtype">void</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a257a855934eb343a0fad3c4e5fe5ff57" title="Prints the XOR specific long usage.">printLongUsage</a>(std::ostream&amp; os);
<a name="l00079"></a>00079 
<a name="l00085"></a>00085         <span class="keywordtype">bool</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a1a74fab4667cc591a1e3094c91bc942d" title="Simply checks whether the Arg is contained in one of the arg lists.">contains</a>( <span class="keyword">const</span> <a class="code" href="classTCLAP_1_1Arg.html" title="A virtual base class that defines the essential data for all arguments.">Arg</a>* a );
<a name="l00086"></a>00086 
<a name="l00087"></a>00087         std::vector&lt; std::vector&lt;Arg*&gt; &gt;&amp; <a class="code" href="classTCLAP_1_1XorHandler.html#a0e0d95c697d227cc51f82424b8530182">getXorList</a>(); 
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 };
<a name="l00090"></a>00090 
<a name="l00091"></a>00091 
<a name="l00093"></a>00093 <span class="comment">//BEGIN XOR.cpp</span>
<a name="l00095"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a76f156bf36a8aede334801aa242f31b9">00095</a> <span class="comment"></span><span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a76f156bf36a8aede334801aa242f31b9" title="Add a list of Arg*&amp;#39;s that will be orred together.">XorHandler::add</a>( std::vector&lt;Arg*&gt;&amp; ors )
<a name="l00096"></a>00096 { 
<a name="l00097"></a>00097     <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>.push_back( ors );
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00100"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a3df7722e4c4c5d331de69fc902336b00">00100</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a3df7722e4c4c5d331de69fc902336b00" title="Checks whether the specified Arg is in one of the xor lists and if it does match...">XorHandler::check</a>( <span class="keyword">const</span> <a class="code" href="classTCLAP_1_1Arg.html" title="A virtual base class that defines the essential data for all arguments.">Arg</a>* a ) 
<a name="l00101"></a>00101 {
<a name="l00102"></a>00102     <span class="comment">// iterate over each XOR list</span>
<a name="l00103"></a>00103     <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; <span class="keyword">static_cast&lt;</span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span><span class="keyword">&gt;</span>(i) &lt; <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>.size(); i++ )
<a name="l00104"></a>00104     {
<a name="l00105"></a>00105         <span class="comment">// if the XOR list contains the arg..</span>
<a name="l00106"></a>00106         <a class="code" href="namespaceTCLAP.html#a04213af1ffc3178ce5f771d21d5164a2" title="Typedef of an Arg vector iterator.">ArgVectorIterator</a> ait = std::find( <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].begin(), 
<a name="l00107"></a>00107                                            <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].end(), a );
<a name="l00108"></a>00108         <span class="keywordflow">if</span> ( ait != <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].end() )
<a name="l00109"></a>00109         {
<a name="l00110"></a>00110             <span class="comment">// first check to see if a mutually exclusive switch</span>
<a name="l00111"></a>00111             <span class="comment">// has not already been set</span>
<a name="l00112"></a>00112             <span class="keywordflow">for</span> ( <a class="code" href="namespaceTCLAP.html#a04213af1ffc3178ce5f771d21d5164a2" title="Typedef of an Arg vector iterator.">ArgVectorIterator</a> it = <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].begin(); 
<a name="l00113"></a>00113                   it != <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].end(); 
<a name="l00114"></a>00114                   it++ )
<a name="l00115"></a>00115                 <span class="keywordflow">if</span> ( a != (*it) &amp;&amp; (*it)-&gt;<a class="code" href="classTCLAP_1_1Arg.html#a6af7a1e92b5d92fc2d90c1a95aab4384" title="Indicates whether the argument has already been set.">isSet</a>() )
<a name="l00116"></a>00116                     <span class="keywordflow">throw</span>(<a class="code" href="classTCLAP_1_1CmdLineParseException.html" title="Thrown from CmdLine when the arguments on the command line are not properly specified...">CmdLineParseException</a>(
<a name="l00117"></a>00117                           <span class="stringliteral">&quot;Mutually exclusive argument already set!&quot;</span>,
<a name="l00118"></a>00118                           (*it)-&gt;toString()));
<a name="l00119"></a>00119 
<a name="l00120"></a>00120             <span class="comment">// go through and set each arg that is not a</span>
<a name="l00121"></a>00121             <span class="keywordflow">for</span> ( <a class="code" href="namespaceTCLAP.html#a04213af1ffc3178ce5f771d21d5164a2" title="Typedef of an Arg vector iterator.">ArgVectorIterator</a> it = <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].begin(); 
<a name="l00122"></a>00122                   it != <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].end(); 
<a name="l00123"></a>00123                   it++ )
<a name="l00124"></a>00124                 <span class="keywordflow">if</span> ( a != (*it) )
<a name="l00125"></a>00125                     (*it)-&gt;xorSet();
<a name="l00126"></a>00126 
<a name="l00127"></a>00127             <span class="comment">// return the number of required args that have now been set</span>
<a name="l00128"></a>00128             <span class="keywordflow">if</span> ( (*ait)-&gt;allowMore() )
<a name="l00129"></a>00129                 <span class="keywordflow">return</span> 0;
<a name="l00130"></a>00130             <span class="keywordflow">else</span>
<a name="l00131"></a>00131                 <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(<a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].size());
<a name="l00132"></a>00132         }
<a name="l00133"></a>00133     }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135     <span class="keywordflow">if</span> ( a-&gt;<a class="code" href="classTCLAP_1_1Arg.html#a00a3cfdb2b6e9a111ad39cbd4978b96c" title="Indicates whether the argument is required.">isRequired</a>() )
<a name="l00136"></a>00136         <span class="keywordflow">return</span> 1;
<a name="l00137"></a>00137     <span class="keywordflow">else</span>
<a name="l00138"></a>00138         <span class="keywordflow">return</span> 0;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00141"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a1a74fab4667cc591a1e3094c91bc942d">00141</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a1a74fab4667cc591a1e3094c91bc942d" title="Simply checks whether the Arg is contained in one of the arg lists.">XorHandler::contains</a>( <span class="keyword">const</span> <a class="code" href="classTCLAP_1_1Arg.html" title="A virtual base class that defines the essential data for all arguments.">Arg</a>* a )
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143     <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; <span class="keyword">static_cast&lt;</span><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span><span class="keyword">&gt;</span>(i) &lt; <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>.size(); i++ )
<a name="l00144"></a>00144         <span class="keywordflow">for</span> ( <a class="code" href="namespaceTCLAP.html#a04213af1ffc3178ce5f771d21d5164a2" title="Typedef of an Arg vector iterator.">ArgVectorIterator</a> it = <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].begin(); 
<a name="l00145"></a>00145               it != <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>[i].end(); 
<a name="l00146"></a>00146               it++ )    
<a name="l00147"></a>00147             <span class="keywordflow">if</span> ( a == (*it) )
<a name="l00148"></a>00148                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 
<a name="l00153"></a><a class="code" href="classTCLAP_1_1XorHandler.html#a0e0d95c697d227cc51f82424b8530182">00153</a> <span class="keyword">inline</span> std::vector&lt; std::vector&lt;Arg*&gt; &gt;&amp; <a class="code" href="classTCLAP_1_1XorHandler.html#a0e0d95c697d227cc51f82424b8530182">XorHandler::getXorList</a>() 
<a name="l00154"></a>00154 {
<a name="l00155"></a>00155     <span class="keywordflow">return</span> <a class="code" href="classTCLAP_1_1XorHandler.html#a4ebd5b96e23a0ab03bdd431fe622d4e1" title="The list of of lists of Arg&amp;#39;s to be or&amp;#39;d together.">_orList</a>;
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158 
<a name="l00159"></a>00159 
<a name="l00161"></a>00161 <span class="comment">//END XOR.cpp</span>
<a name="l00163"></a>00163 <span class="comment"></span>
<a name="l00164"></a>00164 } <span class="comment">//namespace TCLAP</span>
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 <span class="preprocessor">#endif </span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Sat Apr 16 15:34:24 2011 for tclap by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.0 </small></address>
</body>
</html>