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 66551 : Modifications::Modifications() {}
32 :
33 66551 : Modifications::~Modifications() {}
34 :
35 264632 : void Modifications::add(Path const & path) {
36 264632 : Node * p = &root_;
37 264632 : bool wasPresent = false;
38 1413964 : for (Path::const_iterator i(path.begin()); i != path.end(); ++i) {
39 1173568 : Node::Children::iterator j(p->children.find(*i));
40 1173568 : if (j == p->children.end()) {
41 273273 : if (wasPresent && p->children.empty()) {
42 288868 : return;
43 : }
44 498074 : j = p->children.insert(Node::Children::value_type(*i, Node())).
45 249037 : first;
46 249037 : wasPresent = false;
47 : } else {
48 900295 : wasPresent = true;
49 : }
50 1149332 : p = &j->second;
51 : }
52 240396 : 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 1016640 : Modifications::Node const & Modifications::getRoot() const {
77 1016640 : return root_;
78 : }
79 :
80 : }
81 :
82 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|