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 : #ifndef INCLUDED_FRAMEWORK_INC_STDTYPES_H
21 : #define INCLUDED_FRAMEWORK_INC_STDTYPES_H
22 :
23 : #include <algorithm>
24 : #include <queue>
25 : #include <unordered_map>
26 : #include <vector>
27 :
28 : #include "general.h"
29 :
30 : #include <com/sun/star/awt/KeyEvent.hpp>
31 :
32 : #include <cppuhelper/interfacecontainer.hxx>
33 : #include <rtl/ustring.hxx>
34 :
35 : namespace framework{
36 :
37 : /**
38 : Own hash functions used for stl-structures ... e.g. hash tables/maps ...
39 : */
40 :
41 : struct ShortHashCode
42 : {
43 9964 : size_t operator()( const ::sal_Int16& nShort ) const
44 : {
45 9964 : return (size_t)nShort;
46 : }
47 : };
48 :
49 : struct Int32HashCode
50 : {
51 0 : size_t operator()( const ::sal_Int32& nValue ) const
52 : {
53 0 : return (size_t)nValue;
54 : }
55 : };
56 :
57 : struct KeyEventHashCode
58 : {
59 107726 : size_t operator()( const css::awt::KeyEvent& aEvent ) const
60 : {
61 107726 : return (size_t)(aEvent.KeyCode +
62 : //aEvent.KeyChar +
63 : //aEvent.KeyFunc +
64 107726 : aEvent.Modifiers);
65 : }
66 : };
67 :
68 : struct KeyEventEqualsFunc
69 : {
70 22408 : bool operator()(const css::awt::KeyEvent& rKey1,
71 : const css::awt::KeyEvent& rKey2) const
72 : {
73 : return (
74 22408 : (rKey1.KeyCode == rKey2.KeyCode ) &&
75 : //(rKey1.KeyChar == rKey2.KeyChar ) &&
76 : //(rKey1.KeyFunc == rKey2.KeyFunc ) &&
77 0 : (rKey1.Modifiers == rKey2.Modifiers)
78 22408 : );
79 : }
80 : };
81 :
82 : typedef ::std::vector< OUString > OUStringList;
83 :
84 : // search for given element
85 : template <class T>
86 62723 : typename std::vector<T>::iterator find( std::vector<T>& vec, const T& sElement )
87 : {
88 62723 : return ::std::find(vec.begin(), vec.end(), sElement);
89 : }
90 :
91 : template <class T>
92 : typename std::vector<T>::const_iterator find( const std::vector<T>& vec, const T& sElement )
93 : {
94 : return ::std::find(vec.begin(), vec.end(), sElement);
95 : }
96 :
97 : template <class T>
98 : void free(std::vector<T>& vec)
99 : {
100 : OUStringList().swap(vec);
101 : }
102 :
103 : /**
104 : Basic hash based on a std::unordered_map() which provides key=[OUString] and value=[template type] pairs
105 : It implements some additional funtionality which can be useful but
106 : is missing at the normal hash implementation.
107 : */
108 : template< class TType >
109 77641 : class BaseHash : public std::unordered_map< OUString ,
110 : TType ,
111 : OUStringHash ,
112 : std::equal_to< OUString > >
113 : {
114 : public:
115 :
116 : // the only way to free used memory really!
117 3678 : void free()
118 : {
119 3678 : BaseHash().swap( *this );// get rid of reserved capacity
120 3678 : }
121 : };
122 :
123 : /**
124 : Basic OUString hash.
125 : Key and values are OUStrings.
126 : */
127 : typedef BaseHash< OUString > OUStringHashMap;
128 :
129 : /**
130 : It can be used to map names (e.g. of properties) to her corresponding handles.
131 : Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name.
132 : Mapping between these two parts of a property should be done in the fastest way :-)
133 : */
134 :
135 : typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString> ListenerHash;
136 :
137 : } // namespace framework
138 :
139 : #endif // INCLUDED_FRAMEWORK_INC_STDTYPES_H
140 :
141 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|