LCOV - code coverage report
Current view: top level - libreoffice/svx/source/customshapes - EnhancedCustomShapeTypeNames.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 31 100.0 %
Date: 2012-12-27 Functions: 5 5 100.0 %
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             : 
      20             : #include "svx/EnhancedCustomShapeTypeNames.hxx"
      21             : #include <osl/mutex.hxx>
      22             : #include <boost/unordered_map.hpp>
      23             : 
      24             : struct THash
      25             : {
      26        3276 :     size_t operator()( const char* s ) const
      27             :     {
      28        3276 :         return rtl_str_hashCode(s);
      29             :     }
      30             : };
      31             : struct TCheck
      32             : {
      33        1635 :     bool operator()( const char* s1, const char* s2 ) const
      34             :     {
      35        1635 :         return strcmp( s1, s2 ) == 0;
      36             :     }
      37             : };
      38             : typedef boost::unordered_map< const char*, MSO_SPT, THash, TCheck> TypeNameHashMap;
      39             : static TypeNameHashMap* pHashMap = NULL;
      40           8 : static ::osl::Mutex& getHashMapMutex()
      41             : {
      42           8 :     static osl::Mutex s_aHashMapProtection;
      43           8 :     return s_aHashMapProtection;
      44             : }
      45             : 
      46             : struct NameTypeTable
      47             : {
      48             :     const char* pS;
      49             :     MSO_SPT     pE;
      50             : };
      51             : static const NameTypeTable pNameTypeTableArray[] =
      52             : {
      53             :     { "non-primitive", mso_sptMin },
      54             :     { "rectangle", mso_sptRectangle },
      55             :     { "round-rectangle", mso_sptRoundRectangle },
      56             :     { "ellipse", mso_sptEllipse },
      57             :     { "diamond", mso_sptDiamond },
      58             :     { "isosceles-triangle", mso_sptIsocelesTriangle },
      59             :     { "right-triangle", mso_sptRightTriangle },
      60             :     { "parallelogram", mso_sptParallelogram },
      61             :     { "trapezoid", mso_sptTrapezoid },
      62             :     { "hexagon", mso_sptHexagon },
      63             :     { "octagon", mso_sptOctagon },
      64             :     { "cross", mso_sptPlus },
      65             :     { "star5", mso_sptStar },
      66             :     { "right-arrow", mso_sptArrow },
      67             :     { "mso-spt14", mso_sptThickArrow },
      68             :     { "pentagon-right", mso_sptHomePlate },
      69             :     { "cube", mso_sptCube },
      70             :     { "mso-spt17", mso_sptBalloon },
      71             :     { "mso-spt18", mso_sptSeal },
      72             :     { "mso-spt19", mso_sptArc },
      73             :     { "mso-spt20", mso_sptLine },
      74             :     { "mso-spt21", mso_sptPlaque },
      75             :     { "can", mso_sptCan },
      76             :     { "ring", mso_sptDonut },
      77             :     { "mso-spt24", mso_sptTextSimple },
      78             :     { "mso-spt25", mso_sptTextOctagon },
      79             :     { "mso-spt26", mso_sptTextHexagon },
      80             :     { "mso-spt27", mso_sptTextCurve },
      81             :     { "mso-spt28", mso_sptTextWave },
      82             :     { "mso-spt29", mso_sptTextRing },
      83             :     { "mso-spt30", mso_sptTextOnCurve },
      84             :     { "mso-spt31", mso_sptTextOnRing },
      85             :     { "mso-spt32", mso_sptStraightConnector1 },
      86             :     { "mso-spt33", mso_sptBentConnector2 },
      87             :     { "mso-spt34", mso_sptBentConnector3 },
      88             :     { "mso-spt35", mso_sptBentConnector4 },
      89             :     { "mso-spt36", mso_sptBentConnector5 },
      90             :     { "mso-spt37", mso_sptCurvedConnector2 },
      91             :     { "mso-spt38", mso_sptCurvedConnector3 },
      92             :     { "mso-spt39", mso_sptCurvedConnector4 },
      93             :     { "mso-spt40", mso_sptCurvedConnector5 },
      94             :     { "mso-spt41", mso_sptCallout1 },
      95             :     { "mso-spt42", mso_sptCallout2 },
      96             :     { "mso-spt43", mso_sptCallout3 },
      97             :     { "mso-spt44", mso_sptAccentCallout1 },
      98             :     { "mso-spt45", mso_sptAccentCallout2 },
      99             :     { "mso-spt46", mso_sptAccentCallout3 },
     100             :     { "line-callout-1", mso_sptBorderCallout1 },
     101             :     { "line-callout-2", mso_sptBorderCallout2 },
     102             :     { "mso-spt49", mso_sptBorderCallout3 },
     103             :     { "mso-spt50", mso_sptAccentBorderCallout1 },
     104             :     { "mso-spt51", mso_sptAccentBorderCallout2 },
     105             :     { "mso-spt52", mso_sptAccentBorderCallout3 },
     106             :     { "mso-spt53", mso_sptRibbon },
     107             :     { "mso-spt54", mso_sptRibbon2 },
     108             :     { "chevron", mso_sptChevron },
     109             :     { "pentagon", mso_sptPentagon },
     110             :     { "forbidden", mso_sptNoSmoking },
     111             :     { "star8", mso_sptSeal8 },
     112             :     { "mso-spt59", mso_sptSeal16 },
     113             :     { "mso-spt60", mso_sptSeal32 },
     114             :     { "rectangular-callout", mso_sptWedgeRectCallout },
     115             :     { "round-rectangular-callout", mso_sptWedgeRRectCallout },
     116             :     { "round-callout", mso_sptWedgeEllipseCallout },
     117             :     { "mso-spt64", mso_sptWave },
     118             :     { "paper", mso_sptFoldedCorner },
     119             :     { "left-arrow", mso_sptLeftArrow },
     120             :     { "down-arrow", mso_sptDownArrow },
     121             :     { "up-arrow", mso_sptUpArrow },
     122             :     { "left-right-arrow", mso_sptLeftRightArrow },
     123             :     { "up-down-arrow", mso_sptUpDownArrow },
     124             :     { "mso-spt71", mso_sptIrregularSeal1 },
     125             :     { "bang", mso_sptIrregularSeal2 },
     126             :     { "lightning", mso_sptLightningBolt },
     127             :     { "heart", mso_sptHeart },
     128             :     { "mso-spt75", mso_sptPictureFrame },
     129             :     { "quad-arrow", mso_sptQuadArrow },
     130             :     { "left-arrow-callout", mso_sptLeftArrowCallout },
     131             :     { "right-arrow-callout", mso_sptRightArrowCallout },
     132             :     { "up-arrow-callout", mso_sptUpArrowCallout },
     133             :     { "down-arrow-callout", mso_sptDownArrowCallout },
     134             :     { "left-right-arrow-callout", mso_sptLeftRightArrowCallout },
     135             :     { "up-down-arrow-callout", mso_sptUpDownArrowCallout },
     136             :     { "quad-arrow-callout", mso_sptQuadArrowCallout },
     137             :     { "quad-bevel", mso_sptBevel },
     138             :     { "left-bracket", mso_sptLeftBracket },
     139             :     { "right-bracket", mso_sptRightBracket },
     140             :     { "left-brace", mso_sptLeftBrace },
     141             :     { "right-brace", mso_sptRightBrace },
     142             :     { "mso-spt89", mso_sptLeftUpArrow },
     143             :     { "mso-spt90", mso_sptBentUpArrow },
     144             :     { "mso-spt91", mso_sptBentArrow },
     145             :     { "star24", mso_sptSeal24 },
     146             :     { "striped-right-arrow", mso_sptStripedRightArrow },
     147             :     { "notched-right-arrow", mso_sptNotchedRightArrow },
     148             :     { "block-arc", mso_sptBlockArc },
     149             :     { "smiley", mso_sptSmileyFace },
     150             :     { "vertical-scroll", mso_sptVerticalScroll },
     151             :     { "horizontal-scroll", mso_sptHorizontalScroll },
     152             :     { "circular-arrow", mso_sptCircularArrow },
     153             :     { "mso-spt100", mso_sptNotchedCircularArrow },
     154             :     { "mso-spt101", mso_sptUturnArrow },
     155             :     { "mso-spt102", mso_sptCurvedRightArrow },
     156             :     { "mso-spt103", mso_sptCurvedLeftArrow },
     157             :     { "mso-spt104", mso_sptCurvedUpArrow },
     158             :     { "mso-spt105", mso_sptCurvedDownArrow },
     159             :     { "cloud-callout", mso_sptCloudCallout },
     160             :     { "mso-spt107", mso_sptEllipseRibbon },
     161             :     { "mso-spt108", mso_sptEllipseRibbon2 },
     162             :     { "flowchart-process", mso_sptFlowChartProcess },
     163             :     { "flowchart-decision", mso_sptFlowChartDecision },
     164             :     { "flowchart-data", mso_sptFlowChartInputOutput },
     165             :     { "flowchart-predefined-process", mso_sptFlowChartPredefinedProcess },
     166             :     { "flowchart-internal-storage", mso_sptFlowChartInternalStorage },
     167             :     { "flowchart-document", mso_sptFlowChartDocument },
     168             :     { "flowchart-multidocument", mso_sptFlowChartMultidocument },
     169             :     { "flowchart-terminator", mso_sptFlowChartTerminator },
     170             :     { "flowchart-preparation", mso_sptFlowChartPreparation },
     171             :     { "flowchart-manual-input", mso_sptFlowChartManualInput },
     172             :     { "flowchart-manual-operation", mso_sptFlowChartManualOperation },
     173             :     { "flowchart-connector", mso_sptFlowChartConnector },
     174             :     { "flowchart-card", mso_sptFlowChartPunchedCard },
     175             :     { "flowchart-punched-tape", mso_sptFlowChartPunchedTape },
     176             :     { "flowchart-summing-junction", mso_sptFlowChartSummingJunction },
     177             :     { "flowchart-or", mso_sptFlowChartOr },
     178             :     { "flowchart-collate", mso_sptFlowChartCollate },
     179             :     { "flowchart-sort", mso_sptFlowChartSort },
     180             :     { "flowchart-extract", mso_sptFlowChartExtract },
     181             :     { "flowchart-merge", mso_sptFlowChartMerge },
     182             :     { "mso-spt129", mso_sptFlowChartOfflineStorage },
     183             :     { "flowchart-stored-data", mso_sptFlowChartOnlineStorage },
     184             :     { "flowchart-sequential-access", mso_sptFlowChartMagneticTape },
     185             :     { "flowchart-magnetic-disk", mso_sptFlowChartMagneticDisk },
     186             :     { "flowchart-direct-access-storage", mso_sptFlowChartMagneticDrum },
     187             :     { "flowchart-display", mso_sptFlowChartDisplay },
     188             :     { "flowchart-delay", mso_sptFlowChartDelay },
     189             :     { "fontwork-plain-text", mso_sptTextPlainText },
     190             :     { "fontwork-stop", mso_sptTextStop },
     191             :     { "fontwork-triangle-up", mso_sptTextTriangle },
     192             :     { "fontwork-triangle-down", mso_sptTextTriangleInverted },
     193             :     { "fontwork-chevron-up", mso_sptTextChevron },
     194             :     { "fontwork-chevron-down", mso_sptTextChevronInverted },
     195             :     { "mso-spt142", mso_sptTextRingInside },
     196             :     { "mso-spt143", mso_sptTextRingOutside },
     197             :     { "fontwork-arch-up-curve", mso_sptTextArchUpCurve },
     198             :     { "fontwork-arch-down-curve", mso_sptTextArchDownCurve },
     199             :     { "fontwork-circle-curve", mso_sptTextCircleCurve },
     200             :     { "fontwork-open-circle-curve", mso_sptTextButtonCurve },
     201             :     { "fontwork-arch-up-pour", mso_sptTextArchUpPour },
     202             :     { "fontwork-arch-down-pour", mso_sptTextArchDownPour },
     203             :     { "fontwork-circle-pour", mso_sptTextCirclePour },
     204             :     { "fontwork-open-circle-pour", mso_sptTextButtonPour },
     205             :     { "fontwork-curve-up", mso_sptTextCurveUp },
     206             :     { "fontwork-curve-down", mso_sptTextCurveDown },
     207             :     { "fontwork-fade-up-and-right", mso_sptTextCascadeUp },
     208             :     { "fontwork-fade-up-and-left", mso_sptTextCascadeDown },
     209             :     { "fontwork-wave", mso_sptTextWave1 },
     210             :     { "mso-spt157", mso_sptTextWave2 },
     211             :     { "mso-spt158", mso_sptTextWave3 },
     212             :     { "mso-spt159", mso_sptTextWave4 },
     213             :     { "fontwork-inflate", mso_sptTextInflate },
     214             :     { "mso-spt161", mso_sptTextDeflate },
     215             :     { "mso-spt162", mso_sptTextInflateBottom },
     216             :     { "mso-spt163", mso_sptTextDeflateBottom },
     217             :     { "mso-spt164", mso_sptTextInflateTop },
     218             :     { "mso-spt165", mso_sptTextDeflateTop },
     219             :     { "mso-spt166", mso_sptTextDeflateInflate },
     220             :     { "mso-spt167", mso_sptTextDeflateInflateDeflate },
     221             :     { "fontwork-fade-right", mso_sptTextFadeRight },
     222             :     { "fontwork-fade-left", mso_sptTextFadeLeft },
     223             :     { "fontwork-fade-up", mso_sptTextFadeUp },
     224             :     { "fontwork-fade-down", mso_sptTextFadeDown },
     225             :     { "fontwork-slant-up", mso_sptTextSlantUp },
     226             :     { "fontwork-slant-down", mso_sptTextSlantDown },
     227             :     { "mso-spt174", mso_sptTextCanUp },
     228             :     { "mso-spt175", mso_sptTextCanDown },
     229             :     { "flowchart-alternate-process", mso_sptFlowChartAlternateProcess },
     230             :     { "flowchart-off-page-connector", mso_sptFlowChartOffpageConnector },
     231             :     { "mso-spt178", mso_sptCallout90 },
     232             :     { "mso-spt179", mso_sptAccentCallout90 },
     233             :     { "mso-spt180", mso_sptBorderCallout90 },
     234             :     { "line-callout-3", mso_sptAccentBorderCallout90 },
     235             :     { "mso-spt182", mso_sptLeftRightUpArrow },
     236             :     { "sun", mso_sptSun },
     237             :     { "moon", mso_sptMoon },
     238             :     { "bracket-pair", mso_sptBracketPair },
     239             :     { "brace-pair", mso_sptBracePair },
     240             :     { "star4", mso_sptSeal4 },
     241             :     { "mso-spt188", mso_sptDoubleWave },
     242             :     { "mso-spt189", mso_sptActionButtonBlank },
     243             :     { "mso-spt190", mso_sptActionButtonHome },
     244             :     { "mso-spt191", mso_sptActionButtonHelp },
     245             :     { "mso-spt192", mso_sptActionButtonInformation },
     246             :     { "mso-spt193", mso_sptActionButtonForwardNext },
     247             :     { "mso-spt194", mso_sptActionButtonBackPrevious },
     248             :     { "mso-spt195", mso_sptActionButtonEnd },
     249             :     { "mso-spt196", mso_sptActionButtonBeginning },
     250             :     { "mso-spt197", mso_sptActionButtonReturn },
     251             :     { "mso-spt198", mso_sptActionButtonDocument },
     252             :     { "mso-spt199", mso_sptActionButtonSound },
     253             :     { "mso-spt200", mso_sptActionButtonMovie },
     254             :     { "mso-spt201", mso_sptHostControl },
     255             :     { "mso-spt202", mso_sptTextBox }
     256             : };
     257             : 
     258             :     // gallery: quadrat
     259             :     // gallery: round-quadrat
     260             :     // gallery: circle
     261             :     // gallery: circle-pie
     262             :     // gallery: frame
     263             :     // gallery: flower
     264             :     // gallery: cloud
     265             :     // gallery: puzzle
     266             :     // gallery: octagon-bevel
     267             :     // gallery: diamond-bevel
     268             :     // gallery: up-right-arrow
     269             :     // gallery: up-right-down-arrow
     270             :     // gallery: corner-right-arrow
     271             :     // gallery: split-arrow
     272             :     // gallery: up-right-arrow-callout
     273             :     // gallery: split-round-arrow
     274             :     // gallery: s-sharped-arrow
     275             :     // Gallery: star6
     276             :     // Gallery: star12
     277             :     // Gallery: concave-star6
     278             :     // Gallery: signet
     279             :     // Gallery: doorplate
     280             :     // gallery: fontwork-arch-left-curve
     281             :     // gallery: fontwork-arch-right-curve
     282             :     // gallery: fontwork-arch-left-pour
     283             :     // gallery: fontwork-arch-right-pour
     284             : 
     285        1652 : MSO_SPT EnhancedCustomShapeTypeNames::Get( const rtl::OUString& rShapeType )
     286             : {
     287        1652 :     if ( !pHashMap )
     288             :     {   // init hash map
     289           8 :         ::osl::MutexGuard aGuard( getHashMapMutex() );
     290           8 :         if ( !pHashMap )
     291             :         {
     292           8 :             TypeNameHashMap* pH = new TypeNameHashMap;
     293           8 :             const NameTypeTable* pPtr = pNameTypeTableArray;
     294           8 :             const NameTypeTable* pEnd = pPtr + ( sizeof( pNameTypeTableArray ) / sizeof( NameTypeTable ) );
     295        1632 :             for ( ; pPtr < pEnd; pPtr++ )
     296        1624 :                 (*pH)[ pPtr->pS ] = pPtr->pE;
     297           8 :             pHashMap = pH;
     298           8 :         }
     299             :     }
     300        1652 :     MSO_SPT eRetValue = mso_sptNil;
     301        1652 :     int i, nLen = rShapeType.getLength();
     302        1652 :     char* pBuf = new char[ nLen + 1 ];
     303       16768 :     for ( i = 0; i < nLen; i++ )
     304       15116 :         pBuf[ i ] = (char)rShapeType[ i ];
     305        1652 :     pBuf[ i ] = 0;
     306        1652 :     TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
     307        1652 :     delete[] pBuf;
     308        1652 :     if ( aHashIter != pHashMap->end() )
     309        1635 :         eRetValue = (*aHashIter).second;
     310        1652 :     return eRetValue;
     311             : }
     312             : 
     313        1598 : rtl::OUString EnhancedCustomShapeTypeNames::Get( const MSO_SPT eShapeType )
     314             : {
     315             :     return eShapeType <= mso_sptTextBox
     316             :         ? rtl::OUString::createFromAscii( pNameTypeTableArray[ eShapeType ].pS )
     317        1598 :         : rtl::OUString();
     318             : }
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10