Sophie

Sophie

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

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++: XDRUtils.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>XDRUtils.cc</h1><a href="XDRUtils_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// XDRUtils.cc</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="comment">// -*- mode: c++; c-basic-offset:4 -*-</span>
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="comment">// This file is part of libdap, A C++ implementation of the OPeNDAP Data</span>
<a name="l00006"></a>00006 <span class="comment">// Access Protocol.</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">// Copyright (c) 2002,2003 OPeNDAP, Inc.</span>
<a name="l00009"></a>00009 <span class="comment">// Author: Patrick West &lt;pwest@ucar.edu&gt;</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// This library is free software; you can redistribute it and/or</span>
<a name="l00012"></a>00012 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>
<a name="l00013"></a>00013 <span class="comment">// License as published by the Free Software Foundation; either</span>
<a name="l00014"></a>00014 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016 <span class="comment">// This library is distributed in the hope that it will be useful,</span>
<a name="l00017"></a>00017 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00018"></a>00018 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00019"></a>00019 <span class="comment">// Lesser General Public License for more details.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>
<a name="l00022"></a>00022 <span class="comment">// License along with this library; if not, write to the Free Software</span>
<a name="l00023"></a>00023 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
<a name="l00024"></a>00024 <span class="comment">//</span>
<a name="l00025"></a>00025 <span class="comment">// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment">// (c) COPYRIGHT URI/MIT 1994-1999</span>
<a name="l00028"></a>00028 <span class="comment">// Please read the full copyright statement in the file COPYRIGHT_URI.</span>
<a name="l00029"></a>00029 <span class="comment">//</span>
<a name="l00030"></a>00030 <span class="comment">// Authors:</span>
<a name="l00031"></a>00031 <span class="comment">//      pwest       Patrick West &lt;pwest@ucar.edu&gt;</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="XDRUtils_8h.html">XDRUtils.h</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="Str_8h.html">Str.h</a>"</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="keyword">using namespace </span>libdap ;
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="comment">// This function is used to allocate memory for, and initialize, a new XDR</span>
<a name="l00040"></a>00040 <span class="comment">// pointer. It sets the stream associated with the (XDR *) to STREAM.</span>
<a name="l00041"></a>00041 <span class="comment">//</span>
<a name="l00042"></a>00042 <span class="comment">// NB: STREAM is not one of the C++/libg++ iostream classes; it is a (FILE</span>
<a name="l00043"></a>00043 <span class="comment">// *).</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="comment">//  These func's moved to xdrutil_ppc.* under the PPC as explained there</span>
<a name="l00046"></a>00046 <span class="preprocessor">#ifndef __POWERPC__</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>XDR *
<a name="l00048"></a><a class="code" href="XDRUtils_8h.html#91ac75a1d242fbf5bbced463513f9942">00048</a> <a class="code" href="XDRUtils_8cc.html#91ac75a1d242fbf5bbced463513f9942">new_xdrstdio</a>(FILE *stream, <span class="keyword">enum</span> xdr_op xop)
<a name="l00049"></a>00049 {
<a name="l00050"></a>00050     XDR *xdr = <span class="keyword">new</span> XDR;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052     xdrstdio_create(xdr, stream, xop);
<a name="l00053"></a>00053 
<a name="l00054"></a>00054     <span class="keywordflow">return</span> xdr;
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057 XDR *
<a name="l00058"></a><a class="code" href="XDRUtils_8h.html#5119ada259093237ead7048f81ccf5ce">00058</a> <a class="code" href="XDRUtils_8cc.html#5119ada259093237ead7048f81ccf5ce">set_xdrstdio</a>(XDR *xdr, FILE *stream, <span class="keyword">enum</span> xdr_op xop)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060     xdrstdio_create(xdr, stream, xop);
<a name="l00061"></a>00061 
<a name="l00062"></a>00062     <span class="keywordflow">return</span> xdr;
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064 
<a name="l00065"></a>00065 <span class="comment">// Delete an XDR pointer allocated using the above function. Do not close the</span>
<a name="l00066"></a>00066 <span class="comment">// associated FILE pointer.</span>
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 <span class="keywordtype">void</span>
<a name="l00069"></a><a class="code" href="XDRUtils_8h.html#cd1ce82fd29bbb21c05044ecbfc1c8a6">00069</a> <a class="code" href="XDRUtils_8cc.html#cd1ce82fd29bbb21c05044ecbfc1c8a6">delete_xdrstdio</a>(XDR *xdr)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071     xdr_destroy(xdr);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="keyword">delete</span> xdr; xdr = 0;
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span>
<a name="l00077"></a>00077 <span class="comment">// This function is used to en/decode Str and Url type variables. It is</span>
<a name="l00078"></a>00078 <span class="comment">// defined as extern C since it is passed via function pointers to routines</span>
<a name="l00079"></a>00079 <span class="comment">// in the xdr library where it is executed. This function is defined so</span>
<a name="l00080"></a>00080 <span class="comment">// that Str and Url have an en/decoder which takes exactly two arguments: an</span>
<a name="l00081"></a>00081 <span class="comment">// XDR * and a string reference.</span>
<a name="l00082"></a>00082 <span class="comment">//</span>
<a name="l00083"></a>00083 <span class="comment">// NB: this function is *not* used for arrays (i.e., it is not the function</span>
<a name="l00084"></a>00084 <span class="comment">// referenced by BaseType's _xdr_coder field when the object is a Str or Url.</span>
<a name="l00085"></a>00085 <span class="comment">// Also note that \e max_str_len is an obese number but that really does not</span>
<a name="l00086"></a>00086 <span class="comment">// matter; xdr_string() would never actually allocate that much memory unless</span>
<a name="l00087"></a>00087 <span class="comment">// a string that size was sent from the server.</span>
<a name="l00088"></a>00088 <span class="comment">// Returns: XDR's bool_t; TRUE if no errors are detected, FALSE</span>
<a name="l00089"></a>00089 <span class="comment">// otherwise. The formal parameter BUF is modified as a side effect.</span>
<a name="l00090"></a>00090 
<a name="l00091"></a>00091 <span class="keyword">extern</span> <span class="stringliteral">"C"</span> bool_t
<a name="l00092"></a><a class="code" href="XDRUtils_8h.html#78664a2078747f93e8c0dd79c12e21c2">00092</a> <a class="code" href="XDRUtils_8cc.html#78664a2078747f93e8c0dd79c12e21c2">xdr_str</a>(XDR *xdrs, <span class="keywordtype">string</span> &amp;buf)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094     <a class="code" href="debug_8h.html#32adf79142f0a426b5e782fb7cd4cad3">DBG</a>(cerr &lt;&lt; <span class="stringliteral">"In xdr_str, xdrs: "</span> &lt;&lt; xdrs &lt;&lt; endl);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="keywordflow">switch</span> (xdrs-&gt;x_op) {
<a name="l00097"></a>00097     <span class="keywordflow">case</span> XDR_ENCODE: { <span class="comment">// BUF is a pointer to a (string *)</span>
<a name="l00098"></a>00098             <span class="keyword">const</span> <span class="keywordtype">char</span> *out_tmp = buf.c_str();
<a name="l00099"></a>00099 
<a name="l00100"></a>00100             <span class="keywordflow">return</span> xdr_string(xdrs, (<span class="keywordtype">char</span> **)&amp;out_tmp, <a class="code" href="namespacelibdap.html#ef2455580bf5deab23e48dd319ae059f">max_str_len</a>);
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     <span class="keywordflow">case</span> XDR_DECODE: {
<a name="l00104"></a>00104             <span class="keywordtype">char</span> *in_tmp = NULL;
<a name="l00105"></a>00105 
<a name="l00106"></a>00106             bool_t stat = xdr_string(xdrs, &amp;in_tmp, <a class="code" href="namespacelibdap.html#ef2455580bf5deab23e48dd319ae059f">max_str_len</a>);
<a name="l00107"></a>00107             <span class="keywordflow">if</span> (!stat)
<a name="l00108"></a>00108                 <span class="keywordflow">return</span> stat;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110             buf = in_tmp;
<a name="l00111"></a>00111 
<a name="l00112"></a>00112             free(in_tmp);
<a name="l00113"></a>00113 
<a name="l00114"></a>00114             <span class="keywordflow">return</span> stat;
<a name="l00115"></a>00115         }
<a name="l00116"></a>00116 
<a name="l00117"></a>00117     <span class="keywordflow">default</span>:
<a name="l00118"></a>00118         <span class="keywordflow">return</span> 0;
<a name="l00119"></a>00119     }
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 
<a name="l00122"></a>00122 <span class="keyword">namespace </span>libdap {
<a name="l00123"></a>00123 
<a name="l00142"></a>00142 xdrproc_t
<a name="l00143"></a><a class="code" href="classlibdap_1_1XDRUtils.html#af9f4be9a9e22a10416bfbad841751a3">00143</a> <a class="code" href="classlibdap_1_1XDRUtils.html#af9f4be9a9e22a10416bfbad841751a3" title="Returns a function used to encode elements of an array.">XDRUtils::xdr_coder</a>( <span class="keyword">const</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6" title="Identifies the data type.">Type</a> &amp;t )
<a name="l00144"></a>00144 {
<a name="l00145"></a>00145     <span class="keywordflow">switch</span>( t )
<a name="l00146"></a>00146     {
<a name="l00147"></a>00147         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e637d71c620b71be06fbe667e7cb0e80e4">dods_int16_c</a>:
<a name="l00148"></a>00148             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#24654f59366e8cc041ba72d75f6308f9">XDR_INT16</a> ;
<a name="l00149"></a>00149             break ;
<a name="l00150"></a>00150         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e684188f64695716d84cefe910704ca094">dods_uint16_c</a>:
<a name="l00151"></a>00151             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#0440bdd8dcee5f8ff49fd6c689278da8">XDR_UINT16</a> ;
<a name="l00152"></a>00152             break ;
<a name="l00153"></a>00153         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6524bfec434d0a8f82e06bfcc02c9a6b1">dods_int32_c</a>:
<a name="l00154"></a>00154             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#3e24e0d58a6330f2d3dcb3df5f66e59f">XDR_INT32</a> ;
<a name="l00155"></a>00155             break ;
<a name="l00156"></a>00156         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e61bdeca4f415a3372b83448efd87bff83">dods_uint32_c</a>:
<a name="l00157"></a>00157             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#680769c94a1d529e0b8d81e0f1b7d4b4">XDR_UINT32</a> ;
<a name="l00158"></a>00158             break ;
<a name="l00159"></a>00159         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e66aff4fd17f027d0f0c41423e2f74a68c">dods_float32_c</a>:
<a name="l00160"></a>00160             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#b8a7fc1ec52006fbcd2c3da947d5f8e6">XDR_FLOAT32</a> ;
<a name="l00161"></a>00161             break ;
<a name="l00162"></a>00162         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e68661c9f9c227fe59b7f5563f20e145d6">dods_float64_c</a>:
<a name="l00163"></a>00163             <span class="keywordflow">return</span> (xdrproc_t)<a class="code" href="config_8h.html#3c125ee3b49360f8eaea7948b24154a7">XDR_FLOAT64</a> ;
<a name="l00164"></a>00164             break ;
<a name="l00165"></a>00165         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e64124790aeab42dbcd3d5303dea15b200">dods_byte_c</a>:
<a name="l00166"></a>00166         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6d620cef0bf41edebd4ee802071192a79">dods_str_c</a>:
<a name="l00167"></a>00167         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e664d653d09a50d6d17537c43ed217f665">dods_url_c</a>:
<a name="l00168"></a>00168         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6da8f5df7bb2bc72327fcd16af811562f">dods_array_c</a>:
<a name="l00169"></a>00169         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6d93eb0a69e67742f061966ce594b9a6c">dods_structure_c</a>:
<a name="l00170"></a>00170         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e60b03707324b30e4a7c88876bbf8c7e3b">dods_sequence_c</a>:
<a name="l00171"></a>00171         <span class="keywordflow">case</span> <a class="code" href="namespacelibdap.html#05ca706d4539ae7b750c3bc7066ab6e6c41525d2e860d3bcff641eb1fdba41d2">dods_grid_c</a>:
<a name="l00172"></a>00172         <span class="keywordflow">default</span>:
<a name="l00173"></a>00173             <span class="keywordflow">return</span> NULL ;
<a name="l00174"></a>00174             break ;
<a name="l00175"></a>00175     }
<a name="l00176"></a>00176 }
<a name="l00177"></a>00177 
<a name="l00178"></a>00178 } <span class="comment">// namespace libdap</span>
<a name="l00179"></a>00179 
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 7 19:57:08 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>