Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / configmgr / source / partial.cxx
blob89643cb7ceb96141a069ec24c48ec6b3afb36b1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <cassert>
23 #include <set>
25 #include <com/sun/star/uno/RuntimeException.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
30 #include "data.hxx"
31 #include "partial.hxx"
33 namespace configmgr {
35 namespace {
37 bool parseSegment(
38 OUString const & path, sal_Int32 * index, OUString * segment)
40 assert(
41 index != nullptr && *index >= 0 && *index <= path.getLength() &&
42 segment != nullptr);
43 if (path[(*index)++] == '/') {
44 OUString name;
45 bool setElement;
46 OUString templateName;
47 *index = Data::parseSegment(
48 path, *index, &name, &setElement, &templateName);
49 if (*index != -1) {
50 *segment = Data::createSegment(templateName, name);
51 return *index == path.getLength();
54 throw css::uno::RuntimeException("bad path " + path);
59 Partial::Partial(
60 css::uno::Sequence< OUString > const & includedPaths,
61 css::uno::Sequence< OUString > const & excludedPaths)
63 // The Partial::Node tree built up here encodes the following information:
64 // * Inner node, startInclude: an include starts here that contains excluded
65 // sub-trees
66 // * Inner node, !startInclude: contains in-/excluded sub-trees
67 // * Leaf node, startInclude: an include starts here
68 // * Leaf node, !startInclude: an exclude starts here
69 for (auto const& includedPath : includedPaths)
71 sal_Int32 n = 0;
72 for (Node * p = &root_;;) {
73 OUString seg;
74 bool end = parseSegment(includedPath, &n, &seg);
75 p = &p->children[seg];
76 if (p->startInclude) {
77 break;
79 if (end) {
80 p->children.clear();
81 p->startInclude = true;
82 break;
86 for (auto const& excludedPath : excludedPaths)
88 sal_Int32 n = 0;
89 for (Node * p = &root_;;) {
90 OUString seg;
91 bool end = parseSegment(excludedPath, &n, &seg);
92 if (end) {
93 p->children[seg].clear();
94 break;
96 Node::Children::iterator j(p->children.find(seg));
97 if (j == p->children.end()) {
98 break;
100 p = &j->second;
105 Partial::~Partial() {}
107 Partial::Containment Partial::contains(std::vector<OUString> const & path) const {
108 //TODO: For set elements, the segment names recorded in the node tree need
109 // not match the corresponding path segments, so this function can fail.
111 // * If path ends at a leaf node or goes past a leaf node:
112 // ** If that leaf node is startInclude: => CONTAINS_NODE
113 // ** If that leaf node is !startInclude: => CONTAINS_NOT
114 // * If path ends at inner node:
115 // ** If there is some startInclude along its trace: => CONTAINS_NODE
116 // ** If there is no startInclude along its trace: => CONTAINS_SUBNODES
117 Node const * p = &root_;
118 bool bIncludes = false;
119 for (auto const& elemPath : path)
121 Node::Children::const_iterator j(p->children.find(elemPath));
122 if (j == p->children.end()) {
123 return p->startInclude ? CONTAINS_NODE : CONTAINS_NOT;
125 p = &j->second;
126 bIncludes |= p->startInclude;
128 return p->children.empty() && !p->startInclude
129 ? CONTAINS_NOT
130 : bIncludes ? CONTAINS_NODE : CONTAINS_SUBNODES;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */