43#include "D4BaseTypeFactory.h"
44#include "D4Attributes.h"
63 d_factory = dmr.d_factory;
66 d_filename = dmr.d_filename;
68 d_dap_major = dmr.d_dap_major;
69 d_dap_minor = dmr.d_dap_minor;
70 d_dap_version = dmr.d_dap_version;
72 d_dmr_version = dmr.d_dmr_version;
74 d_request_xml_base = dmr.d_request_xml_base;
76 d_namespace = dmr.d_namespace;
78 d_max_response_size_kb = dmr.d_max_response_size_kb;
80 d_ce_empty = dmr.d_ce_empty;
85 DBG(cerr <<
"dmr.d_root: " << dmr.d_root << endl);
86 DBG(cerr <<
"d_root (from ptr_dup(): " << d_root << endl);
102 : d_factory(factory), d_name(name)
127 : d_factory(factory), d_name(dds.get_dataset_name()), d_filename(dds.filename())
147DMR::operator=(
const DMR &rhs)
179 DBG(cerr << __func__ <<
"() - Transforming top level variable: " <<
180 " (" << (*i)->type_name() <<
":'" << (*i)->name() <<
"':"<<(
void *)(*i) <<
181 ") (root:"<< root_grp <<
")"<< endl; );
182 (*i)->transform_to_dap4(root_grp, root_grp);
183 DBG(cerr << __func__ <<
"() - top level variable: '" <<
184 (*i)->name() <<
"' (type:" << (*i)->type_name() <<
") Transformed"<< endl; );
187 DBG(cerr << __func__ <<
"() - Skipping variable: " <<
188 d4_var->
type_name() <<
" " << d4_var->
name() <<
" because a variable with" <<
189 " this name already exists in the root group." << endl; );
215 DBG( cerr << __func__ <<
"() - BEGIN" << endl);
225 unique_ptr< vector<BaseType *>> top_vars(
root()->transform_to_dap2(&(dds->
get_attr_table())));
226 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
231 for (vector<BaseType *>::iterator i = top_vars->begin(), e = top_vars->end(); i != e; i++) {
236 DBG( cerr << __func__ <<
"() - END" << endl);
251 if (!d_root) d_root =
static_cast<D4Group*
>(d_factory->
NewVariable(dods_group_c,
"/"));
263 istringstream iss(v);
265 int major = -1, minor = -1;
267 if (!iss.eof() && !iss.fail())
269 if (!iss.eof() && !iss.fail())
271 if (!iss.eof() && !iss.fail())
274 if (major == -1 || minor == -1 or dot !=
'.')
275 throw InternalErr(__FILE__, __LINE__,
"Could not parse dap version. Value given: " + v);
286 switch (d_dap_major) {
288 d_namespace = c_dap40_namespace;
341 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar*)
"Dataset") < 0)
342 throw InternalErr(__FILE__, __LINE__,
"Could not write Dataset element");
344 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xmlns", (
const xmlChar*)
get_namespace().c_str()) < 0)
345 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xmlns");
348 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"xml:base",
350 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for xml:base");
353 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dapVersion", (
const xmlChar*)dap_version().c_str()) < 0)
354 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
356 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"dmrVersion", (
const xmlChar*)dmr_version().c_str()) < 0)
357 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for dapVersion");
359 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar*)
"name", (
const xmlChar*)
name().c_str()) < 0)
360 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
364 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
365 throw InternalErr(__FILE__, __LINE__,
"Could not end the top-level Group element");
380 has_dap4 |= var->is_dap4_projected(inventory);
382 for(
const auto grp:
root()->groups()){
383 has_dap4 |= grp->is_dap4_projected(inventory);
399 strm << DapIndent::LMarg <<
"DMR::dump - ("
400 << (
void *)
this <<
")" << endl ;
401 DapIndent::Indent() ;
402 strm << DapIndent::LMarg <<
"factory: " << (
void *)d_factory << endl ;
403 strm << DapIndent::LMarg <<
"name: " << d_name << endl ;
404 strm << DapIndent::LMarg <<
"filename: " << d_filename << endl ;
405 strm << DapIndent::LMarg <<
"protocol major: " << d_dap_major << endl;
406 strm << DapIndent::LMarg <<
"protocol minor: " << d_dap_minor << endl;
408 DapIndent::UnIndent() ;
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 string name() const
Returns the name of the class instance.
virtual D4Attributes * attributes()
BaseType * var(const string &name, bool exact_match=true, btp_stack *s=nullptr) override
btp_stack no longer needed; use back pointers (BaseType::get_parent())
const vector< BaseType * > & variables() const
void transform_to_dap4(AttrTable &at)
copy attributes from DAP2 to DAP4
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
virtual BaseType * NewVariable(Type t, const string &name) const
void print_dap4(XMLWriter &xml, bool constrained=false) override
uint64_t request_size_kb(bool constrained)
Get the estimated size of a response in kilobytes.
BaseType * ptr_duplicate() override
long request_size(bool constrained)
std::vector< BaseType * > * transform_to_dap2(AttrTable *parent_attr_table) override
Transform the D4Group's variables to DAP2 variables.
void add_var_nocopy(BaseType *bt)
Adds the variable to the DDS.
virtual AttrTable & get_attr_table()
BaseTypeFactory * set_factory(BaseTypeFactory *factory)
string get_dataset_name() const
Vars_iter var_end()
Return an iterator.
void dump(std::ostream &strm) const override
dumps information about this object
virtual DDS * getDDS()
Build a DDS from a DMR.
void m_duplicate(const DMR &dmr)
Copy the contents of the given DMR into this one. This is defined because the we perform a deep copy ...
void set_dap_version(const std::string &version_string)
std::string get_namespace() const
Get the namespace associated with the DMR.
std::string request_xml_base() const
Get the URL that will return this DMR.
virtual bool is_dap4_projected(std::vector< string > &inventory)
Scans the inventory of projected variables and their attributes for projected DAP4 types....
virtual void build_using_dds(DDS &dds)
long request_size(bool constrained)
Get the estimated response size, in kilobytes.
uint64_t request_size_kb(bool constrained)
Compute the estimated response size, in kilobytes.
std::string filename() const
void print_dap4(XMLWriter &xml, bool constrained=false)
libdap base object for common functionality of libdap objects
A class for software fault reporting.
top level DAP object to house generic methods