38 "$Id: AttrTable.cc 23473 2010-09-01 20:33:22Z mjohnson $";
94 if (s2 ==
"container")
96 else if (s2 ==
"byte")
98 else if (s2 ==
"int16")
100 else if (s2 ==
"uint16")
102 else if (s2 ==
"int32")
104 else if (s2 ==
"uint32")
106 else if (s2 ==
"float32")
108 else if (s2 ==
"float64")
110 else if (s2 ==
"string")
112 else if (s2 ==
"url")
114 else if (s2 ==
"otherxml")
125 d_is_global_attribute = at.d_is_global_attribute;
134 for (; i != ie; ++i) {
137 attr_map.push_back(e);
156 , d_is_global_attribute(true)
167 void AttrTable::delete_attr_table()
169 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
178 DBG(cerr <<
"Entering ~AttrTable (" <<
this <<
")" << endl);
179 delete_attr_table();
DBG(cerr <<
"Exiting ~AttrTable" << endl);
202 return attr_map.size();
240 const string &attribute)
242 DBG(cerr <<
"Entering AttrTable::append_attr" << endl);
243 string lname =
www2id(name);
250 throw Error(
string(
"An attribute called `") + name
251 +
string(
"' already exists but is of a different type"));
252 if (iter != attr_map.end() && (
get_type(iter) ==
"Container"))
253 throw Error(
string(
"An attribute called `") + name
254 +
string(
"' already exists but is a container."));
256 if (iter != attr_map.end()) {
257 (*iter)->attr->push_back(attribute);
258 return (*iter)->attr->size();
266 e->
attr =
new vector<string>;
267 e->
attr->push_back(attribute);
269 attr_map.push_back(e);
271 return e->
attr->size();
295 vector<string> *values)
297 DBG(cerr <<
"Entering AttrTable::append_attr(..., vector)" << endl);
298 string lname =
www2id(name);
305 throw Error(
string(
"An attribute called `") + name
306 +
string(
"' already exists but is of a different type"));
307 if (iter != attr_map.end() && (
get_type(iter) ==
"Container"))
308 throw Error(
string(
"An attribute called `") + name
309 +
string(
"' already exists but is a container."));
311 if (iter != attr_map.end()) {
312 vector<string>::iterator i = values->begin();
313 while (i != values->end())
314 (*iter)->attr->push_back(*i++);
316 return (*iter)->attr->size();
324 e->
attr =
new vector<string>(*values);
326 attr_map.push_back(e);
328 return e->
attr->size();
350 delete new_at; new_at = 0;
371 string lname =
www2id(name);
374 throw Error(
string(
"There already exists a container called `")
375 + name +
string(
"' in this attribute table."));
376 DBG(cerr <<
"Setting appended attribute container name to: " 386 attr_map.push_back(e);
410 string::size_type dotpos = target.rfind(
'.');
411 if (dotpos != string::npos) {
412 string container = target.substr(0, dotpos);
413 string field = target.substr(dotpos + 1);
417 *iter = (*at)->simple_find(field);
420 *iter = attr_map.end();
445 if (target == (*i)->name) {
473 for (i = attr_map.begin(); i != attr_map.end(); ++i) {
474 if (target == (*i)->name) {
497 string::size_type dotpos = target.
find(
'.');
498 if (dotpos != string::npos) {
499 string container = target.substr(0, dotpos);
500 string field = target.substr(dotpos + 1);
517 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
519 return (*i)->attributes;
546 return (p != attr_map.end()) ?
get_type(p) : (string)
"";
569 return (iter != attr_map.end()) ?
get_attr_num(iter) : 0;
610 string lname =
www2id(name);
613 if (iter != attr_map.end()) {
616 attr_map.erase(iter);
625 vector<string> *sxp = (*iter)->
attr;
627 assert(i >= 0 && i < (
int)sxp->size());
628 sxp->erase(sxp->begin() + i);
642 return attr_map.begin();
651 return attr_map.end();
665 return attr_map.begin() + i;
672 assert(iter != attr_map.end());
674 return (*iter)->name;
692 assert(iter != attr_map.end());
713 struct entry* e = *iter;
721 return attr_map.erase(iter);
730 assert(iter != attr_map.end());
740 return (*iter)->type;
753 assert(iter != attr_map.end());
755 ? (*iter)->attributes->get_size()
756 : (*iter)->attr->size();
778 assert(iter != attr_map.end());
780 return (*iter)->type ==
Attr_container ? (
string)
"None" : (*(*iter)->attr)[i];
786 cerr <<
"(*iter)->attr: " << (*iter)->attr << endl;
787 cerr <<
"(*iter)->name: " << (*iter)->name << endl;
788 cerr <<
"(*iter)->type: " << (*iter)->type << endl;
790 if ((*iter)->name ==
"SIS_ID")
791 return "SIS_ID_value";
793 return (*(*iter)->attr)[i];
802 return (p != attr_map.end()) ?
get_attr(p, i) : (string)
"";
819 assert(iter != attr_map.end());
826 assert(iter != attr_map.end());
828 return (*iter)->attributes->is_global_attribute();
830 return (*iter)->is_global;
836 assert(iter != attr_map.end());
838 (*iter)->attributes->set_is_global_attribute(ga);
840 (*iter)->is_global = ga;
854 string lname =
www2id(name);
857 throw Error(
string(
"There already exists a container called `")
858 + name +
string(
"in this attribute table."));
868 attr_map.push_back(e);
885 const string &source)
887 string lname =
www2id(name);
888 string lsource =
www2id(source);
895 das->
find(lsource, &at, &iter);
901 if (!at || (iter == at->
attr_end()) || !*iter) {
902 find(lsource, &at, &iter);
903 if (!at || (iter == at->
attr_end()) || !*iter)
904 throw Error(
string(
"Could not find the attribute `")
905 + source +
string(
"' in the attribute object."));
911 throw Error(
string(
"A value cannot be aliased to the top level of the DAS;\nOnly containers may be present at that level of the DAS."));
914 throw Error(
string(
"There already exists a container called `")
915 + name + string(
"in this attribute table."));
925 e->
attr = (*iter)->attr;
927 attr_map.push_back(e);
975 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
979 attr_map.erase(attr_map.begin(), attr_map.end());
998 write_string_attribute_for_das(ostream &out,
const string &value,
const string &term)
1001 out << value << term;
1003 out << double_quote << value << double_quote << term;
1007 write_string_attribute_for_das(FILE *out,
const string &value,
const string &term)
1010 fprintf(out,
"%s%s", value.c_str(), term.c_str());
1012 fprintf(out,
"\"%s\"%s", value.c_str(), term.c_str());
1018 write_xml_attribute_for_das(ostream &out,
const string &value,
const string &term)
1027 write_xml_attribute_for_das(FILE *out,
const string &value,
const string &term)
1041 switch ((*i)->type) {
1043 fprintf(out,
"%s%s {\n", pad.c_str(),
id2www(
get_name(i)).c_str());
1045 (*i)->attributes->print(out, pad +
" ", dereference);
1047 fprintf(out,
"%s}\n", pad.c_str());
1051 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1054 vector<string> *sxp = (*i)->attr;
1055 vector<string>::iterator last = sxp->end() - 1;
1056 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1057 write_string_attribute_for_das(out, *i,
", ");
1059 write_string_attribute_for_das(out, *last,
";\n");
1064 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1067 vector<string> *sxp = (*i)->attr;
1068 vector<string>::iterator last = sxp->end() - 1;
1069 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1070 write_xml_attribute_for_das(out, *i,
", ");
1072 write_xml_attribute_for_das(out, *last,
";\n");
1077 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1080 vector<string> *sxp = (*i)->attr;
1081 vector<string>::iterator last = sxp->end() - 1;
1082 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1083 fprintf(out,
"%s%s", (*i).c_str(),
", ");
1085 fprintf(out,
"%s%s", (*last).c_str(),
";\n");
1097 switch ((*i)->type) {
1101 (*i)->attributes->print(out, pad +
" ", dereference);
1103 out << pad <<
"}\n";
1109 vector<string> *sxp = (*i)->attr;
1110 vector<string>::iterator last = sxp->end() - 1;
1111 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1112 write_string_attribute_for_das(out, *i,
", ");
1114 write_string_attribute_for_das(out, *last,
";\n");
1121 vector<string> *sxp = (*i)->attr;
1122 vector<string>::iterator last = sxp->end() - 1;
1123 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1124 write_xml_attribute_for_das(out, *i,
", ");
1126 write_xml_attribute_for_das(out, *last,
";\n");
1133 vector<string> *sxp = (*i)->attr;
1134 vector<string>::iterator last = sxp->end() - 1;
1135 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1138 out << *last <<
";\n";
1157 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
1158 if ((*i)->is_alias) {
1163 fprintf(out,
"%sAlias %s %s;\n",
1166 id2www((*i)->aliased_to).c_str());
1188 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
1189 if ((*i)->is_alias) {
1195 <<
" " <<
id2www((*i)->aliased_to) <<
";\n";
1220 if ((*i)->is_alias) {
1221 fprintf(out,
"%s<Alias name=\"%s\" Attribute=\"%s\"/>\n",
1223 (*i)->aliased_to.c_str());
1227 fprintf(out,
"%s<Attribute name=\"%s\" type=\"%s\">\n",
1233 fprintf(out,
"%s</Attribute>\n", pad.c_str());
1236 fprintf(out,
"%s<Attribute name=\"%s\" type=\"%s\">\n",
1239 string value_pad = pad +
" ";
1245 throw Error(
"OtherXML attributes cannot be vector-valued.");
1246 fprintf(out,
"%s%s\n", value_pad.c_str(),
get_attr(i, 0).c_str());
1250 fprintf(out,
"%s<value>%s</value>\n", value_pad.c_str(),
1254 fprintf(out,
"%s</Attribute>\n", pad.c_str());
1267 if ((*i)->is_alias) {
1269 <<
"\" Attribute=\"" << (*i)->aliased_to <<
"\"/>\n";
1274 <<
"\" type=\"" <<
get_type(i) <<
"\">\n";
1278 out << pad <<
"</Attribute>\n";
1282 <<
"\" type=\"" <<
get_type(i) <<
"\">\n";
1284 string value_pad = pad +
" ";
1287 throw Error(
"OtherXML attributes cannot be vector-valued.");
1288 out << value_pad <<
get_attr(i, 0) <<
"\n";
1291 string value_pad = pad +
" ";
1293 out << value_pad <<
"<value>" <<
id2xml(
get_attr(i, j)) <<
"</value>\n";
1296 out << pad <<
"</Attribute>\n";
1312 << (
void *)
this <<
")" << endl;
1315 if (attr_map.size()) {
1320 for (; i != ie; ++i) {
1330 <<
" of type " << type
1338 <<
" of type " << type
1342 vector<string>::const_iterator iter = e->
attr->begin();
1343 vector<string>::const_iterator last = e->
attr->end() - 1;
1344 for (; iter != last; iter++) {
1345 strm << (*iter) <<
", ";
1347 strm << (*(e->
attr->end() - 1)) << endl;
1358 << d_name <<
":" << (
void *)d_parent << endl;
std::vector< entry * >::iterator Attr_iter
virtual bool is_global_attribute() const
virtual Attr_iter attr_end()
Contains the attributes for a dataset.
string AttrType_to_String(const AttrType at)
virtual string get_type(const string &name)
Get the type name of an attribute within this attribute table.
void clone(const AttrTable &at)
virtual string get_name() const
Get the name of this attribute table.
virtual void add_container_alias(const string &name, AttrTable *src)
Add an alias to a container held by this attribute table.
virtual void print_xml(FILE *out, string pad=" ", bool constrained=false)
string id2xml(string in, const string ¬_allowed)
virtual string get_attr(const string &name, unsigned int i=0)
virtual void del_attr(const string &name, int i=-1)
Deletes an attribute.
string escape_double_quotes(string source)
virtual void set_is_global_attribute(bool ga)
virtual AttrTable * recurrsive_find(const string &target, Attr_iter *location)
const string double_quote
virtual void print(FILE *out, string pad=" ", bool dereference=false)
Prints the attribute table.
virtual AttrTable * find_container(const string &target)
Find an attribute with a given name.
AttrTable & operator=(const AttrTable &rhs)
virtual Attr_iter get_attr_iter(int i)
virtual void add_value_alias(AttrTable *at, const string &name, const string &source)
Add an alias for an attribute.
virtual bool is_container(Attr_iter iter)
AttrType String_to_AttrType(const string &s)
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
AttrTable * simple_find_container(const string &target)
virtual AttrTable * get_attr_table(const string &name)
Get an attribute container.
virtual void erase()
Erase the attribute table.
bool is_quoted(const string &s)
virtual bool attr_alias(const string &alias, AttrTable *at, const string &name)
Adds an alias to the set of attributes.
virtual Attr_iter attr_begin()
string www2id(const string &in, const string &escape, const string &except)
std::vector< entry * >::const_iterator Attr_citer
virtual unsigned int get_attr_num(const string &name)
Get the number of attributes in this container.
static ostream & LMarg(ostream &strm)
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
libdap base object for common functionality of libdap objects
void simple_print(FILE *out, string pad, Attr_iter i, bool dereference)
virtual AttrType get_attr_type(const string &name)
Get the type of an attribute.
virtual vector< string > * get_attr_vector(const string &name)
Get a vector-valued attribute.
A class for error processing.
virtual unsigned int get_size() const
Get the number of entries in this attribute table.
virtual void set_name(const string &n)
Set the name of this attribute table.
virtual void dump(ostream &strm) const
dumps information about this object
std::vector< string > * attr
virtual Attr_iter del_attr_table(Attr_iter iter)
virtual void find(const string &target, AttrTable **at, Attr_iter *iter)
string id2www(string in, const string &allowable)
Attr_iter simple_find(const string &target)