Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > f149f58f4a75af135bdb24f5dfe94165 > files > 303

libdap-doc-3.9.3-3mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>libdap++: RValue.cc 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.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;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 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>RValue.cc</h1><a href="RValue_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 &lt;jgallagher@opendap.org&gt;</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-1999</span>
<a name="l00027"></a>00027 <span class="comment">// Please 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 &lt;jgallagher@gso.uri.edu&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="comment">// This file contains mfuncs defined for struct rvalue (see expr.h) that</span>
<a name="l00033"></a>00033 <span class="comment">// *cannot* be included in that struct's declaration because their</span>
<a name="l00034"></a>00034 <span class="comment">// definitions must follow *both* rvalue's and func_rvalue's declarations.</span>
<a name="l00035"></a>00035 <span class="comment">// jhrg 3/4/96</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="config_8h.html">config.h</a>"</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keywordtype">char</span> rcsid[] <a class="code" href="config_8h.html#05e109ec893d0b12023d5b0cf4f718c4">not_used</a> =
<a name="l00040"></a>00040     {<span class="stringliteral">"$Id: RValue.cc 20518 2009-03-05 23:39:46Z jimg $"</span>
<a name="l00041"></a>00041     };
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="BaseType_8h.html">BaseType.h</a>"</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include "expr.h"</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include "<a class="code" href="RValue_8h.html">RValue.h</a>"</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include "<a class="code" href="DDS_8h.html">DDS.h</a>"</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include "<a class="code" href="dods-limits_8h.html">dods-limits.h</a>"</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include "<a class="code" href="util_8h.html">util.h</a>"</span>
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="keyword">using namespace </span>std;
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="keyword">namespace </span>libdap {
<a name="l00056"></a>00056 
<a name="l00057"></a>00057 <a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *
<a name="l00058"></a><a class="code" href="namespacelibdap.html#a689627594051295e6cb5e472403f943">00058</a> <a class="code" href="namespacelibdap.html#a689627594051295e6cb5e472403f943">make_rvalue_list</a>(<a class="code" href="classlibdap_1_1rvalue.html">rvalue</a> *rv)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060     assert(rv);
<a name="l00061"></a>00061 
<a name="l00062"></a>00062     <a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *rvals = <span class="keyword">new</span> <a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a>;
<a name="l00063"></a>00063 
<a name="l00064"></a>00064     <span class="keywordflow">return</span> <a class="code" href="namespacelibdap.html#30de006b7d3ba0b0ee8aca90d4648844">append_rvalue_list</a>(rvals, rv);
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 <span class="comment">// Given a rvalue_list pointer RVALS and a value pointer VAL, make a variable</span>
<a name="l00068"></a>00068 <span class="comment">// to hold VAL and append that variable to the list RVALS.</span>
<a name="l00069"></a>00069 <span class="comment">//</span>
<a name="l00070"></a>00070 <span class="comment">// Returns: A pointer to the updated rvalue_list.</span>
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *
<a name="l00073"></a><a class="code" href="namespacelibdap.html#30de006b7d3ba0b0ee8aca90d4648844">00073</a> <a class="code" href="namespacelibdap.html#30de006b7d3ba0b0ee8aca90d4648844">append_rvalue_list</a>(<a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *rvals, <a class="code" href="classlibdap_1_1rvalue.html">rvalue</a> *rv)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     rvals-&gt;push_back(rv);
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     <span class="keywordflow">return</span> rvals;
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 
<a name="l00092"></a>00092 BaseType **
<a name="l00093"></a><a class="code" href="namespacelibdap.html#928b16257bc714971a2a3c91cb42d882">00093</a> <a class="code" href="namespacelibdap.html#928b16257bc714971a2a3c91cb42d882">build_btp_args</a>(<a class="code" href="namespacelibdap.html#443d3b7d9ceaa4ec25e5bfcc555ce056">rvalue_list</a> *args, <a class="code" href="classlibdap_1_1DDS.html">DDS</a> &amp;dds)
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095     <span class="keywordtype">int</span> argc = 0;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097     <span class="keywordflow">if</span> (args)
<a name="l00098"></a>00098         argc = args-&gt;size();
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     <span class="comment">// Sanitize allocation size</span>
<a name="l00101"></a>00101     <span class="keywordflow">if</span> (!<a class="code" href="namespacelibdap.html#d29f8fc547919875e3369fefbf92fb15" title="sanitize the size of an array. Test for integer overflow when dynamically allocating...">size_ok</a>(<span class="keyword">sizeof</span>(<a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a>*), argc + 1))
<a name="l00102"></a>00102         <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1Error.html" title="A class for error processing.">Error</a>(<a class="code" href="Error_8h.html#5806d25bc779e86c285438e687669803">malformed_expr</a>, <span class="keywordtype">string</span>(<span class="stringliteral">"Malformed argument list ("</span>)
<a name="l00103"></a>00103                 + <a class="code" href="namespacelibdap.html#317edea830aab50d2137a5bd313cc86a">long_to_string</a>(argc) + <span class="keywordtype">string</span>(<span class="stringliteral">")."</span>));
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     <span class="comment">// Add space for a null terminator</span>
<a name="l00106"></a>00106     <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> **argv = <span class="keyword">new</span> <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a>*[argc + 1];
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     <span class="keywordtype">int</span> index = 0;
<a name="l00109"></a>00109     <span class="keywordflow">if</span> (argv &amp;&amp; argc) {
<a name="l00110"></a>00110         <span class="keywordflow">for</span> (<a class="code" href="classlibdap_1_1rvalue.html#3ba3fb841b7b8a1a02e369268d116f78">rvalue::Args_iter</a> i = args-&gt;begin(); i != args-&gt;end() &amp;&amp; index
<a name="l00111"></a>00111                 &lt; argc + 1; ++i)
<a name="l00112"></a>00112             argv[index++] = (*i)-&gt;bvalue(dds);
<a name="l00113"></a>00113     }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     <span class="keywordflow">if</span> (index != argc) {
<a name="l00116"></a>00116         <span class="keyword">delete</span>[] argv;
<a name="l00117"></a>00117         <span class="keywordflow">throw</span> <a class="code" href="classlibdap_1_1InternalErr.html" title="A class for software fault reporting.">InternalErr</a>(__FILE__, __LINE__, <span class="stringliteral">"index out of range."</span>);
<a name="l00118"></a>00118     }
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     argv[index] = 0; <span class="comment">// Add the null terminator.</span>
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <span class="keywordflow">return</span> argv;
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 
<a name="l00125"></a><a class="code" href="classlibdap_1_1rvalue.html#1f7ffe31e84d0d159cc600c258de3ec2">00125</a> <a class="code" href="classlibdap_1_1rvalue.html#3acc265c79602bb7e146df157d9f48aa">rvalue::rvalue</a>(<a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *bt): d_value(bt), d_func(0), d_args(0)
<a name="l00126"></a>00126 {}
<a name="l00127"></a>00127 
<a name="l00128"></a><a class="code" href="classlibdap_1_1rvalue.html#0a1f39c8e9995897a94bceab61e21539">00128</a> <a class="code" href="classlibdap_1_1rvalue.html#3acc265c79602bb7e146df157d9f48aa">rvalue::rvalue</a>(btp_func f, vector&lt;rvalue *&gt; *a) : d_value(0), d_func(f), d_args(a)
<a name="l00129"></a>00129 {}
<a name="l00130"></a>00130 
<a name="l00131"></a><a class="code" href="classlibdap_1_1rvalue.html#3acc265c79602bb7e146df157d9f48aa">00131</a> <a class="code" href="classlibdap_1_1rvalue.html#3acc265c79602bb7e146df157d9f48aa">rvalue::rvalue</a>(): d_value(0), d_func(0), d_args(0)
<a name="l00132"></a>00132 {}
<a name="l00133"></a>00133 
<a name="l00134"></a><a class="code" href="classlibdap_1_1rvalue.html#d5accfe3e920e31b930e2598db0cbfbf">00134</a> <a class="code" href="classlibdap_1_1rvalue.html#d5accfe3e920e31b930e2598db0cbfbf">rvalue::~rvalue</a>()
<a name="l00135"></a>00135 {
<a name="l00136"></a>00136     <span class="comment">// Deleting the BaseType pointers in value and args is a bad idea since</span>
<a name="l00137"></a>00137     <span class="comment">// those might be variables in the dataset. The DDS dtor will take care</span>
<a name="l00138"></a>00138     <span class="comment">// of deleting them. The constants wrapped in BaseType objects should be</span>
<a name="l00139"></a>00139     <span class="comment">// pushed on the list of CE-allocated temp objects which the CE frees.</span>
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 <span class="keywordtype">string</span>
<a name="l00143"></a><a class="code" href="classlibdap_1_1rvalue.html#ed22027f3256cd2595761cc8e1f8588f">00143</a> <a class="code" href="classlibdap_1_1rvalue.html#ed22027f3256cd2595761cc8e1f8588f">rvalue::value_name</a>()
<a name="l00144"></a>00144 {
<a name="l00145"></a>00145     assert(d_value);
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     <span class="keywordflow">return</span> d_value-&gt;<a class="code" href="classlibdap_1_1BaseType.html#0a0c6b5d57813607dc06255b8e0b9bdc" title="Returns the name of the class instance.">name</a>();
<a name="l00148"></a>00148 }
<a name="l00149"></a>00149 
<a name="l00159"></a>00159 <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *
<a name="l00160"></a><a class="code" href="classlibdap_1_1rvalue.html#5ec1d2d66b162aa9ad82b658e70ce7de">00160</a> <a class="code" href="classlibdap_1_1rvalue.html#5ec1d2d66b162aa9ad82b658e70ce7de">rvalue::bvalue</a>(<a class="code" href="classlibdap_1_1DDS.html">DDS</a> &amp;dds)
<a name="l00161"></a>00161 {
<a name="l00162"></a>00162     <span class="keywordflow">if</span> (d_value) {        <span class="comment">// i.e., if this RValue is a BaseType</span>
<a name="l00163"></a>00163         <span class="keywordflow">return</span> d_value;
<a name="l00164"></a>00164     }
<a name="l00165"></a>00165     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d_func) {
<a name="l00166"></a>00166         <span class="comment">// If func is true, then args must be set. See the constructor.</span>
<a name="l00167"></a>00167         <span class="comment">// 12/23/04 jhrg</span>
<a name="l00168"></a>00168         <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#928b16257bc714971a2a3c91cb42d882">build_btp_args</a>(d_args, dds);
<a name="l00169"></a>00169 <span class="preprocessor">#if 0</span>
<a name="l00170"></a>00170 <span class="preprocessor"></span>        <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *ret_val = (*d_func)(d_args-&gt;size(), argv, dds);
<a name="l00171"></a>00171 <span class="preprocessor">#endif</span>
<a name="l00172"></a>00172 <span class="preprocessor"></span>        <a class="code" href="classlibdap_1_1BaseType.html" title="The basic data type for the DODS DAP types.">BaseType</a> *ret_val;
<a name="l00173"></a>00173         (*d_func)(d_args-&gt;size(), argv, dds, &amp;ret_val);
<a name="l00174"></a>00174         <span class="keyword">delete</span>[] argv;
<a name="l00175"></a>00175         <span class="keywordflow">return</span> ret_val;
<a name="l00176"></a>00176     }
<a name="l00177"></a>00177     <span class="keywordflow">else</span> {
<a name="l00178"></a>00178         <span class="keywordflow">return</span> 0;
<a name="l00179"></a>00179     }
<a name="l00180"></a>00180 }
<a name="l00181"></a>00181 
<a name="l00182"></a>00182 } <span class="comment">// namespace libdap</span>
<a name="l00183"></a>00183 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 7 19:57:07 2009 for libdap++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>