RValue.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 1996-1999
00027 // Please read the full copyright statement in the file COPYRIGHT_URI.
00028 //
00029 // Authors:
00030 //      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
00031 
00032 // This file contains mfuncs defined for struct rvalue (see expr.h) that
00033 // *cannot* be included in that struct's declaration because their
00034 // definitions must follow *both* rvalue's and func_rvalue's declarations.
00035 // jhrg 3/4/96
00036 
00037 #include "config.h"
00038 
00039 static char rcsid[] not_used =
00040     {"$Id: RValue.cc 16088 2007-03-28 21:42:19Z jimg $"
00041     };
00042 
00043 #include <assert.h>
00044 
00045 #include <iostream>
00046 
00047 #include "BaseType.h"
00048 #include "expr.h"
00049 #include "RValue.h"
00050 #include "DDS.h"
00051 
00052 using namespace std;
00053 
00054 rvalue_list *
00055 make_rvalue_list(rvalue *rv)
00056 {
00057     assert(rv);
00058 
00059     rvalue_list *rvals = new rvalue_list;
00060 
00061     return append_rvalue_list(rvals, rv);
00062 }
00063 
00064 // Given a rvalue_list pointer RVALS and a value pointer VAL, make a variable
00065 // to hold VAL and append that variable to the list RVALS.
00066 //
00067 // Returns: A pointer to the updated rvalue_list.
00068 
00069 rvalue_list *
00070 append_rvalue_list(rvalue_list *rvals, rvalue *rv)
00071 {
00072     assert(rvals);
00073     assert(rv);
00074 
00075     rvals->push_back(rv);
00076 
00077     return rvals;
00078 }
00079 
00080 
00092 BaseType **
00093 build_btp_args(rvalue_list *args, DDS &dds, const string &dataset)
00094 {
00095     int argc = 0;
00096 
00097     if (args)
00098         argc = args->size();
00099 
00100     // Add space for a null terminator
00101     BaseType **argv = new BaseType *[argc + 1];
00102 
00103     int index = 0;
00104     if (argc) {
00105         for (rvalue::Args_iter i = args->begin(); i != args->end(); i++) {
00106             argv[index++] = (*i)->bvalue(dataset, dds);
00107         }
00108     }
00109 
00110     argv[index] = 0;            // Add the null terminator.
00111 
00112     return argv;
00113 }
00114 
00115 rvalue::rvalue(BaseType *bt): d_value(bt), d_func(0), d_args(0)
00116 {}
00117 
00118 rvalue::rvalue(btp_func f, vector<rvalue *> *a) : d_value(0), d_func(f), d_args(a)
00119 {}
00120 
00121 rvalue::rvalue(): d_value(0), d_func(0), d_args(0)
00122 {}
00123 
00124 rvalue::~rvalue()
00125 {
00126     // Deleting the BaseType pointers in value and args is a bad idea since
00127     // those might be variables in the dataset. The DDS dtor will take care
00128     // of deleting them. The constants wrapped in BaseType objects should be
00129     // pushed on the list of CE-allocated temp objects which the CE frees.
00130 }
00131 
00132 string
00133 rvalue::value_name()
00134 {
00135     assert(d_value);
00136 
00137     return d_value->name();
00138 }
00139 
00149 BaseType *
00150 rvalue::bvalue(const string &dataset, DDS &dds)
00151 {
00152     if (d_value) {        // i.e., if this RValue is a BaseType
00153         return d_value;
00154     }
00155     else if (d_func) {
00156         // If func is true, then args must be set. See the constructor.
00157         // 12/23/04 jhrg
00158         BaseType **argv = build_btp_args(d_args, dds, dataset);
00159         BaseType *ret_val = (*d_func)(d_args->size(), argv, dds, dataset);
00160         delete[] argv;
00161         return ret_val;
00162     }
00163     else {
00164         return 0;
00165     }
00166 }
00167 

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