LibreOffice Module sdext (master)  1
pppoptimizertoken.cxx
Go to the documentation of this file.
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 
21 #include "pppoptimizertoken.hxx"
22 #include <osl/mutex.hxx>
23 #include <sal/macros.h>
24 #include <unordered_map>
25 #include <memory>
26 
27 typedef std::unordered_map< const char*, PPPOptimizerTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
28 static TypeNameHashMap* pHashMap = nullptr;
29 static ::osl::Mutex& getHashMapMutex()
30 {
31  static osl::Mutex s_aHashMapProtection;
32  return s_aHashMapProtection;
33 }
34 
35 namespace {
36 
37 struct TokenTable
38 {
39  const char* pS;
41 };
42 
43 }
44 
45 const TokenTable pTokenTableArray[] =
46 {
47  { "rdmNavi", TK_rdmNavi },
48  { "btnNavBack", TK_btnNavBack },
49  { "btnNavNext", TK_btnNavNext },
50  { "btnNavFinish", TK_btnNavFinish },
51  { "btnNavCancel", TK_btnNavCancel },
52 
53  { "Button0Pg0", TK_Button0Pg0 },
54  { "RadioButton0Pg1", TK_RadioButton0Pg1 },
55  { "RadioButton1Pg1", TK_RadioButton1Pg1 },
56  { "CheckBox1Pg1", TK_CheckBox1Pg1 },
57  { "CheckBox2Pg1", TK_CheckBox2Pg1 },
58  { "CheckBox0Pg2", TK_CheckBox0Pg2 },
59  { "RadioButton0Pg2", TK_RadioButton0Pg2 },
60  { "RadioButton1Pg2", TK_RadioButton1Pg2 },
61  { "CheckBox0Pg3", TK_CheckBox0Pg3 },
62  { "CheckBox1Pg3", TK_CheckBox1Pg3 },
63  { "CheckBox2Pg3", TK_CheckBox2Pg3 },
64  { "CheckBox3Pg3", TK_CheckBox3Pg3 },
65  { "RadioButton0Pg4", TK_RadioButton0Pg4 },
66  { "RadioButton1Pg4", TK_RadioButton1Pg4 },
67  { "CheckBox1Pg4", TK_CheckBox1Pg4 },
68 
69  { "DocumentService", TK_DocumentService },
70  { "FileSizeDestination",TK_FileSizeDestination },
71  { "FileSizeSource", TK_FileSizeSource },
72  { "FilterName", TK_FilterName },
73  { "Flags", TK_Flags },
74  { "InformationDialog", TK_InformationDialog },
75  { "Name", TK_Name },
76  { "Progress", TK_Progress },
77  { "Settings", TK_Settings },
78  { "StatusDispatcher", TK_StatusDispatcher },
79  { "Type", TK_Type },
80  { "UIName", TK_UIName },
81 
82  { "JPEGCompression", TK_JPEGCompression },
83  { "JPEGQuality", TK_JPEGQuality },
84  { "RemoveCropArea", TK_RemoveCropArea },
85  { "ImageResolution", TK_ImageResolution },
86  { "EmbedLinkedGraphics",TK_EmbedLinkedGraphics },
87  { "OLEOptimization", TK_OLEOptimization },
88  { "OLEOptimizationType",TK_OLEOptimizationType },
89  { "DeleteUnusedMasterPages", TK_DeleteUnusedMasterPages },
90  { "DeleteHiddenSlides", TK_DeleteHiddenSlides },
91  { "DeleteNotesPages", TK_DeleteNotesPages },
92  { "CustomShowName", TK_CustomShowName },
93  { "SaveAs", TK_SaveAs },
94  { "SaveAsURL", TK_SaveAsURL },
95  { "OpenNewDocument", TK_OpenNewDocument },
96  { "EstimatedFileSize", TK_EstimatedFileSize },
97 
98  { "Status", TK_Status },
99  { "Pages", TK_Pages },
100 
101  { "STR_SUN_OPTIMIZATION_WIZARD2",STR_SUN_OPTIMIZATION_WIZARD2 },
102  { "STR_STEPS", STR_STEPS },
103  { "STR_BACK", STR_BACK },
104  { "STR_NEXT", STR_NEXT },
105  { "STR_FINISH", STR_FINISH },
106  { "STR_CANCEL", STR_CANCEL },
107  { "STR_INTRODUCTION", STR_INTRODUCTION },
108  { "STR_INTRODUCTION_T", STR_INTRODUCTION_T },
109  { "STR_CHOSE_SETTINGS", STR_CHOSE_SETTINGS },
110  { "STR_REMOVE", STR_REMOVE },
111  { "STR_GRAPHIC_OPTIMIZATION", STR_GRAPHIC_OPTIMIZATION },
112  { "STR_IMAGE_OPTIMIZATION", STR_IMAGE_OPTIMIZATION },
113  { "STR_LOSSLESS_COMPRESSION", STR_LOSSLESS_COMPRESSION },
114  { "STR_JPEG_COMPRESSION", STR_JPEG_COMPRESSION },
115  { "STR_QUALITY", STR_QUALITY },
116  { "STR_REMOVE_CROP_AREA", STR_REMOVE_CROP_AREA },
117  { "STR_IMAGE_RESOLUTION", STR_IMAGE_RESOLUTION },
118  { "STR_IMAGE_RESOLUTION_0", STR_IMAGE_RESOLUTION_0 },
119  { "STR_IMAGE_RESOLUTION_1", STR_IMAGE_RESOLUTION_1 },
120  { "STR_IMAGE_RESOLUTION_2", STR_IMAGE_RESOLUTION_2 },
121  { "STR_IMAGE_RESOLUTION_3", STR_IMAGE_RESOLUTION_3 },
122  { "STR_EMBED_LINKED_GRAPHICS", STR_EMBED_LINKED_GRAPHICS },
123  { "STR_OLE_OBJECTS", STR_OLE_OBJECTS },
124  { "STR_OLE_OPTIMIZATION", STR_OLE_OPTIMIZATION },
125  { "STR_OLE_REPLACE", STR_OLE_REPLACE },
126  { "STR_ALL_OLE_OBJECTS", STR_ALL_OLE_OBJECTS },
127  { "STR_ALIEN_OLE_OBJECTS_ONLY", STR_ALIEN_OLE_OBJECTS_ONLY },
128  { "STR__OLE_OBJECTS_DESC", STR_OLE_OBJECTS_DESC },
129  { "STR_NO_OLE_OBJECTS_DESC", STR_NO_OLE_OBJECTS_DESC },
130  { "STR_SLIDES", STR_SLIDES },
131  { "STR_CHOOSE_SLIDES", STR_CHOOSE_SLIDES },
132  { "STR_DELETE_MASTER_PAGES", STR_DELETE_MASTER_PAGES },
133  { "STR_DELETE_NOTES_PAGES", STR_DELETE_NOTES_PAGES },
134  { "STR_DELETE_HIDDEN_SLIDES", STR_DELETE_HIDDEN_SLIDES },
135  { "STR_CUSTOM_SHOW", STR_CUSTOM_SHOW },
136  { "STR_SUMMARY", STR_SUMMARY },
137  { "STR_SUMMARY_TITLE", STR_SUMMARY_TITLE },
138  { "STR_APPLY_TO_CURRENT", STR_APPLY_TO_CURRENT },
139  { "STR_AUTOMATICALLY_OPEN", STR_AUTOMATICALLY_OPEN },
140  { "STR_SAVE_SETTINGS", STR_SAVE_SETTINGS },
141  { "STR_SAVE_AS", STR_SAVE_AS },
142  { "STR_DELETE_SLIDES", STR_DELETE_SLIDES },
143  { "STR_OPTIMIZE_IMAGES", STR_OPTIMIZE_IMAGES },
144  { "STR_CREATE_REPLACEMENT", STR_CREATE_REPLACEMENT },
145  { "STR_CURRENT_FILESIZE", STR_CURRENT_FILESIZE },
146  { "STR_ESTIMATED_FILESIZE", STR_ESTIMATED_FILESIZE },
147  { "MY_SETTINGS", STR_MY_SETTINGS },
148  { "STR_OK", STR_OK },
149  { "STR_INFO_1", STR_INFO_1 },
150  { "STR_INFO_2", STR_INFO_2 },
151  { "STR_INFO_3", STR_INFO_3 },
152  { "STR_INFO_4", STR_INFO_4 },
153  { "STR_DUPLICATING_PRESENTATION",STR_DUPLICATING_PRESENTATION },
154  { "STR_DELETING_SLIDES", STR_DELETING_SLIDES },
155  { "STR_OPTIMIZING_GRAPHICS", STR_OPTIMIZING_GRAPHICS },
156  { "STR_CREATING_OLE_REPLACEMENTS",STR_CREATING_OLE_REPLACEMENTS },
157  { "STR_FileSizeSeparator", STR_FILESIZESEPARATOR },
158  { "STR_FILENAME_SUFFIX", STR_FILENAME_SUFFIX },
159  { "STR_WARN_UNSAVED_PRESENTATION", STR_WARN_UNSAVED_PRESENTATION },
160 
161 
162  { "NotFound", TK_NotFound }
163 };
164 
165 PPPOptimizerTokenEnum TKGet( const OUString& rToken )
166 {
167  if ( !pHashMap )
168  { // init hash map
169  ::osl::MutexGuard aGuard( getHashMapMutex() );
170  if ( !pHashMap )
171  {
173  const TokenTable* pPtr = pTokenTableArray;
174  const TokenTable* pEnd = pPtr + SAL_N_ELEMENTS( pTokenTableArray );
175  for ( ; pPtr < pEnd; pPtr++ )
176  (*pH)[ pPtr->pS ] = pPtr->pE;
177  pHashMap = pH;
178  }
179  }
181  int i, nLen = rToken.getLength();
182  std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]);
183  for ( i = 0; i < nLen; i++ )
184  pBuf[ i ] = static_cast<char>(rToken[ i ]);
185  pBuf[ i ] = 0;
186  TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf.get() ) );
187  if ( aHashIter != pHashMap->end() )
188  eRetValue = (*aHashIter).second;
189  return eRetValue;
190 }
191 
192 OUString TKGet( const PPPOptimizerTokenEnum eToken )
193 {
194  return OUString::createFromAscii( pTokenTableArray[ eToken ].pS );
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< const char *, MSO_SPT, rtl::CStringHash, rtl::CStringEqual > TypeNameHashMap
FormulaCommand pE
PPPOptimizerTokenEnum
std::unordered_map< const char *, PPPOptimizerTokenEnum, rtl::CStringHash, rtl::CStringEqual > TypeNameHashMap
#define SAL_N_ELEMENTS(arr)
const TokenTable pTokenTableArray[]
int i
::osl::Mutex & getHashMapMutex()
const char * pS
static TypeNameHashMap * pHashMap
PPPOptimizerTokenEnum TKGet(const OUString &rToken)