void herschel::xml::displayTypeVector(Port<Octet>& port, zstring tagName, const TypeVector& types) { if (!types.empty()) { displayOpenTag(port, tagName); for (size_t i = 0; i < types.size(); i++) herschel::display(port, types[i].toString()); displayCloseTag(port, tagName); } }
// The scalar cases in llsd_matches() use this helper. In most cases, we can // accept not only the exact type specified in the prototype, but also other // types convertible to the expected type. That implies looping over an array // of such types. If the actual type doesn't match any of them, we want to // provide a list of acceptable conversions as well as the exact type, e.g.: // "Integer (or Boolean, Real, String) required instead of UUID". Both the // implementation and the calling logic are simplified by separating out the // expected type from the convertible types. static std::string match_types(LLSD::Type expect, // prototype.type() const TypeVector& accept, // types convertible to that type LLSD::Type actual, // type we're checking const std::string& pfx) // as for llsd_matches { // Trivial case: if the actual type is exactly what we expect, we're good. if (actual == expect) return ""; // For the rest of the logic, build up a suitable error string as we go so // we only have to make a single pass over the list of acceptable types. // If we detect success along the way, we'll simply discard the partial // error string. std::ostringstream out; out << colon(pfx) << sTypes.lookup(expect); // If there are any convertible types, append that list. if (! accept.empty()) { out << " ("; const char* sep = "or "; for (TypeVector::const_iterator ai(accept.begin()), aend(accept.end()); ai != aend; ++ai, sep = ", ") { // Don't forget to return success if we match any of those types... if (actual == *ai) return ""; out << sep << sTypes.lookup(*ai); } out << ')'; } // If we got this far, it's because 'actual' was not one of the acceptable // types, so we must return an error. 'out' already contains colon(pfx) // and the formatted list of acceptable types, so just append the mismatch // phrase and the actual type. out << op << sTypes.lookup(actual); return out.str(); }