38 "$Id: AttrTable.cc 24370 2011-03-28 16:21:32Z jimg $";
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();
351 delete new_at; new_at = 0;
374 string lname =
www2id(name);
377 throw Error(
string(
"There already exists a container called `")
378 + name +
string(
"' in this attribute table."));
379 DBG(cerr <<
"Setting appended attribute container name to: "
389 attr_map.push_back(e);
413 string::size_type dotpos = target.rfind(
'.');
414 if (dotpos != string::npos) {
415 string container = target.substr(0, dotpos);
416 string field = target.substr(dotpos + 1);
420 *iter = (*at)->simple_find(field);
423 *iter = attr_map.end();
448 if (target == (*i)->name) {
476 for (i = attr_map.begin(); i != attr_map.end(); ++i) {
477 if (target == (*i)->name) {
500 string::size_type dotpos = target.
find(
'.');
501 if (dotpos != string::npos) {
502 string container = target.substr(0, dotpos);
503 string field = target.substr(dotpos + 1);
520 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
522 return (*i)->attributes;
549 return (p != attr_map.end()) ?
get_type(p) : (string)
"";
572 return (iter != attr_map.end()) ?
get_attr_num(iter) : 0;
613 string lname =
www2id(name);
616 if (iter != attr_map.end()) {
619 attr_map.erase(iter);
628 vector<string> *sxp = (*iter)->
attr;
630 assert(i >= 0 && i < (
int)sxp->size());
631 sxp->erase(sxp->begin() + i);
645 return attr_map.begin();
654 return attr_map.end();
668 return attr_map.begin() + i;
675 assert(iter != attr_map.end());
677 return (*iter)->name;
695 assert(iter != attr_map.end());
716 struct entry* e = *iter;
724 return attr_map.erase(iter);
733 assert(iter != attr_map.end());
743 return (*iter)->type;
756 assert(iter != attr_map.end());
758 ? (*iter)->attributes->get_size()
759 : (*iter)->attr->size();
781 assert(iter != attr_map.end());
783 return (*iter)->type ==
Attr_container ? (
string)
"None" : (*(*iter)->attr)[i];
789 cerr <<
"(*iter)->attr: " << (*iter)->attr << endl;
790 cerr <<
"(*iter)->name: " << (*iter)->name << endl;
791 cerr <<
"(*iter)->type: " << (*iter)->type << endl;
793 if ((*iter)->name ==
"SIS_ID")
794 return "SIS_ID_value";
796 return (*(*iter)->attr)[i];
805 return (p != attr_map.end()) ?
get_attr(p, i) : (string)
"";
822 assert(iter != attr_map.end());
829 assert(iter != attr_map.end());
831 return (*iter)->attributes->is_global_attribute();
833 return (*iter)->is_global;
839 assert(iter != attr_map.end());
841 (*iter)->attributes->set_is_global_attribute(ga);
843 (*iter)->is_global = ga;
857 string lname =
www2id(name);
860 throw Error(
string(
"There already exists a container called `")
861 + name +
string(
"in this attribute table."));
871 attr_map.push_back(e);
888 const string &source)
890 string lname =
www2id(name);
891 string lsource =
www2id(source);
898 das->
find(lsource, &at, &iter);
904 if (!at || (iter == at->
attr_end()) || !*iter) {
905 find(lsource, &at, &iter);
906 if (!at || (iter == at->
attr_end()) || !*iter)
907 throw Error(
string(
"Could not find the attribute `")
908 + source +
string(
"' in the attribute object."));
914 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."));
917 throw Error(
string(
"There already exists a container called `")
918 + name + string(
"in this attribute table."));
928 e->
attr = (*iter)->attr;
930 attr_map.push_back(e);
978 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
982 attr_map.erase(attr_map.begin(), attr_map.end());
1001 write_string_attribute_for_das(ostream &out,
const string &value,
const string &term)
1004 out << value << term;
1010 write_string_attribute_for_das(FILE *out,
const string &value,
const string &term)
1013 fprintf(out,
"%s%s", value.c_str(), term.c_str());
1015 fprintf(out,
"\"%s\"%s", value.c_str(), term.c_str());
1021 write_xml_attribute_for_das(ostream &out,
const string &value,
const string &term)
1030 write_xml_attribute_for_das(FILE *out,
const string &value,
const string &term)
1044 switch ((*i)->type) {
1046 fprintf(out,
"%s%s {\n", pad.c_str(),
id2www(
get_name(i)).c_str());
1048 (*i)->attributes->print(out, pad +
" ", dereference);
1050 fprintf(out,
"%s}\n", pad.c_str());
1054 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1057 vector<string> *sxp = (*i)->attr;
1058 vector<string>::iterator last = sxp->end() - 1;
1059 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1060 write_string_attribute_for_das(out, *i,
", ");
1062 write_string_attribute_for_das(out, *last,
";\n");
1067 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1070 vector<string> *sxp = (*i)->attr;
1071 vector<string>::iterator last = sxp->end() - 1;
1072 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1073 write_xml_attribute_for_das(out, *i,
", ");
1075 write_xml_attribute_for_das(out, *last,
";\n");
1080 fprintf(out,
"%s%s %s ", pad.c_str(),
get_type(i).c_str(),
1083 vector<string> *sxp = (*i)->attr;
1084 vector<string>::iterator last = sxp->end() - 1;
1085 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1086 fprintf(out,
"%s%s", (*i).c_str(),
", ");
1088 fprintf(out,
"%s%s", (*last).c_str(),
";\n");
1100 switch ((*i)->type) {
1104 (*i)->attributes->print(out, pad +
" ", dereference);
1106 out << pad <<
"}\n";
1112 vector<string> *sxp = (*i)->attr;
1113 vector<string>::iterator last = sxp->end() - 1;
1114 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1115 write_string_attribute_for_das(out, *i,
", ");
1117 write_string_attribute_for_das(out, *last,
";\n");
1124 vector<string> *sxp = (*i)->attr;
1125 vector<string>::iterator last = sxp->end() - 1;
1126 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1127 write_xml_attribute_for_das(out, *i,
", ");
1129 write_xml_attribute_for_das(out, *last,
";\n");
1136 vector<string> *sxp = (*i)->attr;
1137 vector<string>::iterator last = sxp->end() - 1;
1138 for (vector<string>::iterator i = sxp->begin(); i != last; ++i) {
1141 out << *last <<
";\n";
1160 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
1161 if ((*i)->is_alias) {
1166 fprintf(out,
"%sAlias %s %s;\n",
1169 id2www((*i)->aliased_to).c_str());
1191 for (
Attr_iter i = attr_map.begin(); i != attr_map.end(); ++i) {
1192 if ((*i)->is_alias) {
1198 <<
" " <<
id2www((*i)->aliased_to) <<
";\n";
1223 if ((*i)->is_alias) {
1224 fprintf(out,
"%s<Alias name=\"%s\" Attribute=\"%s\"/>\n",
1226 (*i)->aliased_to.c_str());
1230 fprintf(out,
"%s<Attribute name=\"%s\" type=\"%s\">\n",
1236 fprintf(out,
"%s</Attribute>\n", pad.c_str());
1239 fprintf(out,
"%s<Attribute name=\"%s\" type=\"%s\">\n",
1242 string value_pad = pad +
" ";
1248 throw Error(
"OtherXML attributes cannot be vector-valued.");
1249 fprintf(out,
"%s%s\n", value_pad.c_str(),
get_attr(i, 0).c_str());
1253 fprintf(out,
"%s<value>%s</value>\n", value_pad.c_str(),
1257 fprintf(out,
"%s</Attribute>\n", pad.c_str());
1270 if ((*i)->is_alias) {
1272 <<
"\" Attribute=\"" << (*i)->aliased_to <<
"\"/>\n";
1277 <<
"\" type=\"" <<
get_type(i) <<
"\">\n";
1281 out << pad <<
"</Attribute>\n";
1285 <<
"\" type=\"" <<
get_type(i) <<
"\">\n";
1287 string value_pad = pad +
" ";
1290 throw Error(
"OtherXML attributes cannot be vector-valued.");
1291 out << value_pad <<
get_attr(i, 0) <<
"\n";
1294 string value_pad = pad +
" ";
1296 out << value_pad <<
"<value>" <<
id2xml(
get_attr(i, j)) <<
"</value>\n";
1299 out << pad <<
"</Attribute>\n";
1315 << (
void *)
this <<
")" << endl;
1318 if (attr_map.size()) {
1320 DapIndent::Indent();
1323 for (; i != ie; ++i) {
1333 <<
" of type " << type
1335 DapIndent::Indent();
1341 <<
" of type " << type
1343 DapIndent::Indent();
1345 vector<string>::const_iterator iter = e->
attr->begin();
1346 vector<string>::const_iterator last = e->
attr->end() - 1;
1347 for (; iter != last; ++iter) {
1348 strm << (*iter) <<
", ";
1350 strm << (*(e->
attr->end() - 1)) << endl;
1361 << d_name <<
":" << (
void *)d_parent << endl;