LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ContextList.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 29 34 85.3 %
Date: 2014-04-11 Functions: 5 6 83.3 %
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             : #include "ContextList.hxx"
      20             : #include "Context.hxx"
      21             : 
      22             : using ::rtl::OUString;
      23             : 
      24             : namespace sfx2 { namespace sidebar {
      25             : 
      26             : 
      27         175 : ContextList::ContextList (void)
      28         175 :     : maEntries()
      29             : {
      30         175 : }
      31             : 
      32             : 
      33             : 
      34             : 
      35         175 : ContextList::~ContextList (void)
      36             : {
      37         175 : }
      38             : 
      39             : 
      40             : 
      41             : 
      42         264 : const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const
      43             : {
      44         264 :     const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
      45         264 :     if (iEntry != maEntries.end())
      46          88 :         return &*iEntry;
      47             :     else
      48         176 :         return NULL;
      49             : }
      50             : 
      51             : 
      52             : 
      53             : 
      54           0 : ContextList::Entry* ContextList::GetMatch (const Context& rContext)
      55             : {
      56           0 :     const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
      57           0 :     if (iEntry != maEntries.end())
      58           0 :         return const_cast<Entry*>(&*iEntry);
      59             :     else
      60           0 :         return NULL;
      61             : }
      62             : 
      63             : 
      64             : 
      65             : 
      66         264 : ::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const
      67             : {
      68         264 :     sal_Int32 nBestMatch (Context::NoMatch);
      69         264 :     ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end());
      70             : 
      71        2706 :     for (::std::vector<Entry>::const_iterator
      72         264 :              iEntry(maEntries.begin()),
      73         264 :              iEnd(maEntries.end());
      74             :          iEntry!=iEnd;
      75             :          ++iEntry)
      76             :     {
      77        2453 :         const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext));
      78        2453 :         if (nMatch < nBestMatch)
      79             :         {
      80          88 :             nBestMatch = nMatch;
      81          88 :             iBestMatch = iEntry;
      82             :         }
      83        2453 :         if (nBestMatch == Context::OptimalMatch)
      84          11 :             return iEntry;
      85             :     }
      86             : 
      87         253 :     return iBestMatch;
      88             : }
      89             : 
      90             : 
      91             : 
      92             : 
      93        1220 : void ContextList::AddContextDescription (
      94             :     const Context& rContext,
      95             :     const bool bIsInitiallyVisible,
      96             :     const OUString& rsMenuCommand)
      97             : {
      98        1220 :     maEntries.push_back(Entry());
      99        1220 :     maEntries.back().maContext = rContext;
     100        1220 :     maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible;
     101        1220 :     maEntries.back().msMenuCommand = rsMenuCommand;
     102        1220 : }
     103             : 
     104             : 
     105             : 
     106             : 
     107             : } } // end of namespace sfx2::sidebar
     108             : 
     109             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10