1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_configmgr.hxx" 25 #include "sal/config.h" 26 27 #include "rtl/ustring.hxx" 28 29 #include "modifications.hxx" 30 #include "path.hxx" 31 32 namespace configmgr { 33 Modifications()34Modifications::Modifications() {} 35 ~Modifications()36Modifications::~Modifications() {} 37 add(Path const & path)38void Modifications::add(Path const & path) { 39 Node * p = &root_; 40 bool wasPresent = false; 41 for (Path::const_iterator i(path.begin()); i != path.end(); ++i) { 42 Node::Children::iterator j(p->children.find(*i)); 43 if (j == p->children.end()) { 44 if (wasPresent && p->children.empty()) { 45 return; 46 } 47 j = p->children.insert(Node::Children::value_type(*i, Node())). 48 first; 49 wasPresent = false; 50 } else { 51 wasPresent = true; 52 } 53 p = &j->second; 54 } 55 p->children.clear(); 56 } 57 remove(Path const & path)58void Modifications::remove(Path const & path) { 59 OSL_ASSERT(!path.empty()); 60 Node * p = &root_; 61 for (Path::const_iterator i(path.begin());;) { 62 Node::Children::iterator j(p->children.find(*i)); 63 if (j == p->children.end()) { 64 break; 65 } 66 if (++i == path.end()) { 67 p->children.erase(j); 68 if (p->children.empty()) { 69 Path parent(path); 70 parent.pop_back(); 71 remove(parent); 72 } 73 break; 74 } 75 p = &j->second; 76 } 77 } 78 getRoot() const79Modifications::Node const & Modifications::getRoot() const { 80 return root_; 81 } 82 83 } 84