LCOV - code coverage report
Current view: top level - configmgr/source - modifications.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 31 58.1 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 38 39.5 %

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

Generated by: LCOV version 1.10