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 <vector>
24 : #include <queue>
25 : #include <boost/unordered_map.hpp>
26 :
27 : #include "general.h"
28 :
29 : #include <com/sun/star/awt/KeyEvent.hpp>
30 :
31 : #include <comphelper/sequenceasvector.hxx>
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 15264 : size_t operator()( const ::sal_Int16& nShort ) const
44 : {
45 15264 : 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 241156 : size_t operator()( const css::awt::KeyEvent& aEvent ) const
60 : {
61 241156 : return (size_t)(aEvent.KeyCode +
62 : //aEvent.KeyChar +
63 : //aEvent.KeyFunc +
64 241156 : aEvent.Modifiers);
65 : }
66 : };
67 :
68 : struct KeyEventEqualsFunc
69 : {
70 41740 : bool operator()(const css::awt::KeyEvent aKey1,
71 : const css::awt::KeyEvent aKey2) const
72 : {
73 : return (
74 41740 : (aKey1.KeyCode == aKey2.KeyCode ) &&
75 : //(aKey1.KeyChar == aKey2.KeyChar ) &&
76 : //(aKey1.KeyFunc == aKey2.KeyFunc ) &&
77 0 : (aKey1.Modifiers == aKey2.Modifiers)
78 41740 : );
79 : }
80 : };
81 :
82 : /**
83 : Basic string list based on a std::vector()
84 : It implements some additional funtionality which can be useful but
85 : is missing at the normal vector implementation.
86 : */
87 415440 : class OUStringList : public ::comphelper::SequenceAsVector< OUString >
88 : {
89 : public:
90 :
91 : // insert given element as the first one into the vector
92 : void push_front( const OUString& sElement )
93 : {
94 : insert( begin(), sElement );
95 : }
96 :
97 : // search for given element
98 86603 : iterator find( const OUString& sElement )
99 : {
100 86603 : return ::std::find(begin(), end(), sElement);
101 : }
102 :
103 9922 : const_iterator findConst( const OUString& sElement ) const
104 : {
105 9922 : return ::std::find(begin(), end(), sElement);
106 : }
107 :
108 : // the only way to free used memory really!
109 : void free()
110 : {
111 : OUStringList().swap( *this );// get rid of reserved capacity
112 : }
113 : };
114 :
115 : /**
116 : Basic string queue based on a std::queue()
117 : It implements some additional funtionality which can be useful but
118 : is missing at the normal std implementation.
119 : */
120 : typedef ::std::queue< OUString > OUStringQueue;
121 :
122 : /**
123 : Basic hash based on a boost::unordered_map() which provides key=[OUString] and value=[template type] pairs
124 : It implements some additional funtionality which can be useful but
125 : is missing at the normal hash implementation.
126 : */
127 : template< class TType >
128 150740 : class BaseHash : public ::boost::unordered_map< OUString ,
129 : TType ,
130 : OUStringHash ,
131 : ::std::equal_to< OUString > >
132 : {
133 : public:
134 :
135 : // the only way to free used memory really!
136 6170 : void free()
137 : {
138 6170 : BaseHash().swap( *this );// get rid of reserved capacity
139 6170 : }
140 : };
141 :
142 : /**
143 : Basic OUString hash.
144 : Key and values are OUStrings.
145 : */
146 : typedef BaseHash< OUString > OUStringHashMap;
147 :
148 : /**
149 : It can be used to map names (e.g. of properties) to her corresponding handles.
150 : Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name.
151 : Mapping between these two parts of a property should be done in the fastest way :-)
152 : */
153 : typedef BaseHash< sal_Int32 > NameToHandleHash;
154 :
155 : typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString> ListenerHash;
156 :
157 : } // namespace framework
158 :
159 : #endif // INCLUDED_FRAMEWORK_INC_STDTYPES_H
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|