Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <cassert>
23 :
24 : #include <rtl/ustring.hxx>
25 :
26 : #include "modifications.hxx"
27 : #include "path.hxx"
28 :
29 : namespace configmgr {
30 :
31 151701 : Modifications::Modifications() {}
32 :
33 151701 : Modifications::~Modifications() {}
34 :
35 560624 : void Modifications::add(Path const & path) {
36 560624 : Node * p = &root_;
37 560624 : bool wasPresent = false;
38 3161579 : for (Path::const_iterator i(path.begin()); i != path.end(); ++i) {
39 2722218 : Node::Children::iterator j(p->children.find(*i));
40 2722218 : if (j == p->children.end()) {
41 821919 : if (wasPresent && p->children.empty()) {
42 681887 : return;
43 : }
44 1401312 : j = p->children.insert(Node::Children::value_type(*i, Node())).
45 700656 : first;
46 700656 : wasPresent = false;
47 : } else {
48 1900299 : wasPresent = true;
49 : }
50 2600955 : p = &j->second;
51 : }
52 439361 : p->children.clear();
53 : }
54 :
55 0 : void Modifications::remove(Path const & path) {
56 : assert(!path.empty());
57 0 : Node * p = &root_;
58 0 : for (Path::const_iterator i(path.begin());;) {
59 0 : Node::Children::iterator j(p->children.find(*i));
60 0 : if (j == p->children.end()) {
61 0 : break;
62 : }
63 0 : if (++i == path.end()) {
64 0 : p->children.erase(j);
65 0 : if (p->children.empty()) {
66 0 : Path parent(path);
67 0 : parent.pop_back();
68 0 : remove(parent);
69 : }
70 0 : break;
71 : }
72 0 : p = &j->second;
73 0 : }
74 0 : }
75 :
76 :
77 : }
78 :
79 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|