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