<!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/xhtml;charset=UTF-8"/> <title>libdap++: Clause.cc Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libdap++ <span id="projectnumber">Updated for version 3.8.2</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</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 id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('Clause_8cc.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>Clause.cc</h1> </div> </div> <div class="contents"> <a href="Clause_8cc.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">// -*- mode: c++; c-basic-offset:4 -*-</span> <a name="l00003"></a>00003 <a name="l00004"></a>00004 <span class="comment">// This file is part of libdap, A C++ implementation of the OPeNDAP Data</span> <a name="l00005"></a>00005 <span class="comment">// Access Protocol.</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">// Copyright (c) 2002,2003 OPeNDAP, Inc.</span> <a name="l00008"></a>00008 <span class="comment">// Author: James Gallagher <jgallagher@opendap.org></span> <a name="l00009"></a>00009 <span class="comment">//</span> <a name="l00010"></a>00010 <span class="comment">// This library is free software; you can redistribute it and/or</span> <a name="l00011"></a>00011 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span> <a name="l00012"></a>00012 <span class="comment">// License as published by the Free Software Foundation; either</span> <a name="l00013"></a>00013 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span> <a name="l00014"></a>00014 <span class="comment">//</span> <a name="l00015"></a>00015 <span class="comment">// This library is distributed in the hope that it will be useful,</span> <a name="l00016"></a>00016 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00017"></a>00017 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00018"></a>00018 <span class="comment">// Lesser General Public License for more details.</span> <a name="l00019"></a>00019 <span class="comment">//</span> <a name="l00020"></a>00020 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span> <a name="l00021"></a>00021 <span class="comment">// License along with this library; if not, write to the Free Software</span> <a name="l00022"></a>00022 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00023"></a>00023 <span class="comment">//</span> <a name="l00024"></a>00024 <span class="comment">// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="comment">// (c) COPYRIGHT URI/MIT 1996,1998,1999</span> <a name="l00027"></a>00027 <span class="comment">// Please first read the full copyright statement in the file COPYRIGHT_URI.</span> <a name="l00028"></a>00028 <span class="comment">//</span> <a name="l00029"></a>00029 <span class="comment">// Authors:</span> <a name="l00030"></a>00030 <span class="comment">// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu></span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="comment">// Implementation for the CE Clause class.</span> <a name="l00033"></a>00033 <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="config_8h.html">config.h</a>"</span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="preprocessor">#include <cassert></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <algorithm></span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="preprocessor">#include "expr.h"</span> <a name="l00041"></a>00041 <span class="preprocessor">#include "<a class="code" href="Byte_8h.html">Byte.h</a>"</span> <a name="l00042"></a>00042 <span class="preprocessor">#include "<a class="code" href="Int16_8h.html">Int16.h</a>"</span> <a name="l00043"></a>00043 <span class="preprocessor">#include "<a class="code" href="UInt16_8h.html">UInt16.h</a>"</span> <a name="l00044"></a>00044 <span class="preprocessor">#include "<a class="code" href="Int32_8h.html">Int32.h</a>"</span> <a name="l00045"></a>00045 <span class="preprocessor">#include "<a class="code" href="UInt32_8h.html">UInt32.h</a>"</span> <a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="DDS_8h.html">DDS.h</a>"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include "<a class="code" href="Clause_8h.html">Clause.h</a>"</span> <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="keyword">using</span> std::cerr; <a name="l00050"></a>00050 <span class="keyword">using</span> std::endl; <a name="l00051"></a>00051 <a name="l00052"></a>00052 <span class="keyword">namespace </span>libdap { <a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="structlibdap_1_1Clause.html#af59809927231f35f29eae3ab972bf8ce">00054</a> <a class="code" href="structlibdap_1_1Clause.html#a86f7ce9fd2b9db982268cc2b121989f3">Clause::Clause</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> oper, <a class="code" href="classlibdap_1_1rvalue.html">rvalue</a> *a1, <a class="code" href="namespacelibdap.html#a443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *rv) <a name="l00055"></a>00055 : _op(oper), _b_func(0), _bt_func(0), _arg1(a1), _args(rv) <a name="l00056"></a>00056 { <a name="l00057"></a>00057 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00058"></a>00058 } <a name="l00059"></a>00059 <span class="preprocessor">#if 1</span> <a name="l00060"></a><a class="code" href="structlibdap_1_1Clause.html#ae932a2f99ee42df567e1b5581040d643">00060</a> <span class="preprocessor"></span><a class="code" href="structlibdap_1_1Clause.html#a86f7ce9fd2b9db982268cc2b121989f3">Clause::Clause</a>(bool_func func, <a class="code" href="namespacelibdap.html#a443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *rv) <a name="l00061"></a>00061 : _op(0), _b_func(func), _bt_func(0), _arg1(0), _args(rv) <a name="l00062"></a>00062 { <a name="l00063"></a>00063 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="keywordflow">if</span> (_args) <span class="comment">// account for null arg list</span> <a name="l00066"></a>00066 _argc = _args->size(); <a name="l00067"></a>00067 <span class="keywordflow">else</span> <a name="l00068"></a>00068 _argc = 0; <a name="l00069"></a>00069 } <a name="l00070"></a>00070 <span class="preprocessor">#endif</span> <a name="l00071"></a><a class="code" href="structlibdap_1_1Clause.html#ac8c43eee6cceb5613379d8b2917b1641">00071</a> <span class="preprocessor"></span><a class="code" href="structlibdap_1_1Clause.html#a86f7ce9fd2b9db982268cc2b121989f3">Clause::Clause</a>(btp_func func, <a class="code" href="namespacelibdap.html#a443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *rv) <a name="l00072"></a>00072 : _op(0), _b_func(0), _bt_func(func), _arg1(0), _args(rv) <a name="l00073"></a>00073 { <a name="l00074"></a>00074 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="keywordflow">if</span> (_args) <a name="l00077"></a>00077 _argc = _args->size(); <a name="l00078"></a>00078 <span class="keywordflow">else</span> <a name="l00079"></a>00079 _argc = 0; <a name="l00080"></a>00080 } <a name="l00081"></a>00081 <a name="l00082"></a><a class="code" href="structlibdap_1_1Clause.html#a86f7ce9fd2b9db982268cc2b121989f3">00082</a> <a class="code" href="structlibdap_1_1Clause.html#a86f7ce9fd2b9db982268cc2b121989f3">Clause::Clause</a>() : _op(0), _b_func(0), _bt_func(0), _arg1(0), _args(0) <a name="l00083"></a>00083 {} <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a name="l00086"></a>00086 delete_rvalue(<a class="code" href="classlibdap_1_1rvalue.html">rvalue</a> *rv) <a name="l00087"></a>00087 { <a name="l00088"></a>00088 <span class="keyword">delete</span> rv; rv = 0; <a name="l00089"></a>00089 } <a name="l00090"></a>00090 <a name="l00091"></a><a class="code" href="structlibdap_1_1Clause.html#aaaeec48bcba4c7a9608c1bb3ef72983a">00091</a> <a class="code" href="structlibdap_1_1Clause.html#aaaeec48bcba4c7a9608c1bb3ef72983a">Clause::~Clause</a>() <a name="l00092"></a>00092 { <a name="l00093"></a>00093 <span class="keywordflow">if</span> (_arg1) { <a name="l00094"></a>00094 <span class="keyword">delete</span> _arg1; _arg1 = 0; <a name="l00095"></a>00095 } <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordflow">if</span> (_args) { <a name="l00098"></a>00098 <span class="comment">// _args is a pointer to a vector<rvalue*> and we must must delete</span> <a name="l00099"></a>00099 <span class="comment">// each rvalue pointer here explicitly. 02/03/04 jhrg</span> <a name="l00100"></a>00100 for_each(_args->begin(), _args->end(), delete_rvalue); <a name="l00101"></a>00101 <span class="keyword">delete</span> _args; _args = 0; <a name="l00102"></a>00102 } <a name="l00103"></a>00103 } <a name="l00104"></a>00104 <a name="l00106"></a>00106 <span class="keywordtype">bool</span> <a name="l00107"></a><a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473">00107</a> <a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">Clause::OK</a>() <a name="l00108"></a>00108 { <a name="l00109"></a>00109 <span class="comment">// Each clause object can contain one of: a relational clause, a boolean</span> <a name="l00110"></a>00110 <span class="comment">// function clause or a BaseType pointer function clause. It must have a</span> <a name="l00111"></a>00111 <span class="comment">// valid argument list.</span> <a name="l00112"></a>00112 <span class="comment">//</span> <a name="l00113"></a>00113 <span class="comment">// But, a valid arg list might contain zero arguments! 10/16/98 jhrg</span> <a name="l00114"></a>00114 <span class="keywordtype">bool</span> relational = (_op && !_b_func && !_bt_func); <a name="l00115"></a>00115 <span class="preprocessor">#if 1</span> <a name="l00116"></a>00116 <span class="preprocessor"></span> <span class="keywordtype">bool</span> <span class="keywordtype">boolean</span> = (!_op && _b_func && !_bt_func); <a name="l00117"></a>00117 <span class="preprocessor">#endif</span> <a name="l00118"></a>00118 <span class="preprocessor"></span> <span class="keywordtype">bool</span> basetype = (!_op && !_b_func && _bt_func); <a name="l00119"></a>00119 <a name="l00120"></a>00120 <span class="keywordflow">if</span> (relational) <a name="l00121"></a>00121 <span class="keywordflow">return</span> _arg1 && _args; <a name="l00122"></a>00122 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">boolean</span> || basetype) <a name="l00123"></a>00123 <span class="keywordflow">return</span> <span class="keyword">true</span>; <span class="comment">// Until we check arguments...10/16/98 jhrg</span> <a name="l00124"></a>00124 <span class="keywordflow">else</span> <a name="l00125"></a>00125 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00126"></a>00126 } <a name="l00127"></a>00127 <a name="l00129"></a>00129 <span class="keywordtype">bool</span> <a name="l00130"></a><a class="code" href="structlibdap_1_1Clause.html#a80d81003665b96012ee3ba175d80e608">00130</a> <a class="code" href="structlibdap_1_1Clause.html#a80d81003665b96012ee3ba175d80e608" title="Return true if the clause returns a boolean value.">Clause::boolean_clause</a>() <a name="l00131"></a>00131 { <a name="l00132"></a>00132 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="keywordflow">return</span> _op || _b_func; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00138"></a>00138 <span class="keywordtype">bool</span> <a name="l00139"></a><a class="code" href="structlibdap_1_1Clause.html#a7bd5122be1851f0bf32ec1c58b46eaa9">00139</a> <a class="code" href="structlibdap_1_1Clause.html#a7bd5122be1851f0bf32ec1c58b46eaa9" title="Return true if the clause returns a value in a BaseType pointer.">Clause::value_clause</a>() <a name="l00140"></a>00140 { <a name="l00141"></a>00141 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="keywordflow">return</span> (_bt_func != 0); <a name="l00144"></a>00144 } <a name="l00145"></a>00145 <a name="l00155"></a>00155 <span class="keywordtype">bool</span> <a name="l00156"></a><a class="code" href="structlibdap_1_1Clause.html#abfff44c4db49ad7462d14665b2458588">00156</a> <a class="code" href="structlibdap_1_1Clause.html#abfff44c4db49ad7462d14665b2458588" title="Evaluate a clause which returns a boolean value This method must only be evaluated for clauses with r...">Clause::value</a>(<a class="code" href="classlibdap_1_1DDS.html">DDS</a> &dds) <a name="l00157"></a>00157 { <a name="l00158"></a>00158 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00159"></a>00159 assert(_op || _b_func); <a name="l00160"></a>00160 <a name="l00161"></a>00161 <span class="keywordflow">if</span> (_op) { <span class="comment">// Is it a relational clause?</span> <a name="l00162"></a>00162 <span class="comment">// rvalue::bvalue(...) returns the rvalue encapsulated in a</span> <a name="l00163"></a>00163 <span class="comment">// BaseType *.</span> <a name="l00164"></a>00164 <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *btp = _arg1-><a class="code" href="classlibdap_1_1rvalue.html#a5ec1d2d66b162aa9ad82b658e70ce7de">bvalue</a>(dds); <a name="l00165"></a>00165 <span class="comment">// The list of rvalues is an implicit logical OR, so assume</span> <a name="l00166"></a>00166 <span class="comment">// FALSE and return TRUE for the first TRUE subclause.</span> <a name="l00167"></a>00167 <span class="keywordtype">bool</span> result = <span class="keyword">false</span>; <a name="l00168"></a>00168 <span class="keywordflow">for</span> (<a class="code" href="namespacelibdap.html#a72bbbdd2885cd9b1105e8f9d25af0b79">rvalue_list_iter</a> i = _args->begin(); <a name="l00169"></a>00169 i != _args->end() && !result; <a name="l00170"></a>00170 i++) { <a name="l00171"></a>00171 result = result || btp-><a class="code" href="classlibdap_1_1BaseType.html#a8a0000be2a244e3e07abda3020af8800" title="Evaluate relational operators.">ops</a>((*i)->bvalue(dds), _op); <a name="l00172"></a>00172 } <a name="l00173"></a>00173 <a name="l00174"></a>00174 <span class="keywordflow">return</span> result; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_b_func) { <span class="comment">// ...A bool function?</span> <a name="l00177"></a>00177 <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **argv = <a class="code" href="namespacelibdap.html#a928b16257bc714971a2a3c91cb42d882">build_btp_args</a>(_args, dds); <a name="l00178"></a>00178 <a name="l00179"></a>00179 <span class="keywordtype">bool</span> result = <span class="keyword">false</span>; <a name="l00180"></a>00180 (*_b_func)(_argc, argv, dds, &result); <a name="l00181"></a>00181 <span class="keyword">delete</span>[] argv; <span class="comment">// Cache me!</span> <a name="l00182"></a>00182 argv = 0; <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="keywordflow">return</span> result; <a name="l00185"></a>00185 } <a name="l00186"></a>00186 <span class="keywordflow">else</span> { <a name="l00187"></a>00187 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00188"></a>00188 <span class="stringliteral">"A selection expression must contain only boolean clauses."</span>); <a name="l00189"></a>00189 } <a name="l00190"></a>00190 } <a name="l00191"></a>00191 <a name="l00203"></a>00203 <span class="keywordtype">bool</span> <a name="l00204"></a><a class="code" href="structlibdap_1_1Clause.html#a7b124a939247dce1320c494a3b18f6a1">00204</a> <a class="code" href="structlibdap_1_1Clause.html#abfff44c4db49ad7462d14665b2458588" title="Evaluate a clause which returns a boolean value This method must only be evaluated for clauses with r...">Clause::value</a>(<a class="code" href="classlibdap_1_1DDS.html">DDS</a> &dds, <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **value) <a name="l00205"></a>00205 { <a name="l00206"></a>00206 assert(<a class="code" href="structlibdap_1_1Clause.html#aeaccc72688521a8b08aeae970d983473" title="Checks the &quot;representation invariant&quot; of a clause.">OK</a>()); <a name="l00207"></a>00207 assert(_bt_func); <a name="l00208"></a>00208 <a name="l00209"></a>00209 <span class="keywordflow">if</span> (_bt_func) { <a name="l00210"></a>00210 <span class="comment">// build_btp_args() is a function defined in RValue.cc. It no longer</span> <a name="l00211"></a>00211 <span class="comment">// reads the values as it builds the arguments, that is now left up</span> <a name="l00212"></a>00212 <span class="comment">// to the functions themselves. 9/25/06 jhrg</span> <a name="l00213"></a>00213 <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **argv = <a class="code" href="namespacelibdap.html#a928b16257bc714971a2a3c91cb42d882">build_btp_args</a>(_args, dds); <a name="l00214"></a>00214 <a name="l00215"></a>00215 (*_bt_func)(_argc, argv, dds, <a class="code" href="structlibdap_1_1Clause.html#abfff44c4db49ad7462d14665b2458588" title="Evaluate a clause which returns a boolean value This method must only be evaluated for clauses with r...">value</a>); <a name="l00216"></a>00216 <a name="l00217"></a>00217 <span class="keyword">delete</span>[] argv; <span class="comment">// Cache me!</span> <a name="l00218"></a>00218 argv = 0; <a name="l00219"></a>00219 <a name="l00220"></a>00220 <span class="keywordflow">if</span> (*value) { <a name="l00221"></a>00221 (*value)->set_send_p(<span class="keyword">true</span>); <a name="l00222"></a>00222 (*value)->set_read_p(<span class="keyword">true</span>); <a name="l00223"></a>00223 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00224"></a>00224 } <a name="l00225"></a>00225 <span class="keywordflow">else</span> { <a name="l00226"></a>00226 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00227"></a>00227 } <a name="l00228"></a>00228 } <a name="l00229"></a>00229 <span class="keywordflow">else</span> { <a name="l00230"></a>00230 <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <a name="l00231"></a>00231 <span class="stringliteral">"Clause::value() was called in a context expecting a BaseType pointer return, but the Clause was boolean-valued instead."</span>); <a name="l00232"></a>00232 } <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a>00235 } <span class="comment">// namespace libdap</span> </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="Clause_8cc.html">Clause.cc</a> </li> <li class="footer">Generated on Tue Feb 8 2011 for libdap++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>