PassiveArray.cc

Go to the documentation of this file.
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2002,2003 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 // (c) COPYRIGHT URI/MIT 1994-1999
00027 // Please read the full copyright statement in the file COPYRIGHT_URI.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 
00032 // Implementation for PassiveArray.
00033 //
00034 // pwest 11/04/03
00035 
00036 
00037 #include "config.h"
00038 
00039 static char rcsid[] not_used =
00040     {"$Id: PassiveArray.cc 16088 2007-03-28 21:42:19Z jimg $"
00041     };
00042 
00043 #include <stdlib.h>
00044 
00045 #include "PassiveArray.h"
00046 #include "InternalErr.h"
00047 #include "debug.h"
00048 
00049 
00050 using std::cerr;
00051 using std::endl;
00052 
00061 PassiveArray::PassiveArray(const string &n, BaseType *v)
00062         : Array(n, v),
00063         _byte_val(0),
00064         _int16_val(0),
00065         _int32_val(0),
00066         _uint16_val(0),
00067         _uint32_val(0),
00068         _float32_val(0),
00069         _float64_val(0),
00070         _str_val(0)
00071 {}
00072 
00073 PassiveArray::PassiveArray(const PassiveArray &copy_from)
00074         : Array(copy_from),
00075         _byte_val(0),
00076         _int16_val(0),
00077         _int32_val(0),
00078         _uint16_val(0),
00079         _uint32_val(0),
00080         _float32_val(0),
00081         _float64_val(0),
00082         _str_val(0)
00083 {}
00084 
00085 BaseType *
00086 PassiveArray::ptr_duplicate()
00087 {
00088     return new PassiveArray(*this);
00089 }
00090 
00091 PassiveArray::~PassiveArray()
00092 {
00093     DBG(cerr << "~PassiveArray" << endl);
00094 }
00095 
00096 PassiveArray &
00097 PassiveArray::operator=(const PassiveArray &rhs)
00098 {
00099     if (this == &rhs)
00100         return *this;
00101 
00102     _duplicate(rhs) ;
00103 
00104     return *this;
00105 }
00106 
00107 bool
00108 PassiveArray::read(const string &)
00109 {
00110     if (!read_p()) {
00111         switch (var()->type()) {
00112         case dods_byte_c: {
00113                 val2buf((void *) _byte_val);
00114                 delete [] _byte_val;
00115                 _byte_val = 0 ;
00116             }
00117             break;
00118         case dods_int16_c: {
00119                 val2buf((void *) _int16_val);
00120                 delete [] _int16_val;
00121                 _int16_val = 0 ;
00122             }
00123             break;
00124         case dods_uint16_c: {
00125                 val2buf((void *) _uint16_val);
00126                 delete [] _uint16_val;
00127                 _uint16_val = 0 ;
00128             }
00129             break;
00130         case dods_int32_c: {
00131                 val2buf((void *) _int32_val);
00132                 delete [] _int32_val;
00133                 _int32_val = 0 ;
00134             }
00135             break;
00136         case dods_uint32_c: {
00137                 val2buf((void *) _uint32_val);
00138                 delete [] _uint32_val;
00139                 _uint32_val = 0 ;
00140             }
00141             break;
00142         case dods_float32_c: {
00143                 val2buf((void *) _float32_val);
00144                 delete [] _float32_val;
00145                 _float32_val = 0 ;
00146             }
00147             break;
00148         case dods_float64_c: {
00149                 val2buf((void *) _float64_val);
00150                 delete [] _float64_val;
00151                 _float64_val = 0 ;
00152             }
00153             break;
00154         case dods_str_c: {
00155                 val2buf((void*) _str_val);
00156                 delete [] _str_val;
00157                 _str_val = 0 ;
00158             }
00159             break;
00160         default: {
00161                 cerr << __FILE__ << ":"
00162                 << __LINE__ << "Unsupported DAP2 data type"
00163                 << endl;
00164                 throw InternalErr("Unsupported DAP2 data type");
00165             }
00166             break;
00167         }
00168         set_read_p(true);
00169     }
00170 
00171     return true ;
00172 }
00173 
00174 bool
00175 PassiveArray::set_value(dods_byte *val, int sz)
00176 {
00177     if (var()->type() == dods_byte_c && val) {
00178         _byte_val = new dods_byte[sz] ;
00179         for (register int t = 0; t < sz; t++) {
00180             _byte_val[t] = val[t] ;
00181         }
00182         set_length(sz) ;
00183         return read("") ;
00184     }
00185     else {
00186         return false;
00187     }
00188 }
00189 
00190 bool
00191 PassiveArray::set_value(dods_int16 *val, int sz)
00192 {
00193     if (var()->type() == dods_int16_c && val) {
00194         _int16_val = new dods_int16[sz] ;
00195         for (register int t = 0; t < sz; t++) {
00196             _int16_val[t] = val[t] ;
00197         }
00198         set_length(sz) ;
00199         return read("") ;
00200     }
00201     else {
00202         return false;
00203     }
00204 }
00205 
00206 bool
00207 PassiveArray::set_value(dods_int32 *val, int sz)
00208 {
00209     if (var()->type() == dods_int32_c && val) {
00210         _int32_val = new dods_int32[sz] ;
00211         for (register int t = 0; t < sz; t++) {
00212             _int32_val[t] = val[t] ;
00213         }
00214         set_length(sz) ;
00215         return read("") ;
00216     }
00217     else {
00218         return false;
00219     }
00220 }
00221 
00222 bool
00223 PassiveArray::set_value(dods_uint16 *val, int sz)
00224 {
00225     if (var()->type() == dods_uint16_c && val) {
00226         _uint16_val = new dods_uint16[sz] ;
00227         for (register int t = 0; t < sz; t++) {
00228             _uint16_val[t] = val[t] ;
00229         }
00230         set_length(sz) ;
00231         return read("") ;
00232     }
00233     else {
00234         return false;
00235     }
00236 }
00237 
00238 bool
00239 PassiveArray::set_value(dods_uint32 *val, int sz)
00240 {
00241     if (var()->type() == dods_uint32_c && val) {
00242         _uint32_val = new dods_uint32[sz] ;
00243         for (register int t = 0; t < sz; t++) {
00244             _uint32_val[t] = val[t] ;
00245         }
00246         set_length(sz) ;
00247         return read("") ;
00248     }
00249     else {
00250         return false;
00251     }
00252 }
00253 
00254 bool
00255 PassiveArray::set_value(dods_float32 *val, int sz)
00256 {
00257     if (var()->type() == dods_float32_c && val) {
00258         _float32_val = new dods_float32[sz] ;
00259         for (register int t = 0; t < sz; t++) {
00260             _float32_val[t] = val[t] ;
00261         }
00262         set_length(sz) ;
00263         return read("") ;
00264     }
00265     else {
00266         return false;
00267     }
00268 }
00269 
00270 bool
00271 PassiveArray::set_value(dods_float64 *val, int sz)
00272 {
00273     if (var()->type() == dods_float64_c && val) {
00274         _float64_val = new dods_float64[sz] ;
00275         for (register int t = 0; t < sz; t++) {
00276             _float64_val[t] = val[t] ;
00277         }
00278         set_length(sz) ;
00279         return read("") ;
00280     }
00281     else {
00282         return false;
00283     }
00284 }
00285 
00286 bool
00287 PassiveArray::set_value(string *val, int sz)
00288 {
00289     if (var()->type() == dods_str_c && val) {
00290         _str_val = new string[sz] ;
00291         for (register int t = 0; t < sz; t++) {
00292             _str_val[t] = val[t] ;
00293         }
00294         set_length(sz) ;
00295         return read("") ;
00296     }
00297     else {
00298         return false;
00299     }
00300 }

Generated on Wed Jun 27 12:56:39 2007 for libdap++ by  doxygen 1.4.7