84const string c_xml_xsi =
"http://www.w3.org/2001/XMLSchema-instance";
118 DBG(cerr <<
"Entering DDS::duplicate... " << endl);
120 d_factory = dds.d_factory;
123 d_filename = dds.d_filename;
124 d_container_name = dds.d_container_name;
125 d_container = dds.d_container;
127 d_dap_major = dds.d_dap_major;
128 d_dap_minor = dds.d_dap_minor;
130 d_dap_version = dds.d_dap_version;
131 d_request_xml_base = dds.d_request_xml_base;
132 d_namespace = dds.d_namespace;
136 DDS &dds_tmp =
const_cast<DDS &
>(dds);
143 d_timeout = dds.d_timeout;
145 d_max_response_size_kb = dds.d_max_response_size_kb;
161 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0), d_request_xml_base(
""), d_timeout(0),
162 d_max_response_size_kb(0) {
163 DBG(cerr <<
"Building a DDS for the default version (2.0)" << endl);
186 : d_factory(factory), d_name(name), d_container_name(
""), d_container(0), d_request_xml_base(
""), d_timeout(0),
187 d_max_response_size_kb(0) {
188 DBG(cerr <<
"Building a DDS for version: " <<
version << endl);
197 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
199 DBG(cerr <<
" bye." << endl);
204 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
238 "Error transferring attributes: working on a container in dds, but not das");
244 (*i)->transfer_attributes(top);
250 if ((*i)->type ==
Attr_container && (*i)->attributes->is_global_attribute()) {
254 d_attr.append_container(at, at->
get_name());
303 if (d_dap_minor >= 0) {
305 oss << d_dap_major <<
"." << d_dap_minor;
306 d_dap_version = oss.str();
316 if (d_dap_major >= 0) {
318 oss << d_dap_major <<
"." << d_dap_minor;
319 d_dap_version = oss.str();
329 istringstream iss(v);
331 int major = -1, minor = -1;
333 if (!iss.eof() && !iss.fail())
335 if (!iss.eof() && !iss.fail())
337 if (!iss.eof() && !iss.fail())
340 if (major == -1 || minor == -1 or dot !=
'.')
341 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
352 switch (d_dap_major) {
363 throw InternalErr(__FILE__, __LINE__,
"Unknown DAP version.");
375 int major = floor(d);
376 int minor = (d - major) * 10;
378 DBG(cerr <<
"Major: " << major <<
", Minor: " << minor << endl);
381 oss << major <<
"." << minor;
418 d_container_name = cn;
440 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
443 w += (*i)->width(constrained);
445 w += (*i)->width(constrained);
464 uint64_t req_size = 0;
465 for (
auto &btp : vars) {
468 req_size += btp->width_ll(constrained);
470 req_size += btp->width_ll(constrained);
474 return req_size / 1024;
484 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
486 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
489 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
493 d_container->add_var(bt);
506 throw InternalErr(__FILE__, __LINE__,
"Trying to add a BaseType object with a NULL pointer.");
508 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
511 d_container->add_var_nocopy(bt);
525 d_container->del_var(n);
529 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
530 if ((*i)->name() == n) {
545 if (i != vars.end()) {
560 for (
Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
599 return d_container->var(name,
false, s);
609 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
611 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
613 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
615 if (btp->
name() == n) {
616 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
623 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
627#if STRUCTURE_ARRAY_SYNTAX_OLD
632 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->d_name() << endl);
643 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
645 DBG2(cerr <<
"Looking for " << d_name <<
" in: " << btp << endl);
647 if (btp->
name() == name) {
648 DBG2(cerr <<
"Found " << d_name <<
" in: " << btp << endl);
653 string::size_type dot_pos = name.find(
".");
654 if (dot_pos != string::npos) {
655 string aggregate = name.substr(0, dot_pos);
656 string field = name.substr(dot_pos + 1);
660 DBG2(cerr <<
"Descending into " << agg_ptr->
name() << endl);
661 return agg_ptr->
var(field,
true, s);
688#if USE_LOCAL_TIMEOUT_SCHEME
696#if USE_LOCAL_TIMEOUT_SCHEME
715#if USE_LOCAL_TIMEOUT_SCHEME
722#if USE_LOCAL_TIMEOUT_SCHEME
731 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
741 FILE *in = fopen(fname.c_str(),
"r");
759 int new_fd = _dup(fd);
761 int new_fd = dup(fd);
765 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
766 FILE *in = fdopen(new_fd,
"r");
769 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
789 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
801 DBG2(cout <<
"Status from parser: " << status << endl);
805 if (!status || !arg.
status()) {
815 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
820 out <<
"Dataset {\n";
822 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
823 (*i)->print_decl(out);
826 out <<
"} " <<
id2www(d_name) <<
";\n";
864 Grid *grid =
dynamic_cast<Grid *
>(btp);
886static string four_spaces =
" ";
897 Grid *grid =
dynamic_cast<Grid *
>(bt);
908 mIter != grid->
map_end(); ++mIter) {
915 attr_table.
print(out, indent + four_spaces);
918 for (; i != e; i++) {
928 attr_table.
print(out, indent + four_spaces);
931 out << indent <<
"}" << endl;
943 unique_ptr<DAS> das(
get_das());
968static string get_unique_top_level_global_container_name(
DAS *das) {
983 throw InternalErr(__FILE__, __LINE__,
"Cannot add top-level attributes to the DAS");
1001 Grid *grid =
dynamic_cast<Grid *
>(bt);
1008 string childName = arrayAT.
get_name(atIter);
1031 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
1035 das->
add_table((*i)->name(), childAttrT);
1040 unique_ptr<AttrTable> global(
new AttrTable);
1045 if (d_attr.get_attr_table(i)) {
1049 global->append_attr(d_attr.get_name(i), d_attr.get_type(i), d_attr.get_attr_vector(i), (*i)->is_utf8_str);
1054 if (global->get_size() > 0) {
1055 das->
add_table(get_unique_top_level_global_container_name(das),
1074 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
1088 out <<
"Dataset {\n";
1090 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
1094 (*i)->print_decl(out,
" ",
true,
false,
true);
1097 out <<
"} " <<
id2www(d_name) <<
";\n";
1116 fwrite(oss.str().data(), 1, oss.str().length(), out);
1153 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Dataset") < 0)
1154 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
1155 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)d_name.c_str()) < 0)
1156 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1157 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:xsi",
1158 (
const xmlChar *)
"http://www.w3.org/2001/XMLSchema-instance") < 0)
1159 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1161 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xsi:schemaLocation",
1163 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1165 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:grddl",
1166 (
const xmlChar *)
"http://www.w3.org/2003/g/data-view#") < 0)
1167 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:grddl");
1169 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"grddl:transformation",
1171 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:transformation");
1173 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns",
1175 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1176 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:dap",
1178 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:dap");
1180 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"dapVersion", (
const xmlChar *)
"3.2") < 0)
1181 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1184 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:xml",
1186 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1188 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xml:base",
1190 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1194 d_attr.print_xml_writer(xml);
1198 var->print_xml_writer(xml, constrained);
1201 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"blob") < 0)
1202 throw InternalErr(__FILE__, __LINE__,
"Could not write blob element");
1203 string cid =
"cid:" + blob;
1204 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"href", (
const xmlChar *)cid.c_str()) < 0)
1205 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for d_name");
1206 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1207 throw InternalErr(__FILE__, __LINE__,
"Could not end blob element");
1209 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1210 throw InternalErr(__FILE__, __LINE__,
"Could not end Dataset element");
1230 throw InternalErr(__FILE__, __LINE__,
"Tried to print a DMR with DAP major version less than 4");
1235 if (xmlTextWriterStartElement(xml.
get_writer(), (
const xmlChar *)
"Group") < 0)
1236 throw InternalErr(__FILE__, __LINE__,
"Could not write Group element");
1238 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:xml",
1240 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xml");
1242 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns:xsi",
1243 (
const xmlChar *)
c_xml_xsi.c_str()) < 0)
1244 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:xsi");
1246 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xsi:schemaLocation",
1248 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns:schemaLocation");
1250 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xmlns",
1252 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
1254 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"dapVersion",
1256 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1258 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"dmrVersion",
1260 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
1263 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"xml:base",
1265 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
1268 if (xmlTextWriterWriteAttribute(xml.
get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)d_name.c_str()) < 0)
1269 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
1272 d_attr.print_xml_writer(xml);
1276 var->print_xml_writer(xml, constrained);
1279 if (xmlTextWriterEndElement(xml.
get_writer()) < 0)
1280 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
1303 cerr <<
"A dataset must have a d_name" << endl;
1312 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1313 if (!(*i)->check_semantics(msg,
true))
1345 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1354 DBG2(cerr <<
"DDS::mark: Set variable " << variable->d_name() <<
" (a " << variable->
type_name() <<
")" << endl);
1360 while (!s->empty()) {
1361 s->top()->BaseType::set_send_p(state);
1363 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->d_name() <<
" (a " << s->top()->type_name() <<
")"
1366 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name() :
"none";
1367 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name() :
"none";
1368 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1382 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1383 (*i)->set_send_p(state);
1392 bool has_dap4 = d_attr.has_dap4_types(
"/", inventory);
1394 has_dap4 |=
var->is_dap4_projected(inventory);
1407 strm <<
DapIndent::LMarg <<
"DDS::dump - (" << (
void *)
this <<
")" << endl;
1425 for (; i != ie; i++) {
const string c_default_dap20_schema_location
void * dds_buffer(FILE *fp)
const string TOP_LEVEL_ATTRS_CONTAINER_NAME
const string c_dap_20_n_sl
const string c_default_dap32_schema_location
const string grddl_transformation_dap32
int ddsparse(libdap::parser_arg *arg)
const string c_dap_32_n_sl
const string c_dap_40_n_sl
const string c_dap32_namespace
const string c_dap20_namespace
const string c_default_dap40_schema_location
void dds_switch_to_buffer(void *new_buffer)
void dds_delete_buffer(void *buffer)
const string c_xml_namespace
const string c_dap40_namespace
#define malformed_expr
(400)
#define cannot_read_file
(400)
A multidimensional array of identical data types.
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual Attr_iter attr_end()
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
virtual Attr_iter attr_begin()
virtual string get_name() const
Get the name of this attribute table.
virtual void print(FILE *out, string pad=" ", bool dereference=false)
Prints the attribute table.
virtual unsigned int get_size() const
Get the number of entries in this attribute table.
std::vector< entry * >::iterator Attr_iter
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
The basic data type for the DODS DAP types.
virtual string type_name() const
Returns the type of the class instance as a string.
virtual AttrTable & get_attr_table()
virtual string name() const
Returns the name of the class instance.
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual void set_send_p(bool state)
virtual BaseType * ptr_duplicate()=0
stack< BaseType * > btp_stack
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
std::vector< BaseType * >::iterator Vars_iter
Hold attribute data for a DAP2 dataset.
virtual AttrTable * get_top_level_attributes()
Returns the top most set of attributes.
virtual AttrTable * add_table(const string &name, AttrTable *at)
Adds a variable attribute table to the DAS or the current dataset container attribute table.
AttrTable * get_table(AttrTable::Attr_iter &i)
Returns the referenced variable attribute table.
virtual string container_name() const
Returns the name of the current attribute container when multiple files used to build this DAS.
void set_dataset_name(const string &n)
void set_dap_major(int p)
void mark_all(bool state)
void print_dmr(ostream &out, bool constrained)
Print the DAP4 DMR object using a DDS.
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
virtual AttrTable & get_attr_table()
std::vector< BaseType * >::const_iterator Vars_citer
string get_dap_version() const
uint64_t get_request_size_kb(bool constrained)
Get the estimated response size in kilobytes.
virtual void transfer_attributes(DAS *das)
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
void set_dap_minor(int p)
string get_namespace() const
Get the namespace associated with the DDS - likely set only by DDX responses.
int num_var()
Returns the number of variables in the DDS.
void print(FILE *out)
Print the entire DDS to the specified file.
int get_request_size(bool constrained)
Get the estimated response size in bytes.
bool is_dap4_projected(std::vector< string > &inventory)
string get_dataset_name() const
BaseType * exact_match(const string &name, BaseType::btp_stack *s=0)
void del_var(const string &n)
Removes a variable from the DDS.
void parse(string fname)
Parse a DDS from a file with the given d_name.
BaseType * var(const string &n, BaseType::btp_stack &s)
void print_xml(FILE *out, bool constrained, const string &blob="")
void insert_var(Vars_iter i, BaseType *ptr)
Insert a variable before the referenced element.
void duplicate(const DDS &dds)
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
DDS(BaseTypeFactory *factory, const string &name="")
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
DAS * get_das()
Get a DAS object.
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
string get_dmr_version() const
void insert_var_nocopy(Vars_iter i, BaseType *ptr)
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
Vars_iter var_end()
Return an iterator.
int get_dap_major() const
Get the DAP major version as sent by the client.
const vector< BaseType * > & variables() const
void set_dap_version(const string &version_string="2.0")
void add_var(BaseType *bt)
Adds a copy of the variable to the DDS. Using the ptr_duplicate() method, perform a deep copy on the ...
std::vector< BaseType * >::iterator Vars_iter
void print_xml_writer(ostream &out, bool constrained, const string &blob="")
DDS & operator=(const DDS &rhs)
void print_das(ostream &out)
write the DAS response given the attribute information in the DDS
virtual void dump(ostream &strm) const
dumps information about this object
static ostream & LMarg(ostream &strm)
libdap base object for common functionality of libdap objects
A class for error processing.
Holds the Grid data type.
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
std::vector< BaseType * >::iterator Map_iter
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required.
A class for software fault reporting.
virtual void set_leaf_sequence(int lvl=1)
Mark the Sequence which holds the leaf elements.
Holds a structure (aggregate) type.
virtual void set_leaf_sequence(int level=1)
Traverse Structure, set Sequence leaf nodes.
xmlTextWriterPtr get_writer() const
top level DAP object to house generic methods
bool has_dap2_attributes(AttrTable &a)
string www2id(const string &in, const string &escape, const string &except)
const string c_dap40_namespace
string add_space_encoding(const string &s)
string AttrType_to_String(const AttrType at)
void print_var_das(ostream &out, BaseType *bt, string indent="")
void fillConstructorAttrTable(AttrTable *at, BaseType *bt)
Recursive helper function for Building DAS entries for Constructor types.
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
string id2www(string in, const string &allowable)
Pass parameters by reference to a parser.