34#include <libdap/BaseType.h>
35#include <libdap/Str.h>
37#include <libdap/Error.h>
38#include <libdap/DDS.h>
39#include <libdap/DMR.h>
40#include <libdap/D4Group.h>
41#include <libdap/D4RValue.h>
43#include <libdap/debug.h>
44#include <libdap/util.h>
48#include "BindNameFunction.h"
54string bind_name_info =
55 string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
56 +
"<function name=\"make_array\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#bind_name\">\n"
72void function_bind_name_dap2(
int argc, BaseType * argv[], DDS &dds, BaseType **btpp)
74 DBG(cerr <<
"function_bind_name_dap2() - BEGIN" << endl);
77 Str *response =
new Str(
"info");
78 response->set_value(bind_name_info);
84 if (argc != 2)
throw Error(malformed_expr,
"bind_name(name,variable) requires two arguments.");
86 DBG(cerr <<
"function_bind_name_dap2() - Processing argv[0]" << endl);
88 string name = extract_string_argument(argv[0]);
89 DBG(cerr <<
"function_bind_name_dap2() - New name: " << name << endl);
91 DBG(cerr <<
"function_bind_name_dap2() - Processing argv[1]" << endl);
92 BaseType *sourceVar = argv[1];
93 DBG(cerr <<
"function_bind_name_dap2() - Source variable: " <<
94 sourceVar->type_name() <<
" " << sourceVar->name() << endl);
105 if (dds.var(name))
throw Error(malformed_expr,
"The name '" + name +
"' is already in use.");
111 if (dds.var(sourceVar->name())) {
112 DBG(cerr <<
"function_bind_name_dap2() - Copying existing variable in DDS: " << sourceVar->name() << endl);
113 *btpp = sourceVar->ptr_duplicate();
114 if (!(*btpp)->read_p()) {
116 (*btpp)->set_read_p(
true);
118 (*btpp)->set_send_p(
true);
119 (*btpp)->set_name(name);
122 DBG(cerr <<
"function_bind_name_dap2 - Using passed variable: " << sourceVar->name() << endl);
123 sourceVar->set_name(name);
125 } DBG(cerr <<
"function_bind_name_dap2() - END" << endl);
130BaseType *function_bind_name_dap4(D4RValueList *args, DMR &dmr)
133 if (args == 0 || args->size() == 0) {
134 Str *response =
new Str(
"info");
135 response->set_value(bind_name_info);
141 DBG(cerr <<
"args->size() = " << args->size() << endl);
142 if (args->size() != 2)
throw Error(malformed_expr,
"bind_shape(shape,variable) requires two arguments.");
144 string name = extract_string_argument(args->get_rvalue(0)->value(dmr));
146 DBG(cerr <<
"function_bind_name_dap4() - New name: " << name << endl);
148 BaseType *sourceVar = args->get_rvalue(1)->value(dmr);
149 DBG(cerr <<
"function_bind_name_dap4() - Source variable: " << sourceVar->type_name() <<
" " << sourceVar->name() << endl);
162 if (dmr.root()->var(name))
163 throw Error(malformed_expr,
"The name '" + name +
"' is already in use.");
169 if (dmr.root()->var(sourceVar->name())) {
170 DBG(cerr <<
"function_bind_name_dap4() - Copying existing variable in DMR: " << sourceVar->name() << endl);
171 resultVar = sourceVar->ptr_duplicate();
172 if (!resultVar->read_p()) {
174 resultVar->set_read_p(
true);
176 resultVar->set_send_p(
true);
177 resultVar->set_name(name);
180 DBG(cerr <<
"function_bind_name_dap4 - Using passed variable: " << sourceVar->name() << endl);
181 resultVar = sourceVar;
182 resultVar->set_name(name);