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