LCOV - code coverage report
Current view: top level - libreoffice/framework/inc - stdtypes.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 11 19 57.9 %
Date: 2012-12-27 Functions: 21 34 61.8 %
Legend: Lines: hit not hit

          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 __FRAMEWORK_STDTYPES_H_
      21             : #define __FRAMEWORK_STDTYPES_H_
      22             : 
      23             : #include <vector>
      24             : #include <queue>
      25             : #include <boost/unordered_map.hpp>
      26             : 
      27             : #include <general.h>
      28             : 
      29             : #ifndef __COM_SUN_STAR_AWT_KEYEVENT_HPP_
      30             : #include <com/sun/star/awt/KeyEvent.hpp>
      31             : #endif
      32             : 
      33             : #include <comphelper/sequenceasvector.hxx>
      34             : #include <cppuhelper/interfacecontainer.hxx>
      35             : #include <rtl/ustring.hxx>
      36             : 
      37             : namespace framework{
      38             : 
      39             : /**
      40             :     Own hash functions used for stl-structures ... e.g. hash tables/maps ...
      41             : */
      42             : struct OUStringHashCode
      43             : {
      44       50908 :     size_t operator()( const ::rtl::OUString& sString ) const
      45             :     {
      46       50908 :         return sString.hashCode();
      47             :     }
      48             : };
      49             : 
      50             : struct ShortHashCode
      51             : {
      52           0 :     size_t operator()( const ::sal_Int16& nShort ) const
      53             :     {
      54           0 :         return (size_t)nShort;
      55             :     }
      56             : };
      57             : 
      58             : struct Int32HashCode
      59             : {
      60           0 :     size_t operator()( const ::sal_Int32& nValue ) const
      61             :     {
      62           0 :         return (size_t)nValue;
      63             :     }
      64             : };
      65             : 
      66             : struct KeyEventHashCode
      67             : {
      68           0 :     size_t operator()( const css::awt::KeyEvent& aEvent ) const
      69             :     {
      70             :         return (size_t)(aEvent.KeyCode  +
      71             :                         //aEvent.KeyChar  +
      72             :                         //aEvent.KeyFunc  +
      73           0 :                         aEvent.Modifiers);
      74             :     }
      75             : };
      76             : 
      77             : struct KeyEventEqualsFunc
      78             : {
      79           0 :     bool operator()(const css::awt::KeyEvent aKey1,
      80             :                     const css::awt::KeyEvent aKey2) const
      81             :     {
      82             :         return (
      83             :                 (aKey1.KeyCode   == aKey2.KeyCode  ) &&
      84             :                 //(aKey1.KeyChar   == aKey2.KeyChar  ) &&
      85             :                 //(aKey1.KeyFunc   == aKey2.KeyFunc  ) &&
      86             :                 (aKey1.Modifiers == aKey2.Modifiers)
      87           0 :                );
      88             :     }
      89             : };
      90             : 
      91             : //_________________________________________________________________________________________________________________
      92             : 
      93             : /**
      94             :     Basic string list based on a std::vector()
      95             :     It implements some additional funtionality which can be usefull but
      96             :     is missing at the normal vector implementation.
      97             : */
      98       19953 : class OUStringList : public ::comphelper::SequenceAsVector< ::rtl::OUString >
      99             : {
     100             :     public:
     101             : 
     102             :         // insert given element as the first one into the vector
     103             :         void push_front( const ::rtl::OUString& sElement )
     104             :         {
     105             :             insert( begin(), sElement );
     106             :         }
     107             : 
     108             :         // search for given element
     109        5442 :         iterator find( const ::rtl::OUString& sElement )
     110             :         {
     111        5442 :             return ::std::find(begin(), end(), sElement);
     112             :         }
     113             : 
     114         637 :         const_iterator findConst( const ::rtl::OUString& sElement ) const
     115             :         {
     116         637 :             return ::std::find(begin(), end(), sElement);
     117             :         }
     118             : 
     119             :         // the only way to free used memory realy!
     120             :         void free()
     121             :         {
     122             :             OUStringList().swap( *this );
     123             :         }
     124             : };
     125             : 
     126             : //_________________________________________________________________________________________________________________
     127             : 
     128             : /**
     129             :     Basic string queue based on a std::queue()
     130             :     It implements some additional funtionality which can be usefull but
     131             :     is missing at the normal std implementation.
     132             : */
     133             : typedef ::std::queue< ::rtl::OUString > OUStringQueue;
     134             : 
     135             : //_________________________________________________________________________________________________________________
     136             : 
     137             : /**
     138             :     Basic hash based on a boost::unordered_map() which provides key=[OUString] and value=[template type] pairs
     139             :     It implements some additional funtionality which can be usefull but
     140             :     is missing at the normal hash implementation.
     141             : */
     142             : template< class TType >
     143        2413 : class BaseHash : public ::boost::unordered_map< ::rtl::OUString                    ,
     144             :                                          TType                              ,
     145             :                                          OUStringHashCode                   ,
     146             :                                          ::std::equal_to< ::rtl::OUString > >
     147             : {
     148             :     public:
     149             : 
     150             :         // the only way to free used memory realy!
     151          85 :         void free()
     152             :         {
     153          85 :             BaseHash().swap( *this );
     154          85 :         }
     155             : };
     156             : 
     157             : //_________________________________________________________________________________________________________________
     158             : 
     159             : /**
     160             :     Basic OUString hash.
     161             :     Key and values are OUStrings.
     162             : */
     163             : typedef BaseHash< ::rtl::OUString > OUStringHash;
     164             : 
     165             : //_________________________________________________________________________________________________________________
     166             : 
     167             : /**
     168             :     It can be used to map names (e.g. of properties) to her corresponding handles.
     169             :     Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name.
     170             :     Mapping between these two parts of a property should be done in the fastest way :-)
     171             : */
     172             : typedef BaseHash< sal_Int32 > NameToHandleHash;
     173             : 
     174             : //_________________________________________________________________________________________________________________
     175             : 
     176             : /**
     177             :     Sometimes we need this template to implement listener container ...
     178             :     and we need it at different positions ...
     179             :     So it's better to declare it one times only!
     180             : */
     181             : typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<  ::rtl::OUString                    ,
     182             :                                                         OUStringHashCode                   ,
     183             :                                                         ::std::equal_to< ::rtl::OUString > >    ListenerHash;
     184             : 
     185             : }       // namespace framework
     186             : 
     187             : #endif  // #ifndef __FRAMEWORK_STDTYPES_H_
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10