LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - EnumContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 106 111 95.5 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
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 <osl/diagnose.h>
      22             : 
      23             : #include <map>
      24             : 
      25             : namespace sfx2 { namespace sidebar {
      26             : 
      27             : namespace {
      28             : 
      29             : typedef ::std::map<rtl::OUString,EnumContext::Application> ApplicationMap;
      30             : typedef ::std::vector<rtl::OUString> ApplicationVector;
      31         216 : static ApplicationMap maApplicationMap;
      32         216 : static ApplicationVector maApplicationVector;
      33             : 
      34             : typedef ::std::map<rtl::OUString,EnumContext::Context> ContextMap;
      35             : typedef ::std::vector<rtl::OUString> ContextVector;
      36         216 : static ContextMap maContextMap;
      37         216 : static ContextVector maContextVector;
      38             : 
      39             : }
      40             : 
      41             : const sal_Int32 EnumContext::NoMatch = 4;
      42             : const sal_Int32 EnumContext::OptimalMatch = 0;  // Neither application nor context name is "any".
      43             : 
      44        1281 : EnumContext::EnumContext()
      45             :     : meApplication(Application_None),
      46        1281 :       meContext(Context_Unknown)
      47             : {
      48        1281 : }
      49             : 
      50        1356 : EnumContext::EnumContext (
      51             :     const Application eApplication,
      52             :     const Context eContext)
      53             :     : meApplication(eApplication),
      54        1356 :       meContext(eContext)
      55             : {
      56        1356 : }
      57             : 
      58        3479 : EnumContext::EnumContext (
      59             :     const ::rtl::OUString& rsApplicationName,
      60             :     const ::rtl::OUString& rsContextName)
      61        3479 :     : meApplication(GetApplicationEnum(rsApplicationName)),
      62        3479 :       meContext(GetContextEnum(rsContextName))
      63             : {
      64        3479 : }
      65             : 
      66        2460 : sal_Int32 EnumContext::GetCombinedContext_DI() const
      67             : {
      68        2460 :     return CombinedEnumContext(GetApplication_DI(), meContext);
      69             : }
      70             : 
      71        3319 : EnumContext::Application EnumContext::GetApplication_DI() const
      72             : {
      73        3319 :      switch (meApplication)
      74             :      {
      75             :          case Application_Draw:
      76             :          case Application_Impress:
      77           5 :             return Application_DrawImpress;
      78             : 
      79             :          case Application_Writer:
      80             :          case Application_WriterGlobal:
      81             :          case Application_WriterWeb:
      82             :          case Application_WriterXML:
      83             :          case Application_WriterForm:
      84             :          case Application_WriterReport:
      85        2968 :              return Application_WriterVariants;
      86             : 
      87             :          default:
      88         346 :              return meApplication;
      89             :      }
      90             : }
      91             : 
      92        1356 : bool EnumContext::operator== (const EnumContext& rOther)
      93             : {
      94        1356 :     return meApplication==rOther.meApplication
      95        1356 :         && meContext==rOther.meContext;
      96             : }
      97             : 
      98           0 : bool EnumContext::operator!= (const EnumContext& rOther)
      99             : {
     100           0 :     return meApplication!=rOther.meApplication
     101           0 :         || meContext!=rOther.meContext;
     102             : }
     103             : 
     104        1078 : void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Application eApplication)
     105             : {
     106        1078 :     maApplicationMap[rsName] = eApplication;
     107             :     OSL_ASSERT(eApplication<=__LastApplicationEnum);
     108        1078 :     if (maApplicationVector.size() <= size_t(eApplication))
     109           0 :         maApplicationVector.resize(eApplication+1);
     110        1078 :     maApplicationVector[eApplication]=rsName;
     111        1078 : }
     112             : 
     113       58605 : void EnumContext::ProvideApplicationContainers()
     114             : {
     115       58605 :     if (maApplicationMap.empty())
     116             :     {
     117          98 :         maApplicationVector.resize(static_cast<size_t>(EnumContext::__LastApplicationEnum)+1);
     118          98 :         AddEntry(OUString("com.sun.star.text.TextDocument"), EnumContext::Application_Writer);
     119          98 :         AddEntry(OUString("com.sun.star.text.GlobalDocument"), EnumContext::Application_WriterGlobal);
     120          98 :         AddEntry(OUString("com.sun.star.text.WebDocument"), EnumContext::Application_WriterWeb);
     121          98 :         AddEntry(OUString("com.sun.star.xforms.XMLFormDocument"), EnumContext::Application_WriterXML);
     122          98 :         AddEntry(OUString("com.sun.star.sdb.FormDesign"), EnumContext::Application_WriterForm);
     123          98 :         AddEntry(OUString("com.sun.star.sdb.TextReportDesign"), EnumContext::Application_WriterReport);
     124          98 :         AddEntry(OUString("com.sun.star.sheet.SpreadsheetDocument"), EnumContext::Application_Calc);
     125          98 :         AddEntry(OUString("com.sun.star.drawing.DrawingDocument"), EnumContext::Application_Draw);
     126          98 :         AddEntry(OUString("com.sun.star.presentation.PresentationDocument"), EnumContext::Application_Impress);
     127             : 
     128          98 :         AddEntry(OUString("any"), EnumContext::Application_Any);
     129          98 :         AddEntry(OUString("none"), EnumContext::Application_None);
     130             :     }
     131       58605 : }
     132             : 
     133       17348 : EnumContext::Application EnumContext::GetApplicationEnum (const ::rtl::OUString& rsApplicationName)
     134             : {
     135       17348 :     ProvideApplicationContainers();
     136             : 
     137             :     ApplicationMap::const_iterator iApplication(
     138       17348 :         maApplicationMap.find(rsApplicationName));
     139       17348 :     if (iApplication != maApplicationMap.end())
     140        2897 :         return iApplication->second;
     141             :     else
     142       14451 :         return EnumContext::Application_None;
     143             : }
     144             : 
     145       41257 : const ::rtl::OUString& EnumContext::GetApplicationName (const Application eApplication)
     146             : {
     147       41257 :     ProvideApplicationContainers();
     148             : 
     149       41257 :     const sal_Int32 nIndex (eApplication);
     150       41257 :     if (nIndex<0 || nIndex>= __LastApplicationEnum)
     151       11963 :         return maApplicationVector[Application_None];
     152             :     else
     153       29294 :         return maApplicationVector[nIndex];
     154             : }
     155             : 
     156        2800 : void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Context eApplication)
     157             : {
     158        2800 :     maContextMap[rsName] = eApplication;
     159             :     OSL_ASSERT(eApplication<=__LastContextEnum);
     160        2800 :     if (maContextVector.size() <= size_t(eApplication))
     161           0 :         maContextVector.resize(eApplication+1);
     162        2800 :     maContextVector[eApplication] = rsName;
     163        2800 : }
     164             : 
     165       62387 : void EnumContext::ProvideContextContainers()
     166             : {
     167       62387 :     if (maContextMap.empty())
     168             :     {
     169         100 :         maContextVector.resize(static_cast<size_t>(__LastContextEnum)+1);
     170         100 :         AddEntry(OUString("any"), Context_Any);
     171         100 :         AddEntry(OUString("default"), Context_Default);
     172         100 :         AddEntry(OUString("empty"), Context_Empty);
     173             : #define AddContext(context) AddEntry(OUString(#context), Context_##context);
     174         100 :         AddContext(3DObject);
     175         100 :         AddContext(Annotation);
     176         100 :         AddContext(Auditing);
     177         100 :         AddContext(Cell);
     178         100 :         AddContext(Chart);
     179         100 :         AddContext(Chart);
     180         100 :         AddContext(Draw);
     181         100 :         AddContext(DrawPage);
     182         100 :         AddContext(DrawText);
     183         100 :         AddContext(EditCell);
     184         100 :         AddContext(Form);
     185         100 :         AddContext(Frame);
     186         100 :         AddContext(Graphic);
     187         100 :         AddContext(HandoutPage);
     188         100 :         AddContext(MasterPage);
     189         100 :         AddContext(Media);
     190         100 :         AddContext(MultiObject);
     191         100 :         AddContext(NotesPage);
     192         100 :         AddContext(OLE);
     193         100 :         AddContext(OutlineText);
     194         100 :         AddContext(Pivot);
     195         100 :         AddContext(SlidesorterPage);
     196         100 :         AddContext(Table);
     197         100 :         AddContext(Text);
     198         100 :         AddContext(TextObject);
     199             : #undef AddContext
     200             :     }
     201       62387 : }
     202             : 
     203       20949 : EnumContext::Context EnumContext::GetContextEnum (const ::rtl::OUString& rsContextName)
     204             : {
     205       20949 :     ProvideContextContainers();
     206             : 
     207             :     ContextMap::const_iterator iContext(
     208       20949 :         maContextMap.find(rsContextName));
     209       20949 :     if (iContext != maContextMap.end())
     210       17792 :         return iContext->second;
     211             :     else
     212        3157 :         return EnumContext::Context_Unknown;
     213             : }
     214             : 
     215       41438 : const ::rtl::OUString& EnumContext::GetContextName (const Context eContext)
     216             : {
     217       41438 :     ProvideContextContainers();
     218             : 
     219       41438 :     const sal_Int32 nIndex (eContext);
     220       41438 :     if (nIndex<0 || nIndex>= __LastContextEnum)
     221           2 :         return maContextVector[Context_Unknown];
     222             :     else
     223       41436 :         return maContextVector[nIndex];
     224             : }
     225             : 
     226         648 : } } // end of namespace sfx2::sidebar
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11