37 {
"$Id: DDS.cc 23577 2010-09-14 22:20:18Z jimg $" 41 #include <sys/types.h> 110 DDS::duplicate(
const DDS &dds)
112 DBG(cerr <<
"Entering DDS::duplicate... " <<endl);
114 d_filename = dds.d_filename;
115 d_container_name = dds.d_container_name;
116 d_timeout = dds.d_timeout;
119 d_factory = dds.d_factory;
120 d_container = dds.d_container;
121 d_dap_major = dds.d_dap_major;
122 d_dap_minor = dds.d_dap_minor;
124 DDS &dds_tmp =
const_cast<DDS &
>(dds);
144 : d_factory(factory), name(n), d_container(0), d_dap_major(2),
146 d_request_xml_base(
""), d_timeout(0)
148 DBG(cerr <<
"Building a DDS with client major/minor: " 149 << d_dap_major <<
"." << d_dap_minor << endl);
155 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
157 DBG(cerr <<
" bye." << endl);
163 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
165 delete btp ; btp = 0;
172 DBG(cerr <<
"Entering DDS::operator= ..." << endl);
178 DBG(cerr <<
" bye." << endl);
202 string::size_type i = source->
name.find(
"_dim_");
203 if (i != string::npos && (btp =
var(source->
name.substr(0, i)))) {
210 int n = atoi(source->
name.substr(i + 5).c_str());
211 DBG(cerr <<
"Found a Grid (" << btp->
name() <<
") and " 212 << source->
name.substr(i) <<
", extracted n: " << n << endl);
230 throw InternalErr(__FILE__, __LINE__,
"DDS::find_matching_container; expected 'source' to be a container.");
235 if ((btp =
var(source->
name))) {
237 *dest_variable = btp;
240 else if ((btp = find_hdf4_dimension_attribute_home(source))) {
244 DBG(cerr <<
"Found a Grid, assigning to the map" << endl);
245 *dest_variable = btp;
249 string::size_type i = source->
name.find(
"_dim_");
250 string ext = source->
name.substr(i + 1);
251 *dest_variable = btp;
300 string err = (string)
"Error transferring attributes: " 301 +
"working on container in dds, but not das" ;
311 while (das_i != das_e) {
312 DBG(cerr <<
"Working on the '" << (*das_i)->name <<
"' container." 318 AttrTable *dest = find_matching_container(*das_i, &dest_variable);
322 while (source_p != source->
attr_end()) {
323 DBG(cerr <<
"Working on the '" << (*source_p)->name <<
"' attribute" 376 throw InternalErr(__FILE__, __LINE__,
"Error transferring attributes: working on a container in dds, but not das" ) ;
384 (*var)->transfer_attributes(top_level);
392 while (at_cont_p != top_level->
attr_end()) {
397 && (*at_cont_p)->attributes->is_global_attribute()) {
398 DBG(cerr << (*at_cont_p)->name <<
" is a global attribute." << endl);
414 cerr <<
"making a new sub containter for it" << endl;
421 cerr <<
"now copying its contents to the new container" << endl;
425 while (at_p != at->attr_end()) {
429 dest->
append_attr(at->get_name(at_p), at->get_type(at_p), at->get_attr_vector(at_p));
496 istringstream iss(version_string);
498 int major = -1, minor = -1;
504 DBG(cerr <<
"Major: " << major <<
", dot: " << dot <<
", Minor: " << minor << endl);
506 if (major == -1 || minor == -1)
507 throw Error(
"Could not parse the client dap (XDAP-Accept header) value");
525 return d_container_name;
553 d_container_name = cn;
576 "Trying to add a BaseType object with a NULL pointer.");
578 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
581 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
611 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
612 if ((*i)->name() == n) {
628 if (i != vars.end()) {
644 for (
Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
687 return d_container->
var( name,
false, s ) ;
699 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
701 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
703 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
705 if (btp->
name() == n) {
706 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
713 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
717 #if STRUCTURE_ARRAY_SYNTAX_OLD 722 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->
name() << endl);
735 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
737 DBG2(cerr <<
"Looking for " << name <<
" in: " << btp << endl);
739 if (btp->
name() == name) {
740 DBG2(cerr <<
"Found " << name <<
" in: " << btp << endl);
745 string::size_type dot_pos = name.find(
".");
746 if (dot_pos != string::npos) {
747 string aggregate = name.substr(0, dot_pos);
748 string field = name.substr(dot_pos + 1);
752 DBG2(cerr <<
"Descending into " << agg_ptr->
name() << endl);
753 return agg_ptr->
var(field,
true, s);
774 return vars.rbegin();
795 return vars.begin() + i;
804 return *(vars.begin() + i);
826 d_timeout = alarm(0);
848 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
850 dynamic_cast<Sequence&>(**i).set_leaf_sequence();
852 dynamic_cast<Structure&>(**i).set_leaf_sequence();
860 FILE *in = fopen(fname.c_str(),
"r");
882 FILE *in = fdopen(_dup(fd),
"r");
884 FILE *in = fdopen(dup(fd),
"r");
888 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
911 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
919 bool status =
ddsparse((
void *) & arg) == 0;
923 DBG2(cout <<
"Status from parser: " << status << endl);
927 if (!status || !arg.status()) {
942 fwrite(oss.str().c_str(), oss.str().length(), 1, out);
944 fprintf(out,
"Dataset {\n") ;
946 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
947 (*i)->print_decl(out) ;
950 fprintf(out,
"} %s;\n",
id2www(name).c_str()) ;
961 out <<
"Dataset {\n" ;
963 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
964 (*i)->print_decl(out) ;
967 out <<
"} " <<
id2www(name) <<
";\n" ;
986 fprintf(out,
"Dataset {\n") ;
988 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
992 (*i)->print_decl(out,
" ",
true,
false,
true) ;
995 fprintf(out,
"} %s;\n",
id2www(name).c_str()) ;
1014 out <<
"Dataset {\n" ;
1016 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
1020 (*i)->print_decl(out,
" ",
true,
false,
true) ;
1023 out <<
"} " <<
id2www(name) <<
";\n" ;
1029 class VariablePrintXML :
public unary_function<BaseType *, void>
1034 VariablePrintXML(FILE *out,
bool constrained)
1035 : d_out(out), d_constrained(constrained)
1039 bt->
print_xml(d_out,
" ", d_constrained);
1056 fprintf(out,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1058 fprintf(out,
"<Dataset name=\"%s\"\n",
id2xml(name).c_str());
1060 fprintf(out,
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
1062 fprintf(out,
"method=\"FILE*\"\n");
1071 fprintf(out,
"xsi:schemaLocation=\"%s %s\">\n\n",
1076 fprintf(out,
"xsi:schemaLocation=\"%s %s\">\n\n",
1081 d_attr.print_xml(out,
" ", constrained);
1092 fprintf(out,
" <dataBLOB href=\"\"/>\n");
1094 else if (!blob.empty()
1097 fprintf(out,
" <blob href=\"cid:%s\"/>\n", blob.c_str());
1101 fprintf(out,
"</Dataset>\n");
1105 class VariablePrintXMLStrm :
public unary_function<BaseType *, void>
1110 VariablePrintXMLStrm(ostream &out,
bool constrained)
1111 : d_out(out), d_constrained(constrained)
1115 bt->
print_xml(d_out,
" ", d_constrained);
1132 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ;
1134 out <<
"<Dataset name=\"" <<
id2xml(name) <<
"\"\n" ;
1136 out <<
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" ;
1144 out <<
"xmlns:grddl=\"http://www.w3.org/2003/g/data-view#\"\n";
1148 out <<
"xmlns:dap=\"" << c_dap32_namespace <<
"\"\n" ;
1164 out <<
"xsi:schemaLocation=\"" << c_dap20_namespace
1168 d_attr.print_xml(out,
" ", constrained);
1181 out <<
" <dataBLOB href=\"\"/>\n" ;
1183 else if (!blob.empty()
1186 out <<
" <blob href=\"cid:" << blob <<
"\"/>\n";
1189 out <<
"</Dataset>\n" ;
1212 cerr <<
"A dataset must have a name" << endl;
1221 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1222 if (!(*i)->check_semantics(msg,
true))
1258 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1262 DBG2(cerr <<
"Could not find variable " << n << endl);
1268 DBG2(cerr <<
"DDS::mark: Set variable " << variable->
name()
1269 <<
" (a " << variable->
type_name() <<
")" << endl);
1275 while (!s->empty()) {
1276 s->top()->BaseType::set_send_p(state);
1278 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->name()
1279 <<
" (a " << s->top()->type_name() <<
")" << endl);
1280 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name():
"none";
1281 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name():
"none";
1282 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1300 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1301 (*i)->set_send_p(state);
1315 << (
void *)
this <<
")" << endl ;
1333 for (; i != ie; i++) {
std::vector< entry * >::iterator Attr_iter
string name() const
Returns the name of the class instance.
const string c_dap32_namespace
void print(FILE *out)
Print the entire DDS to the specified file.
virtual Attr_iter attr_end()
DDS(BaseTypeFactory *factory, const string &n="")
virtual void print_xml(FILE *out, string space=" ", bool constrained=false)
bool unique_names(vector< BaseType *> l, const string &var_name, const string &type_name, string &msg)
const string c_dap20_namespace
Contains the attributes for a dataset.
void dds_delete_buffer(void *buffer)
virtual BaseType * var(const string &name, bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
Vars_iter get_vars_iter(int i)
Get an iterator.
const string c_default_dap32_schema_location
virtual string get_type(const string &name)
Get the type name of an attribute within this attribute table.
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
Vars_iter var_begin()
Return an iterator to the first variable.
virtual string get_name() const
Get the name of this attribute table.
string id2xml(string in, const string ¬_allowed)
virtual BaseType * get_parent()
BaseType * var(const string &n, BaseType::btp_stack &s)
virtual void transfer_attributes(DAS *das)
void print_xml(FILE *out, bool constrained, const string &blob="")
std::vector< BaseType * >::const_iterator Vars_citer
virtual AttrTable * find_container(const string &target)
Find an attribute with a given name.
virtual void add_var(BaseType *bt, Part part=nil)
Holds a structure (aggregate) type.
Vars_riter var_rend()
Return a reverse iterator.
string get_dataset_name() const
int num_var()
Returns the number of variables in the DDS.
std::vector< BaseType * >::reverse_iterator Vars_riter
stack< BaseType * > btp_stack
bool mark(const string &name, bool state)
Mark the send_p flag of the named variable to state.
A class for software fault reporting.
virtual bool is_vector_type()
Returns true if the instance is a vector (i.e., array) type variable.
void parse(string fname)
Parse a DDS from a file with the given name.
DDS & operator=(const DDS &rhs)
virtual bool is_constructor_type()
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable...
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
virtual void set_send_p(bool state)
virtual void transfer_attributes(AttrTable *at_container)
void mark_all(bool state)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
Type type() const
Returns the type of the class instance.
const string c_xml_namespace
std::vector< BaseType * >::iterator Vars_iter
Holds the Grid data type.
virtual AttrTable & get_attr_table()
BaseType * get_var_index(int i)
Get a variable.
bool check_semantics(bool all=false)
Check the semantics of each of the variables represented in the DDS.
void * dds_buffer(FILE *fp)
void set_dap_version(const string &version_string)
int get_dap_major() const
Get the DAP major version as sent by the client.
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
virtual void del_var(const string &name)
void dds_switch_to_buffer(void *new_buffer)
virtual AttrTable * get_top_level_attributes()
Returns the top most set of attributes.
virtual void dump(ostream &strm) const
dumps information about this object
virtual Attr_iter attr_begin()
virtual BaseType * ptr_duplicate()=0
string www2id(const string &in, const string &escape, const string &except)
Vars_iter var_end()
Return an iterator.
BaseType * exact_match(const string &name, BaseType::btp_stack *s=0)
void tag_nested_sequences()
Traverse DDS, set Sequence leaf nodes.
static ostream & LMarg(ostream &strm)
const string c_default_dap20_schema_location
virtual AttrTable & get_attr_table()
void ddsrestart(FILE *yyin)
void set_dap_minor(int p)
Set the DAP minor version (typically using info from the client)
void set_dataset_name(const string &n)
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
The basic data type for the DODS DAP types.
libdap base object for common functionality of libdap objects
Pass parameters by reference to a parser.
void del_var(const string &n)
Removes a variable from the DDS.
string type_name() const
Returns the type of the class instance as a string.
Vars_riter var_rbegin()
Return a reverse iterator.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
Hold attribute data for a DAP2 dataset.
const string grddl_transformation_dap32
A class for error processing.
void duplicate(const DDS &dds)
int get_dap_minor() const
Get the DAP minor version as sent by the client.
void set_dap_major(int p)
Set the DAP major version (typically using info from the client)
void print_constrained(FILE *out)
Print a constrained DDS to the specified file.
virtual string container_name()
Returns the name of the current attribute container when multiple files used to build this DAS...
string id2www(string in, const string &allowable)
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 ...