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