| 668 | } |
| 669 | |
| 670 | void Param::removeAll(const std::string& prefix) |
| 671 | { |
| 672 | if (!prefix.empty() && prefix.back() == ':')//we have to delete one node only (and its subnodes) |
| 673 | { |
| 674 | ParamNode* node = root_.findParentOf(prefix.substr(0, prefix.length() - 1)); |
| 675 | if (node != nullptr) |
| 676 | { |
| 677 | Param::ParamNode::NodeIterator it = node->findNode(node->suffix(prefix.substr(0, prefix.length() - 1))); |
| 678 | if (it != node->nodes.end()) |
| 679 | { |
| 680 | std::string name = it->name; |
| 681 | node->nodes.erase(it); // will automatically delete subnodes |
| 682 | if (node->nodes.empty() && node->entries.empty()) |
| 683 | { |
| 684 | // delete last section name (could be partial) |
| 685 | removeAll(prefix.substr(0, prefix.length() - name.length() - 1));// '-1' for the tailing ':' |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | else //we have to delete all entries and nodes starting with the prefix |
| 691 | { |
| 692 | ParamNode* node = root_.findParentOf(prefix); |
| 693 | if (node != nullptr) |
| 694 | { |
| 695 | std::string suffix = node->suffix(prefix); // name behind last ":" |
| 696 | |
| 697 | for (Param::ParamNode::NodeIterator it = node->nodes.begin(); it != node->nodes.end(); /*do nothing*/) |
| 698 | { |
| 699 | if (it->name.compare(0, suffix.length(), suffix) == 0) |
| 700 | { |
| 701 | it = node->nodes.erase(it); |
| 702 | } |
| 703 | else if (it != node->nodes.end()) |
| 704 | { |
| 705 | ++it; |
| 706 | } |
| 707 | } |
| 708 | for (Param::ParamNode::EntryIterator it = node->entries.begin(); it != node->entries.end(); /*do nothing*/) |
| 709 | { |
| 710 | if (it->name.compare(0, suffix.size(), suffix) == 0) |
| 711 | { |
| 712 | it = node->entries.erase(it); |
| 713 | } |
| 714 | else if (it != node->entries.end()) |
| 715 | { |
| 716 | ++it; |
| 717 | } |
| 718 | } |
| 719 | // the parent node might now be empty (delete it as well - otherwise the trace might be broken) |
| 720 | if (node->nodes.empty() && node->entries.empty()) |
| 721 | { |
| 722 | // delete last section name (could be partial) |
| 723 | removeAll(prefix.substr(0, prefix.size() - suffix.size())); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
no test coverage detected