std::string RosterSerializer::serializePayload(std::shared_ptr<RosterPayload> roster) const { XMLElement queryElement("query", "jabber:iq:roster"); if (roster->getVersion()) { queryElement.setAttribute("ver", *roster->getVersion()); } foreach(const RosterItemPayload& item, roster->getItems()) { std::shared_ptr<XMLElement> itemElement(new XMLElement("item")); itemElement->setAttribute("jid", item.getJID()); itemElement->setAttribute("name", item.getName()); switch (item.getSubscription()) { case RosterItemPayload::To: itemElement->setAttribute("subscription", "to"); break; case RosterItemPayload::From: itemElement->setAttribute("subscription", "from"); break; case RosterItemPayload::Both: itemElement->setAttribute("subscription", "both"); break; case RosterItemPayload::Remove: itemElement->setAttribute("subscription", "remove"); break; case RosterItemPayload::None: itemElement->setAttribute("subscription", "none"); break; } if (item.getSubscriptionRequested()) { itemElement->setAttribute("ask", "subscribe"); } foreach(const std::string& group, item.getGroups()) { std::shared_ptr<XMLElement> groupElement(new XMLElement("group")); groupElement->addNode(std::make_shared<XMLTextNode>(group)); itemElement->addNode(groupElement); } if (!item.getUnknownContent().empty()) { itemElement->addNode(std::make_shared<XMLRawTextNode>(item.getUnknownContent())); } queryElement.addNode(itemElement); } return queryElement.serialize(); }
void GroupCountMap::insert(string &indexName, vector<string> &elementNames, \ int increasement) { map<string, GroupCountElement>::iterator it; if (indexName.size() ==0 ) return; it = countMap.find(indexName); if (it != countMap.end()) { it->second.update(elementNames, increasement); } else { GroupCountElement groupElement(elementNames); countMap.insert(pair<string, GroupCountElement>(indexName, groupElement)); } int count = countMap.find(indexName)->second.count; if (count > countForMost) { countForMost = count; nameForMost = indexName; } }