| 759 | } |
| 760 | |
| 761 | Param Param::copy(const std::string& prefix, bool remove_prefix) const |
| 762 | { |
| 763 | ParamNode out("ROOT", ""); |
| 764 | |
| 765 | ParamNode* node = root_.findParentOf(prefix); |
| 766 | if (node == nullptr) |
| 767 | { |
| 768 | return Param(); |
| 769 | } |
| 770 | //we have to copy this node only |
| 771 | if (!prefix.empty() && prefix.back() == ':') |
| 772 | { |
| 773 | if (remove_prefix) |
| 774 | { |
| 775 | out = *node; |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | out.insert(*node, prefix.substr(0, prefix.size() - node->name.size() - 1)); |
| 780 | } |
| 781 | } |
| 782 | else //we have to copy all entries and nodes starting with the right suffix |
| 783 | { |
| 784 | std::string suffix = node->suffix(prefix); |
| 785 | for (Param::ParamNode::NodeIterator it = node->nodes.begin(); it != node->nodes.end(); ++it) |
| 786 | { |
| 787 | if (it->name.compare(0, suffix.size(), suffix) == 0) |
| 788 | { |
| 789 | if (remove_prefix) |
| 790 | { |
| 791 | ParamNode tmp = *it; |
| 792 | tmp.name = tmp.name.substr(suffix.size()); |
| 793 | out.insert(tmp); |
| 794 | } |
| 795 | else |
| 796 | { |
| 797 | out.insert(*it, prefix.substr(0, prefix.size() - suffix.size())); |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | for (Param::ParamNode::EntryIterator it = node->entries.begin(); it != node->entries.end(); ++it) |
| 802 | { |
| 803 | if (it->name.compare(0, suffix.size(), suffix) == 0) |
| 804 | { |
| 805 | if (remove_prefix) |
| 806 | { |
| 807 | ParamEntry tmp = *it; |
| 808 | tmp.name = tmp.name.substr(suffix.size()); |
| 809 | out.insert(tmp); |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | out.insert(*it, prefix.substr(0, prefix.size() - suffix.size())); |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |