37 {
"$Id: DDS.cc 24370 2011-03-28 16:21:32Z jimg $"
41 #include <sys/types.h>
111 DDS::duplicate(
const DDS &dds)
113 DBG(cerr <<
"Entering DDS::duplicate... " <<endl);
115 d_filename = dds.d_filename;
116 d_container_name = dds.d_container_name;
117 d_timeout = dds.d_timeout;
120 d_factory = dds.d_factory;
121 d_container = dds.d_container;
122 d_dap_major = dds.d_dap_major;
123 d_dap_minor = dds.d_dap_minor;
125 d_keywords = dds.d_keywords;
127 DDS &dds_tmp =
const_cast<DDS &
>(dds);
147 : d_factory(factory), name(n), d_container(0),
148 d_dap_major(2), d_dap_minor(0),
149 d_request_xml_base(
""), d_timeout(0), d_keywords()
151 DBG(cerr <<
"Building a DDS with client major/minor: "
152 << d_dap_major <<
"." << d_dap_minor << endl);
158 DBG(cerr <<
"Entering DDS(const DDS &rhs) ..." << endl);
160 DBG(cerr <<
" bye." << endl);
166 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
168 delete btp ; btp = 0;
175 DBG(cerr <<
"Entering DDS::operator= ..." << endl);
181 DBG(cerr <<
" bye." << endl);
207 throw InternalErr(__FILE__, __LINE__,
"Error transferring attributes: working on a container in dds, but not das" ) ;
215 (*var)->transfer_attributes(top_level);
223 while (at_cont_p != top_level->
attr_end()) {
228 && (*at_cont_p)->attributes->is_global_attribute()) {
229 DBG(cerr << (*at_cont_p)->name <<
" is a global attribute." << endl);
303 if (d_dap_minor >= 0) {
305 oss << d_dap_major <<
"." << d_dap_minor;
306 d_dap_version = oss.str();
315 if (d_dap_major >= 0) {
317 oss << d_dap_major <<
"." << d_dap_minor;
318 d_dap_version = oss.str();
331 istringstream iss(version_string);
333 int major = -1, minor = -1;
335 if (!iss.eof() && !iss.fail())
337 if (!iss.eof() && !iss.fail())
339 if (!iss.eof() && !iss.fail())
342 DBG(cerr <<
"Major: " << major <<
", dot: " << dot <<
", Minor: " << minor << endl);
344 if (major == -1 || minor == -1)
345 throw Error(
"Could not parse the client dap (XDAP-Accept header) value");
348 d_dap_version = version_string;
365 int minor = (d-major)*10;
367 DBG(cerr <<
"Major: " << major <<
", Minor: " << minor << endl);
370 oss << major <<
"." << minor;
371 d_dap_version = oss.str();
389 return d_container_name;
417 d_container_name = cn;
440 "Trying to add a BaseType object with a NULL pointer.");
442 DBG2(cerr <<
"In DDS::add_var(), bt's address is: " << bt << endl);
445 DBG2(cerr <<
"In DDS::add_var(), btp's address is: " << btp << endl);
475 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
476 if ((*i)->name() == n) {
492 if (i != vars.end()) {
508 for (
Vars_iter i_tmp = i1; i_tmp != i2; i_tmp++) {
551 return d_container->
var( name,
false, s ) ;
563 DBG(cerr <<
"DDS::leaf_match: Looking for " << n << endl);
565 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
567 DBG(cerr <<
"DDS::leaf_match: Looking for " << n <<
" in: " << btp->
name() << endl);
569 if (btp->
name() == n) {
570 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
577 DBG(cerr <<
"Found " << n <<
" in: " << btp->
name() << endl);
581 #if STRUCTURE_ARRAY_SYNTAX_OLD
586 DBG(cerr <<
"Found " << n <<
" in: " << btp->
var()->
name() << endl);
599 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
601 DBG2(cerr <<
"Looking for " << name <<
" in: " << btp << endl);
603 if (btp->
name() == name) {
604 DBG2(cerr <<
"Found " << name <<
" in: " << btp << endl);
609 string::size_type dot_pos = name.find(
".");
610 if (dot_pos != string::npos) {
611 string aggregate = name.substr(0, dot_pos);
612 string field = name.substr(dot_pos + 1);
616 DBG2(cerr <<
"Descending into " << agg_ptr->
name() << endl);
617 return agg_ptr->
var(field,
true, s);
638 return vars.rbegin();
659 return vars.begin() + i;
668 return *(vars.begin() + i);
690 d_timeout = alarm(0);
712 for (
Vars_iter i = vars.begin(); i != vars.end(); i++) {
714 dynamic_cast<Sequence&>(**i).set_leaf_sequence();
716 dynamic_cast<Structure&>(**i).set_leaf_sequence();
724 FILE *in = fopen(fname.c_str(),
"r");
746 FILE *in = fdopen(_dup(fd),
"r");
748 FILE *in = fdopen(dup(fd),
"r");
752 throw InternalErr(__FILE__, __LINE__,
"Could not access file.");
775 throw InternalErr(__FILE__, __LINE__,
"Null input stream.");
783 bool status =
ddsparse((
void *) & arg) == 0;
787 DBG2(cout <<
"Status from parser: " << status << endl);
791 if (!status || !arg.
status()) {
806 fwrite(oss.str().c_str(), oss.str().length(), 1, out);
808 fprintf(out,
"Dataset {\n") ;
810 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
811 (*i)->print_decl(out) ;
814 fprintf(out,
"} %s;\n",
id2www(name).c_str()) ;
825 out <<
"Dataset {\n" ;
827 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
828 (*i)->print_decl(out) ;
831 out <<
"} " <<
id2www(name) <<
";\n" ;
850 fprintf(out,
"Dataset {\n") ;
852 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
856 (*i)->print_decl(out,
" ",
true,
false,
true) ;
859 fprintf(out,
"} %s;\n",
id2www(name).c_str()) ;
878 out <<
"Dataset {\n" ;
880 for (
Vars_citer i = vars.begin(); i != vars.end(); i++) {
884 (*i)->print_decl(out,
" ",
true,
false,
true) ;
887 out <<
"} " <<
id2www(name) <<
";\n" ;
893 class VariablePrintXML :
public unary_function<BaseType *, void>
898 VariablePrintXML(FILE *out,
bool constrained)
899 : d_out(out), d_constrained(constrained)
901 void operator()(BaseType *bt)
903 bt->print_xml(d_out,
" ", d_constrained);
920 fprintf(out,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
922 fprintf(out,
"<Dataset name=\"%s\"\n",
id2xml(name).c_str());
924 fprintf(out,
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
926 fprintf(out,
"method=\"FILE*\"\n");
935 fprintf(out,
"xsi:schemaLocation=\"%s %s\">\n\n",
940 fprintf(out,
"xsi:schemaLocation=\"%s %s\">\n\n",
956 fprintf(out,
" <dataBLOB href=\"\"/>\n");
958 else if (!blob.empty()
961 fprintf(out,
" <blob href=\"cid:%s\"/>\n", blob.c_str());
965 fprintf(out,
"</Dataset>\n");
969 class VariablePrintXMLStrm :
public unary_function<BaseType *, void>
974 VariablePrintXMLStrm(ostream &out,
bool constrained)
975 : d_out(out), d_constrained(constrained)
977 void operator()(BaseType *bt)
979 bt->print_xml(d_out,
" ", d_constrained);
996 out <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ;
998 out <<
"<Dataset name=\"" <<
id2xml(name) <<
"\"\n" ;
1000 out <<
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" ;
1008 out <<
"xmlns:grddl=\"http://www.w3.org/2003/g/data-view#\"\n";
1012 out <<
"xmlns:dap=\"" << c_dap32_namespace <<
"\"\n" ;
1028 out <<
"xsi:schemaLocation=\"" << c_dap20_namespace
1032 d_attr.
print_xml(out,
" ", constrained);
1045 out <<
" <dataBLOB href=\"\"/>\n" ;
1047 else if (!blob.empty()
1050 out <<
" <blob href=\"cid:" << blob <<
"\"/>\n";
1053 out <<
"</Dataset>\n" ;
1076 cerr <<
"A dataset must have a name" << endl;
1085 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1086 if (!(*i)->check_semantics(msg,
true))
1122 DBG2(cerr <<
"DDS::mark: Looking for " << n << endl);
1126 DBG2(cerr <<
"Could not find variable " << n << endl);
1132 DBG2(cerr <<
"DDS::mark: Set variable " << variable->
name()
1133 <<
" (a " << variable->
type_name() <<
")" << endl);
1139 while (!s->empty()) {
1140 s->top()->BaseType::set_send_p(state);
1142 DBG2(cerr <<
"DDS::mark: Set variable " << s->top()->name()
1143 <<
" (a " << s->top()->type_name() <<
")" << endl);
1144 string parent_name = (s->top()->get_parent()) ? s->top()->get_parent()->name():
"none";
1145 string parent_type = (s->top()->get_parent()) ? s->top()->get_parent()->type_name():
"none";
1146 DBG2(cerr <<
"DDS::mark: Parent variable " << parent_name <<
" (a " << parent_type <<
")" << endl);
1164 for (
Vars_iter i = vars.begin(); i != vars.end(); i++)
1165 (*i)->set_send_p(state);
1179 << (
void *)
this <<
")" << endl ;
1197 for (; i != ie; i++) {
std::vector< entry * >::iterator Attr_iter
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="")
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
BaseType * leaf_match(const string &name, BaseType::btp_stack *s=0)
Vars_iter var_begin()
Return an iterator to the first variable.
virtual void print_xml(FILE *out, string pad=" ", bool constrained=false)
string get_request_xml_base() const
Get the URL that will return this DDS/DDX/DataThing.
string id2xml(string in, const string ¬_allowed)
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 void add_var(BaseType *bt, Part part=nil)
Holds a structure (aggregate) type.
Vars_riter var_rend()
Return a reverse iterator.
virtual string get_name() const
Get the name of this attribute table.
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...
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=0)
Returns a pointer to a member of a constructor class.
string type_name() const
Returns the type of the class instance as a string.
int get_dap_major() const
Get the DAP major version as sent by the client.
virtual void set_send_p(bool state)
void mark_all(bool state)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
const string c_xml_namespace
std::vector< BaseType * >::iterator Vars_iter
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)
virtual void del_var(const string &name)
void dds_switch_to_buffer(void *new_buffer)
string name() const
Returns the name of the class instance.
virtual AttrTable * get_top_level_attributes()
Returns the top most set of attributes.
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
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)
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.
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
virtual void dump(ostream &strm) const
dumps information about this object
Vars_riter var_rbegin()
Return a reverse iterator.
Hold attribute data for a DAP2 dataset.
const string grddl_transformation_dap32
int get_dap_minor() const
Get the DAP minor version as sent by the client.
A class for error processing.
string get_dataset_name() const
void duplicate(const DDS &dds)
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 void dump(ostream &strm) const
dumps information about this object
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 ...