1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "pppoptimizertoken.hxx"
23 #include <sal/macros.h>
24 #include <unordered_map>
28 typedef std::unordered_map
< const char*, PPPOptimizerTokenEnum
, rtl::CStringHash
, rtl::CStringEqual
> TypeNameHashMap
;
29 static TypeNameHashMap
* pHashMap
= nullptr;
30 static std::mutex
& getHashMapMutex()
32 static std::mutex s_aHashMapProtection
;
33 return s_aHashMapProtection
;
41 PPPOptimizerTokenEnum pE
;
46 const TokenTable pTokenTableArray
[] =
48 { "btnNavFinish", TK_btnNavFinish
},
50 { "DocumentService", TK_DocumentService
},
51 { "FileSizeDestination",TK_FileSizeDestination
},
52 { "FileSizeSource", TK_FileSizeSource
},
53 { "FilterName", TK_FilterName
},
54 { "Flags", TK_Flags
},
55 { "DocumentFrame", TK_DocumentFrame
},
56 { "DialogParentWindow", TK_DialogParentWindow
},
58 { "Progress", TK_Progress
},
59 { "Settings", TK_Settings
},
60 { "StatusDispatcher", TK_StatusDispatcher
},
62 { "UIName", TK_UIName
},
64 { "JPEGCompression", TK_JPEGCompression
},
65 { "JPEGQuality", TK_JPEGQuality
},
66 { "RemoveCropArea", TK_RemoveCropArea
},
67 { "ImageResolution", TK_ImageResolution
},
68 { "EmbedLinkedGraphics",TK_EmbedLinkedGraphics
},
69 { "OLEOptimization", TK_OLEOptimization
},
70 { "OLEOptimizationType",TK_OLEOptimizationType
},
71 { "DeleteUnusedMasterPages", TK_DeleteUnusedMasterPages
},
72 { "DeleteHiddenSlides", TK_DeleteHiddenSlides
},
73 { "DeleteNotesPages", TK_DeleteNotesPages
},
74 { "CustomShowName", TK_CustomShowName
},
75 { "SaveAs", TK_SaveAs
},
76 { "SaveAsURL", TK_SaveAsURL
},
77 { "OpenNewDocument", TK_OpenNewDocument
},
78 { "EstimatedFileSize", TK_EstimatedFileSize
},
80 { "Status", TK_Status
},
81 { "Pages", TK_Pages
},
83 { "STR_SUN_OPTIMIZATION_WIZARD2",STR_SUN_OPTIMIZATION_WIZARD2
},
84 { "STR_INTRODUCTION", STR_INTRODUCTION
},
85 { "STR_IMAGE_OPTIMIZATION", STR_IMAGE_OPTIMIZATION
},
86 { "STR_OLE_OBJECTS", STR_OLE_OBJECTS
},
87 { "STR_OLE_OBJECTS_DESC", STR_OLE_OBJECTS_DESC
},
88 { "STR_NO_OLE_OBJECTS_DESC", STR_NO_OLE_OBJECTS_DESC
},
89 { "STR_SLIDES", STR_SLIDES
},
90 { "STR_SUMMARY", STR_SUMMARY
},
91 { "STR_DELETE_SLIDES", STR_DELETE_SLIDES
},
92 { "STR_OPTIMIZE_IMAGES", STR_OPTIMIZE_IMAGES
},
93 { "STR_CREATE_REPLACEMENT", STR_CREATE_REPLACEMENT
},
94 { "MY_SETTINGS", STR_MY_SETTINGS
},
96 { "STR_INFO_PRIMARY", STR_INFO_PRIMARY
},
97 { "STR_INFO_SECONDARY_1", STR_INFO_SECONDARY_1
},
98 { "STR_INFO_SECONDARY_2", STR_INFO_SECONDARY_2
},
99 { "STR_INFO_SECONDARY_3", STR_INFO_SECONDARY_3
},
100 { "STR_INFO_SECONDARY_4", STR_INFO_SECONDARY_4
},
101 { "STR_DUPLICATING_PRESENTATION",STR_DUPLICATING_PRESENTATION
},
102 { "STR_DELETING_SLIDES", STR_DELETING_SLIDES
},
103 { "STR_OPTIMIZING_GRAPHICS", STR_OPTIMIZING_GRAPHICS
},
104 { "STR_CREATING_OLE_REPLACEMENTS",STR_CREATING_OLE_REPLACEMENTS
},
105 { "STR_FileSizeSeparator", STR_FILESIZESEPARATOR
},
106 { "STR_FILENAME_SUFFIX", STR_FILENAME_SUFFIX
},
107 { "STR_WARN_UNSAVED_PRESENTATION", STR_WARN_UNSAVED_PRESENTATION
},
110 { "NotFound", TK_NotFound
}
113 PPPOptimizerTokenEnum
TKGet( std::u16string_view rToken
)
117 std::scoped_lock
aGuard( getHashMapMutex() );
120 TypeNameHashMap
* pH
= new TypeNameHashMap
;
121 const TokenTable
* pPtr
= pTokenTableArray
;
122 const TokenTable
* pEnd
= pPtr
+ SAL_N_ELEMENTS( pTokenTableArray
);
123 for ( ; pPtr
< pEnd
; pPtr
++ )
124 (*pH
)[ pPtr
->pS
] = pPtr
->pE
;
128 PPPOptimizerTokenEnum eRetValue
= TK_NotFound
;
129 size_t i
, nLen
= rToken
.size();
130 std::unique_ptr
<char[]> pBuf(new char[ nLen
+ 1 ]);
131 for ( i
= 0; i
< nLen
; i
++ )
132 pBuf
[ i
] = static_cast<char>(rToken
[ i
]);
134 TypeNameHashMap::iterator
aHashIter( pHashMap
->find( pBuf
.get() ) );
135 if ( aHashIter
!= pHashMap
->end() )
136 eRetValue
= (*aHashIter
).second
;
140 OUString
TKGet( const PPPOptimizerTokenEnum eToken
)
142 return OUString::createFromAscii( pTokenTableArray
[ eToken
].pS
);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */