LCOV - code coverage report
Current view: top level - framework/inc - stdtypes.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 17 19 89.5 %
Date: 2012-08-25 Functions: 29 34 85.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 16 43.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef __FRAMEWORK_STDTYPES_H_
      30                 :            : #define __FRAMEWORK_STDTYPES_H_
      31                 :            : 
      32                 :            : #include <vector>
      33                 :            : #include <queue>
      34                 :            : #include <boost/unordered_map.hpp>
      35                 :            : 
      36                 :            : #include <general.h>
      37                 :            : 
      38                 :            : #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
      39                 :            : #include <com/sun/star/awt/KeyEvent.hpp>
      40                 :            : #endif
      41                 :            : 
      42                 :            : #include <comphelper/sequenceasvector.hxx>
      43                 :            : #include <cppuhelper/interfacecontainer.hxx>
      44                 :            : #include <rtl/ustring.hxx>
      45                 :            : 
      46                 :            : namespace framework{
      47                 :            : 
      48                 :            : /**
      49                 :            :     Own hash functions used for stl-structures ... e.g. hash tables/maps ...
      50                 :            : */
      51                 :            : struct OUStringHashCode
      52                 :            : {
      53                 :    2665284 :     size_t operator()( const ::rtl::OUString& sString ) const
      54                 :            :     {
      55                 :    2665284 :         return sString.hashCode();
      56                 :            :     }
      57                 :            : };
      58                 :            : 
      59                 :            : struct ShortHashCode
      60                 :            : {
      61                 :      12390 :     size_t operator()( const ::sal_Int16& nShort ) const
      62                 :            :     {
      63                 :      12390 :         return (size_t)nShort;
      64                 :            :     }
      65                 :            : };
      66                 :            : 
      67                 :            : struct Int32HashCode
      68                 :            : {
      69                 :          0 :     size_t operator()( const ::sal_Int32& nValue ) const
      70                 :            :     {
      71                 :          0 :         return (size_t)nValue;
      72                 :            :     }
      73                 :            : };
      74                 :            : 
      75                 :            : struct KeyEventHashCode
      76                 :            : {
      77                 :     160010 :     size_t operator()( const css::awt::KeyEvent& aEvent ) const
      78                 :            :     {
      79                 :            :         return (size_t)(aEvent.KeyCode  +
      80                 :            :                         //aEvent.KeyChar  +
      81                 :            :                         //aEvent.KeyFunc  +
      82                 :     160010 :                         aEvent.Modifiers);
      83                 :            :     }
      84                 :            : };
      85                 :            : 
      86                 :            : struct KeyEventEqualsFunc
      87                 :            : {
      88                 :      19544 :     bool operator()(const css::awt::KeyEvent aKey1,
      89                 :            :                     const css::awt::KeyEvent aKey2) const
      90                 :            :     {
      91                 :            :         return (
      92                 :            :                 (aKey1.KeyCode   == aKey2.KeyCode  ) &&
      93                 :            :                 //(aKey1.KeyChar   == aKey2.KeyChar  ) &&
      94                 :            :                 //(aKey1.KeyFunc   == aKey2.KeyFunc  ) &&
      95                 :            :                 (aKey1.Modifiers == aKey2.Modifiers)
      96 [ -  + ][ #  # ]:      19544 :                );
      97                 :            :     }
      98                 :            : };
      99                 :            : 
     100                 :            : //_________________________________________________________________________________________________________________
     101                 :            : 
     102                 :            : /**
     103                 :            :     Basic string list based on a std::vector()
     104                 :            :     It implements some additional funtionality which can be usefull but
     105                 :            :     is missing at the normal vector implementation.
     106                 :            : */
     107                 :     170290 : class OUStringList : public ::comphelper::SequenceAsVector< ::rtl::OUString >
     108                 :            : {
     109                 :            :     public:
     110                 :            : 
     111                 :            :         // insert given element as the first one into the vector
     112                 :            :         void push_front( const ::rtl::OUString& sElement )
     113                 :            :         {
     114                 :            :             insert( begin(), sElement );
     115                 :            :         }
     116                 :            : 
     117                 :            :         // search for given element
     118                 :      37220 :         iterator find( const ::rtl::OUString& sElement )
     119                 :            :         {
     120                 :      37220 :             return ::std::find(begin(), end(), sElement);
     121                 :            :         }
     122                 :            : 
     123                 :       7743 :         const_iterator findConst( const ::rtl::OUString& sElement ) const
     124                 :            :         {
     125                 :       7743 :             return ::std::find(begin(), end(), sElement);
     126                 :            :         }
     127                 :            : 
     128                 :            :         // the only way to free used memory realy!
     129                 :            :         void free()
     130                 :            :         {
     131                 :            :             OUStringList().swap( *this );
     132                 :            :         }
     133                 :            : };
     134                 :            : 
     135                 :            : //_________________________________________________________________________________________________________________
     136                 :            : 
     137                 :            : /**
     138                 :            :     Basic string queue based on a std::queue()
     139                 :            :     It implements some additional funtionality which can be usefull but
     140                 :            :     is missing at the normal std implementation.
     141                 :            : */
     142                 :            : typedef ::std::queue< ::rtl::OUString > OUStringQueue;
     143                 :            : 
     144                 :            : //_________________________________________________________________________________________________________________
     145                 :            : 
     146                 :            : /**
     147                 :            :     Basic hash based on a boost::unordered_map() which provides key=[OUString] and value=[template type] pairs
     148                 :            :     It implements some additional funtionality which can be usefull but
     149                 :            :     is missing at the normal hash implementation.
     150                 :            : */
     151                 :            : template< class TType >
     152 [ +  - ][ +  - ]:      72044 : class BaseHash : public ::boost::unordered_map< ::rtl::OUString                    ,
         [ +  - ][ +  - ]
     153                 :            :                                          TType                              ,
     154                 :            :                                          OUStringHashCode                   ,
     155                 :            :                                          ::std::equal_to< ::rtl::OUString > >
     156                 :            : {
     157                 :            :     public:
     158                 :            : 
     159                 :            :         // the only way to free used memory realy!
     160                 :       2162 :         void free()
     161                 :            :         {
     162 [ +  - ][ +  - ]:       2162 :             BaseHash().swap( *this );
     163                 :       2162 :         }
     164                 :            : };
     165                 :            : 
     166                 :            : //_________________________________________________________________________________________________________________
     167                 :            : 
     168                 :            : /**
     169                 :            :     Basic OUString hash.
     170                 :            :     Key and values are OUStrings.
     171                 :            : */
     172                 :            : typedef BaseHash< ::rtl::OUString > OUStringHash;
     173                 :            : 
     174                 :            : //_________________________________________________________________________________________________________________
     175                 :            : 
     176                 :            : /**
     177                 :            :     It can be used to map names (e.g. of properties) to her corresponding handles.
     178                 :            :     Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name.
     179                 :            :     Mapping between these two parts of a property should be done in the fastest way :-)
     180                 :            : */
     181                 :            : typedef BaseHash< sal_Int32 > NameToHandleHash;
     182                 :            : 
     183                 :            : //_________________________________________________________________________________________________________________
     184                 :            : 
     185                 :            : /**
     186                 :            :     Sometimes we need this template to implement listener container ...
     187                 :            :     and we need it at different positions ...
     188                 :            :     So it's better to declare it one times only!
     189                 :            : */
     190                 :            : typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<  ::rtl::OUString                    ,
     191                 :            :                                                         OUStringHashCode                   ,
     192                 :            :                                                         ::std::equal_to< ::rtl::OUString > >    ListenerHash;
     193                 :            : 
     194                 :            : }       // namespace framework
     195                 :            : 
     196                 :            : #endif  // #ifndef __FRAMEWORK_STDTYPES_H_
     197                 :            : 
     198                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10