/** * processItem * - If this is a TclCommand - flush all the consolidations and output. * - If there's already a consolidation for this type if the message is the * same just count it, otherwise flush and set a new consolidation. * - If there's not an existing consolidation, make one. * - free storage associated with the action item's payload. * * @param action - action message. */ void Actions::COutputThread::processItem(Actions::ActionItem item) { Actions::ActionType type = item.s_type; std::string msg = item.s_pMessage; free(item.s_pMessage); // Free storage!' if (type == Actions::TclCommand) { flushMessages(); // Flush All messages before commanding. outputItem(type, msg); } else { // Message, not an actual 'action'. std::map<Actions::ActionType, ActionInfo>::iterator p = m_ConsolidatedActions.find(type); if (p == m_ConsolidatedActions.end()) { // No prior message. createConsolidation(type, msg); } else { if(msg == p->second.s_message) { // If repetition p->second.s_messageCount++; // count. } else { flushItem(type); // otherwise flush that item. createConsolidation(type, msg); // start a new one. } } } }
void distributeRgbRainbow(char *inList, char *inPairs, char *outTab) /* distributeRgbRainbow - Associate colors with items on a list where distance between colors * is proportional to distance between items. */ { /* Read in inputs */ struct slName *item, *itemList = readAllLines(inList); verbose(1, "%d items in %s\n", slCount(itemList), inList); struct pairDistance *pairList= pairDistanceReadAll(inPairs); verbose(1, "%d pairs in %s\n", slCount(pairList), inPairs); struct hash *pairHash = pairDistanceHashList(pairList); /* Open output, and just finish early if it should be empty */ FILE *f = mustOpen(outTab, "w"); if (itemList == NULL) return; /* Cope with invert option. */ if (optionExists("invert")) pairDistanceInvert(pairList); /* Add up total distance between all items */ double totalDistance = 0.0; for (item = itemList; item != NULL; item = item->next) { struct slName *nextItem = item->next; if (nextItem == NULL) break; totalDistance += pairDistanceHashLookup(pairHash, item->name, nextItem->name); } double colorRange = gEnd - gStart; outputItem(f, itemList->name, gStart); double soFar = 0.0; for (item = itemList; item != NULL; item = item->next) { struct slName *nextItem = item->next; if (nextItem == NULL) break; double distance = pairDistanceHashLookup(pairHash, item->name, nextItem->name); soFar += distance; outputItem(f, nextItem->name, gStart + (soFar/totalDistance * colorRange)); } carefulClose(&f); }
/** * flushItem * Flush consolidated messages for a single item type. * * @param itemType - Type of item to flush. * * @note - if there are no consolidated messages for this type obviously * nothing is emitted. * @note - If there is only one message it is emitted unmodified. * @note - If there are multiple messges, the message is preceded * with count information. * @note - Regardless after all of this is done, the item is removed from * the map. */ void Actions::COutputThread::flushItem(Actions::ActionType itemType) { std::map<Actions::ActionType, ActionInfo>::iterator p = m_ConsolidatedActions.find(itemType); if (p != m_ConsolidatedActions.end()) { std::string baseMessage = p->second.s_message; unsigned count = p->second.s_messageCount; if(count == 1) { outputItem(itemType, baseMessage); } else { std::stringstream s; s << count << " repetitions of: " << baseMessage; outputItem(itemType, s.str()); } m_ConsolidatedActions.erase(p); // Remove the consolidation entry. } }
NPT_String RootContainer::generateDidl(const NPT_List<const Object*>& ls, const NPT_String& resUriTmpl) { NPT_StringOutputStream outputStream; NPT_XmlSerializer xml(&outputStream, 0, true, true); xml.StartDocument(); xml.StartElement(NULL, "DIDL-Lite"); xml.Attribute(NULL, "xmlns", "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"); xml.Attribute("xmlns", "dc", "http://purl.org/dc/elements/1.1/"); xml.Attribute("xmlns", "upnp", "urn:schemas-upnp-org:metadata-1-0/upnp/"); for (NPT_Ordinal i = 0; i < ls.GetItemCount(); i++) { const Object *obj = *ls.GetItem(i); if (const Item *item = obj->asItem()) { outputItem(xml, item, resUriTmpl); } else if (const Container *container = obj->asContainer()) { outputContainer(xml, container, resUriTmpl); } } xml.EndElement(NULL, "DIDL-Lite"); xml.EndDocument(); return outputStream.GetString(); }