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 6353 : Modifications::Modifications() {}
32 :
33 6353 : Modifications::~Modifications() {}
34 :
35 24646 : void Modifications::add(Path const & path) {
36 24646 : Node * p = &root_;
37 24646 : bool wasPresent = false;
38 147131 : for (Path::const_iterator i(path.begin()); i != path.end(); ++i) {
39 130123 : Node::Children::iterator j(p->children.find(*i));
40 130123 : if (j == p->children.end()) {
41 40835 : if (wasPresent && p->children.empty()) {
42 24646 : return;
43 : }
44 66394 : j = p->children.insert(Node::Children::value_type(*i, Node())).
45 33197 : first;
46 33197 : wasPresent = false;
47 : } else {
48 89288 : wasPresent = true;
49 : }
50 122485 : p = &j->second;
51 : }
52 17008 : 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 : 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 : break;
71 : }
72 0 : p = &j->second;
73 : }
74 0 : }
75 :
76 112895 : Modifications::Node const & Modifications::getRoot() const {
77 112895 : return root_;
78 : }
79 :
80 : }
81 :
82 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|