LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - EnumContext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 86 115 74.8 %
Date: 2014-04-11 Functions: 10 19 52.6 %
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 <sfx2/sidebar/EnumContext.hxx>
      20             : 
      21             : #include <map>
      22             : 
      23             : namespace sfx2 { namespace sidebar {
      24             : 
      25             : namespace {
      26             : 
      27             : typedef ::std::map<rtl::OUString,EnumContext::Application> ApplicationMap;
      28             : typedef ::std::vector<rtl::OUString> ApplicationVector;
      29         149 : static ApplicationMap maApplicationMap;
      30         149 : static ApplicationVector maApplicationVector;
      31             : 
      32             : typedef ::std::map<rtl::OUString,EnumContext::Context> ContextMap;
      33             : typedef ::std::vector<rtl::OUString> ContextVector;
      34         149 : static ContextMap maContextMap;
      35         149 : static ContextVector maContextVector;
      36             : 
      37             : }
      38             : 
      39             : const sal_Int32 EnumContext::NoMatch = 4;
      40             : const sal_Int32 EnumContext::OptimalMatch = 0;  // Neither application nor context name is "any".
      41             : 
      42             : 
      43           0 : EnumContext::EnumContext (void)
      44             :     : meApplication(Application_None),
      45           0 :       meContext(Context_Unknown)
      46             : {
      47           0 : }
      48             : 
      49             : 
      50             : 
      51             : 
      52           0 : EnumContext::EnumContext (
      53             :     const Application eApplication,
      54             :     const Context eContext)
      55             :     : meApplication(eApplication),
      56           0 :       meContext(eContext)
      57             : {
      58           0 : }
      59             : 
      60             : 
      61             : 
      62             : 
      63           0 : EnumContext::EnumContext (
      64             :     const ::rtl::OUString& rsApplicationName,
      65             :     const ::rtl::OUString& rsContextName)
      66           0 :     : meApplication(GetApplicationEnum(rsApplicationName)),
      67           0 :       meContext(GetContextEnum(rsContextName))
      68             : {
      69           0 : }
      70             : 
      71             : 
      72             : 
      73             : 
      74           0 : sal_Int32 EnumContext::GetCombinedContext_DI (void) const
      75             : {
      76           0 :     return CombinedEnumContext(GetApplication_DI(), meContext);
      77             : }
      78             : 
      79             : 
      80             : 
      81             : 
      82           0 : EnumContext::Application EnumContext::GetApplication_DI (void) const
      83             : {
      84           0 :      switch (meApplication)
      85             :      {
      86             :          case Application_Draw:
      87             :          case Application_Impress:
      88           0 :             return Application_DrawImpress;
      89             : 
      90             :          case Application_Writer:
      91             :          case Application_WriterGlobal:
      92             :          case Application_WriterWeb:
      93             :          case Application_WriterXML:
      94             :          case Application_WriterForm:
      95             :          case Application_WriterReport:
      96           0 :              return Application_WriterVariants;
      97             : 
      98             :          default:
      99           0 :              return meApplication;
     100             :      }
     101             : }
     102             : 
     103             : 
     104             : 
     105             : 
     106           0 : const ::rtl::OUString& EnumContext::GetApplicationName (void) const
     107             : {
     108           0 :     return EnumContext::GetApplicationName(meApplication);
     109             : }
     110             : 
     111             : 
     112             : 
     113             : 
     114           0 : const ::rtl::OUString& EnumContext::GetContextName (void) const
     115             : {
     116           0 :     return EnumContext::GetContextName(meContext);
     117             : }
     118             : 
     119             : 
     120             : 
     121             : 
     122           0 : bool EnumContext::operator== (const EnumContext aOther)
     123             : {
     124           0 :     return meApplication==aOther.meApplication
     125           0 :         && meContext==aOther.meContext;
     126             : }
     127             : 
     128             : 
     129             : 
     130             : 
     131           0 : bool EnumContext::operator!= (const EnumContext aOther)
     132             : {
     133           0 :     return meApplication!=aOther.meApplication
     134           0 :         || meContext!=aOther.meContext;
     135             : }
     136             : 
     137             : 
     138             : 
     139             : 
     140         110 : void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Application eApplication)
     141             : {
     142         110 :     maApplicationMap[rsName] = eApplication;
     143             :     OSL_ASSERT(eApplication<=__LastApplicationEnum);
     144         110 :     if (maApplicationVector.size() <= size_t(eApplication))
     145           0 :         maApplicationVector.resize(eApplication+1);
     146         110 :     maApplicationVector[eApplication]=rsName;
     147         110 : }
     148             : 
     149             : 
     150             : 
     151             : 
     152        2444 : void EnumContext::ProvideApplicationContainers (void)
     153             : {
     154        2444 :     if (maApplicationMap.empty())
     155             :     {
     156          10 :         maApplicationVector.resize(static_cast<size_t>(EnumContext::__LastApplicationEnum)+1);
     157          10 :         AddEntry(OUString("com.sun.star.text.TextDocument"), EnumContext::Application_Writer);
     158          10 :         AddEntry(OUString("com.sun.star.text.GlobalDocument"), EnumContext::Application_WriterGlobal);
     159          10 :         AddEntry(OUString("com.sun.star.text.WebDocument"), EnumContext::Application_WriterWeb);
     160          10 :         AddEntry(OUString("com.sun.star.xforms.XMLFormDocument"), EnumContext::Application_WriterXML);
     161          10 :         AddEntry(OUString("com.sun.star.sdb.FormDesign"), EnumContext::Application_WriterForm);
     162          10 :         AddEntry(OUString("com.sun.star.sdb.TextReportDesign"), EnumContext::Application_WriterReport);
     163          10 :         AddEntry(OUString("com.sun.star.sheet.SpreadsheetDocument"), EnumContext::Application_Calc);
     164          10 :         AddEntry(OUString("com.sun.star.drawing.DrawingDocument"), EnumContext::Application_Draw);
     165          10 :         AddEntry(OUString("com.sun.star.presentation.PresentationDocument"), EnumContext::Application_Impress);
     166             : 
     167          10 :         AddEntry(OUString("any"), EnumContext::Application_Any);
     168          10 :         AddEntry(OUString("none"), EnumContext::Application_None);
     169             :     }
     170        2444 : }
     171             : 
     172             : 
     173             : 
     174             : 
     175         595 : EnumContext::Application EnumContext::GetApplicationEnum (const ::rtl::OUString& rsApplicationName)
     176             : {
     177         595 :     ProvideApplicationContainers();
     178             : 
     179             :     ApplicationMap::const_iterator iApplication(
     180         595 :         maApplicationMap.find(rsApplicationName));
     181         595 :     if (iApplication != maApplicationMap.end())
     182          45 :         return iApplication->second;
     183             :     else
     184         550 :         return EnumContext::Application_None;
     185             : }
     186             : 
     187             : 
     188             : 
     189             : 
     190        1849 : const ::rtl::OUString& EnumContext::GetApplicationName (const Application eApplication)
     191             : {
     192        1849 :     ProvideApplicationContainers();
     193             : 
     194        1849 :     const sal_Int32 nIndex (eApplication);
     195        1849 :     if (nIndex<0 || nIndex>= __LastApplicationEnum)
     196         629 :         return maApplicationVector[Application_None];
     197             :     else
     198        1220 :         return maApplicationVector[nIndex];
     199             : }
     200             : 
     201             : 
     202             : 
     203             : 
     204        1764 : void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Context eApplication)
     205             : {
     206        1764 :     maContextMap[rsName] = eApplication;
     207             :     OSL_ASSERT(eApplication<=__LastContextEnum);
     208        1764 :     if (maContextVector.size() <= size_t(eApplication))
     209           0 :         maContextVector.resize(eApplication+1);
     210        1764 :     maContextVector[eApplication] = rsName;
     211        1764 : }
     212             : 
     213             : 
     214             : 
     215             : 
     216        7672 : void EnumContext::ProvideContextContainers (void)
     217             : {
     218        7672 :     if (maContextMap.empty())
     219             :     {
     220          63 :         maContextVector.resize(static_cast<size_t>(__LastContextEnum)+1);
     221          63 :         AddEntry(OUString("any"), Context_Any);
     222          63 :         AddEntry(OUString("default"), Context_Default);
     223          63 :         AddEntry(OUString("empty"), Context_Empty);
     224             : #define AddContext(context) AddEntry(OUString(#context), Context_##context);
     225          63 :         AddContext(3DObject);
     226          63 :         AddContext(Annotation);
     227          63 :         AddContext(Auditing);
     228          63 :         AddContext(Cell);
     229          63 :         AddContext(Chart);
     230          63 :         AddContext(Chart);
     231          63 :         AddContext(Draw);
     232          63 :         AddContext(DrawPage);
     233          63 :         AddContext(DrawText);
     234          63 :         AddContext(EditCell);
     235          63 :         AddContext(Form);
     236          63 :         AddContext(Frame);
     237          63 :         AddContext(Graphic);
     238          63 :         AddContext(HandoutPage);
     239          63 :         AddContext(MasterPage);
     240          63 :         AddContext(Media);
     241          63 :         AddContext(MultiObject);
     242          63 :         AddContext(NotesPage);
     243          63 :         AddContext(OLE);
     244          63 :         AddContext(OutlineText);
     245          63 :         AddContext(Pivot);
     246          63 :         AddContext(SlidesorterPage);
     247          63 :         AddContext(Table);
     248          63 :         AddContext(Text);
     249          63 :         AddContext(TextObject);
     250             : #undef AddContext
     251             :     }
     252        7672 : }
     253             : 
     254             : 
     255             : 
     256             : 
     257         813 : EnumContext::Context EnumContext::GetContextEnum (const ::rtl::OUString& rsContextName)
     258             : {
     259         813 :     ProvideContextContainers();
     260             : 
     261             :     ContextMap::const_iterator iContext(
     262         813 :         maContextMap.find(rsContextName));
     263         813 :     if (iContext != maContextMap.end())
     264         806 :         return iContext->second;
     265             :     else
     266           7 :         return EnumContext::Context_Unknown;
     267             : }
     268             : 
     269             : 
     270             : 
     271             : 
     272        6859 : const ::rtl::OUString& EnumContext::GetContextName (const Context eContext)
     273             : {
     274        6859 :     ProvideContextContainers();
     275             : 
     276        6859 :     const sal_Int32 nIndex (eContext);
     277        6859 :     if (nIndex<0 || nIndex>= __LastContextEnum)
     278           2 :         return maContextVector[Context_Unknown];
     279             :     else
     280        6857 :         return maContextVector[nIndex];
     281             : }
     282             : 
     283             : 
     284         447 : } } // end of namespace sfx2::sidebar
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10