LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ContextList.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 34 85.3 %
Date: 2014-11-03 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        2940 : ContextList::ContextList (void)
      28        2940 :     : maEntries()
      29             : {
      30        2940 : }
      31             : 
      32             : 
      33             : 
      34             : 
      35        2940 : ContextList::~ContextList (void)
      36             : {
      37        2940 : }
      38             : 
      39             : 
      40             : 
      41             : 
      42      169296 : const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const
      43             : {
      44      169296 :     const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext);
      45      169296 :     if (iEntry != maEntries.end())
      46       10242 :         return &*iEntry;
      47             :     else
      48      159054 :         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      169296 : ::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const
      67             : {
      68      169296 :     sal_Int32 nBestMatch (Context::NoMatch);
      69      169296 :     ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end());
      70             : 
      71     2427392 :     for (::std::vector<Entry>::const_iterator
      72      169296 :              iEntry(maEntries.begin()),
      73      169296 :              iEnd(maEntries.end());
      74             :          iEntry!=iEnd;
      75             :          ++iEntry)
      76             :     {
      77     2260406 :         const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext));
      78     2260406 :         if (nMatch < nBestMatch)
      79             :         {
      80       10242 :             nBestMatch = nMatch;
      81       10242 :             iBestMatch = iEntry;
      82             :         }
      83     2260406 :         if (nBestMatch == Context::OptimalMatch)
      84        2310 :             return iEntry;
      85             :     }
      86             : 
      87      166986 :     return iBestMatch;
      88             : }
      89             : 
      90             : 
      91             : 
      92             : 
      93       20832 : void ContextList::AddContextDescription (
      94             :     const Context& rContext,
      95             :     const bool bIsInitiallyVisible,
      96             :     const OUString& rsMenuCommand)
      97             : {
      98       20832 :     maEntries.push_back(Entry());
      99       20832 :     maEntries.back().maContext = rContext;
     100       20832 :     maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible;
     101       20832 :     maEntries.back().msMenuCommand = rsMenuCommand;
     102       20832 : }
     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