1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_STDTYPES_H_ 25 #define __FRAMEWORK_STDTYPES_H_ 26 27 #include <vector> 28 #include <queue> 29 #include <hash_map> 30 31 //_________________________________________________________________________________________________________________ 32 // own includes 33 //_________________________________________________________________________________________________________________ 34 #include <general.h> 35 36 //_________________________________________________________________________________________________________________ 37 // interface includes 38 //_________________________________________________________________________________________________________________ 39 40 #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_ 41 #include <com/sun/star/awt/KeyEvent.hpp> 42 #endif 43 44 //_________________________________________________________________________________________________________________ 45 // other includes 46 //_________________________________________________________________________________________________________________ 47 #include <comphelper/sequenceasvector.hxx> 48 #include <cppuhelper/interfacecontainer.hxx> 49 #include <rtl/ustring.hxx> 50 51 //_________________________________________________________________________________________________________________ 52 // namespace 53 //_________________________________________________________________________________________________________________ 54 55 namespace framework{ 56 57 //_________________________________________________________________________________________________________________ 58 // definitions 59 //_________________________________________________________________________________________________________________ 60 61 62 struct ShortHashCode 63 { operator ()framework::ShortHashCode64 size_t operator()( const ::sal_Int16& nShort ) const 65 { 66 return (size_t)nShort; 67 } 68 }; 69 70 struct Int32HashCode 71 { operator ()framework::Int32HashCode72 size_t operator()( const ::sal_Int32& nValue ) const 73 { 74 return (size_t)nValue; 75 } 76 }; 77 78 struct KeyEventHashCode 79 { operator ()framework::KeyEventHashCode80 size_t operator()( const css::awt::KeyEvent& aEvent ) const 81 { 82 return (size_t)(aEvent.KeyCode + 83 //aEvent.KeyChar + 84 //aEvent.KeyFunc + 85 aEvent.Modifiers); 86 } 87 }; 88 89 struct KeyEventEqualsFunc 90 { operator ()framework::KeyEventEqualsFunc91 bool operator()(const css::awt::KeyEvent aKey1, 92 const css::awt::KeyEvent aKey2) const 93 { 94 return ( 95 (aKey1.KeyCode == aKey2.KeyCode ) && 96 //(aKey1.KeyChar == aKey2.KeyChar ) && 97 //(aKey1.KeyFunc == aKey2.KeyFunc ) && 98 (aKey1.Modifiers == aKey2.Modifiers) 99 ); 100 } 101 }; 102 103 //_________________________________________________________________________________________________________________ 104 105 /** 106 Basic string list based on a std::vector() 107 It implements some additional funtionality which can be useful but 108 is missing at the normal vector implementation. 109 */ 110 class OUStringList : public ::comphelper::SequenceAsVector< ::rtl::OUString > 111 { 112 public: 113 114 // insert given element as the first one into the vector push_front(const::rtl::OUString & sElement)115 void push_front( const ::rtl::OUString& sElement ) 116 { 117 insert( begin(), sElement ); 118 } 119 120 // search for given element find(const::rtl::OUString & sElement)121 iterator find( const ::rtl::OUString& sElement ) 122 { 123 return ::std::find(begin(), end(), sElement); 124 } 125 findConst(const::rtl::OUString & sElement) const126 const_iterator findConst( const ::rtl::OUString& sElement ) const 127 { 128 return ::std::find(begin(), end(), sElement); 129 } 130 131 // the only way to free used memory really! free()132 void free() 133 { 134 OUStringList().swap( *this ); 135 } 136 }; 137 138 //_________________________________________________________________________________________________________________ 139 140 /** 141 Basic string queue based on a std::queue() 142 It implements some additional funtionality which can be useful but 143 is missing at the normal std implementation. 144 */ 145 typedef ::std::queue< ::rtl::OUString > OUStringQueue; 146 147 //_________________________________________________________________________________________________________________ 148 149 /** 150 Basic hash based on a std::hash_map() which provides key=[OUString] and value=[template type] pairs 151 It implements some additional funtionality which can be useful but 152 is missing at the normal hash implementation. 153 */ 154 template< class TType > 155 class BaseHash : public ::std::hash_map< ::rtl::OUString , 156 TType , 157 rtl::OUStringHash , 158 ::std::equal_to< ::rtl::OUString > > 159 { 160 public: 161 162 // the only way to free used memory really! free()163 void free() 164 { 165 BaseHash().swap( *this ); 166 } 167 }; 168 169 //_________________________________________________________________________________________________________________ 170 171 /** 172 Basic OUString hash. 173 Key and values are OUStrings. 174 */ 175 typedef BaseHash< ::rtl::OUString > OUStringHashMap; 176 177 //_________________________________________________________________________________________________________________ 178 179 /** 180 It can be used to map names (e.g. of properties) to her corresponding handles. 181 Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name. 182 Mapping between these two parts of a property should be done in the fastest way :-) 183 */ 184 typedef BaseHash< sal_Int32 > NameToHandleHash; 185 186 //_________________________________________________________________________________________________________________ 187 188 /** 189 Sometimes we need this template to implement listener container ... 190 and we need it at different positions ... 191 So it's better to declare it one times only! 192 */ 193 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString , 194 rtl::OUStringHash, 195 ::std::equal_to< ::rtl::OUString > > ListenerHash; 196 197 } // namespace framework 198 199 #endif // #ifndef __FRAMEWORK_STDTYPES_H_ 200