LCOV - code coverage report
Current view: top level - configmgr/source - partial.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          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             : #include <map>
      24             : #include <set>
      25             : 
      26             : #include "com/sun/star/uno/Reference.hxx"
      27             : #include "com/sun/star/uno/RuntimeException.hpp"
      28             : #include "com/sun/star/uno/XInterface.hpp"
      29             : #include "rtl/ustring.h"
      30             : #include "rtl/ustring.hxx"
      31             : #include "sal/types.h"
      32             : 
      33             : #include "data.hxx"
      34             : #include "partial.hxx"
      35             : 
      36             : namespace configmgr {
      37             : 
      38             : namespace {
      39             : 
      40           0 : bool parseSegment(
      41             :     OUString const & path, sal_Int32 * index, OUString * segment)
      42             : {
      43             :     assert(
      44             :         index != 0 && *index >= 0 && *index <= path.getLength() &&
      45             :         segment != 0);
      46           0 :     if (path[(*index)++] == '/') {
      47           0 :         OUString name;
      48             :         bool setElement;
      49           0 :         OUString templateName;
      50             :         *index = Data::parseSegment(
      51           0 :             path, *index, &name, &setElement, &templateName);
      52           0 :         if (*index != -1) {
      53           0 :             *segment = Data::createSegment(templateName, name);
      54           0 :             return *index == path.getLength();
      55           0 :         }
      56             :     }
      57             :     throw css::uno::RuntimeException(
      58           0 :         "bad path " + path, css::uno::Reference< css::uno::XInterface >());
      59             : }
      60             : 
      61             : }
      62             : 
      63           0 : Partial::Partial(
      64             :     std::set< OUString > const & includedPaths,
      65           0 :     std::set< OUString > const & excludedPaths)
      66             : {
      67             :     // The Partial::Node tree built up here encodes the following information:
      68             :     // * Inner node, startInclude: an include starts here that contains excluded
      69             :     //   sub-trees
      70             :     // * Inner node, !startInclude: contains in-/excluded sub-trees
      71             :     // * Leaf node, startInclude: an include starts here
      72             :     // * Leaf node, !startInclude: an exclude starts here
      73           0 :     for (std::set< OUString >::const_iterator i(includedPaths.begin());
      74           0 :          i != includedPaths.end(); ++i)
      75             :     {
      76           0 :         sal_Int32 n = 0;
      77           0 :         for (Node * p = &root_;;) {
      78           0 :             OUString seg;
      79           0 :             bool end = parseSegment(*i, &n, &seg);
      80           0 :             p = &p->children[seg];
      81           0 :             if (p->startInclude) {
      82           0 :                 break;
      83             :             }
      84           0 :             if (end) {
      85           0 :                 p->children.clear();
      86           0 :                 p->startInclude = true;
      87           0 :                 break;
      88             :             }
      89           0 :         }
      90             :     }
      91           0 :     for (std::set< OUString >::const_iterator i(excludedPaths.begin());
      92           0 :          i != excludedPaths.end(); ++i)
      93             :     {
      94           0 :         sal_Int32 n = 0;
      95           0 :         for (Node * p = &root_;;) {
      96           0 :             OUString seg;
      97           0 :             bool end = parseSegment(*i, &n, &seg);
      98           0 :             if (end) {
      99           0 :                 p->children[seg].clear();
     100           0 :                 break;
     101             :             }
     102           0 :             Node::Children::iterator j(p->children.find(seg));
     103           0 :             if (j == p->children.end()) {
     104           0 :                 break;
     105             :             }
     106           0 :             p = &j->second;
     107           0 :         }
     108             :     }
     109           0 : }
     110             : 
     111           0 : Partial::~Partial() {}
     112             : 
     113           0 : Partial::Containment Partial::contains(Path const & path) const {
     114             :     //TODO: For set elements, the segment names recorded in the node tree need
     115             :     // not match the corresponding path segments, so this function can fail.
     116             : 
     117             :     // * If path ends at a leaf node or goes past a leaf node:
     118             :     // ** If that leaf node is startInclude: => CONTAINS_NODE
     119             :     // ** If that leaf node is !startInclude: => CONTAINS_NOT
     120             :     // * If path ends at inner node:
     121             :     // ** If there is some startInclude along its trace: => CONTAINS_NODE
     122             :     // ** If there is no startInclude along its trace: => CONTAINS_SUBNODES
     123           0 :     Node const * p = &root_;
     124           0 :     bool includes = false;
     125           0 :     for (Path::const_iterator i(path.begin()); i != path.end(); ++i) {
     126           0 :         Node::Children::const_iterator j(p->children.find(*i));
     127           0 :         if (j == p->children.end()) {
     128           0 :             return p->startInclude ? CONTAINS_NODE : CONTAINS_NOT;
     129             :         }
     130           0 :         p = &j->second;
     131           0 :         includes |= p->startInclude;
     132             :     }
     133           0 :     return p->children.empty() && !p->startInclude
     134             :         ? CONTAINS_NOT
     135           0 :         : includes ? CONTAINS_NODE : CONTAINS_SUBNODES;
     136             : }
     137             : 
     138             : }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10