LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/inc - stdtypes.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 17 20 85.0 %
Date: 2013-07-09 Functions: 29 34 85.3 %
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             : #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        6195 :     size_t operator()( const ::sal_Int16& nShort ) const
      44             :     {
      45        6195 :         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       99754 :     size_t operator()( const css::awt::KeyEvent& aEvent ) const
      60             :     {
      61       99754 :         return (size_t)(aEvent.KeyCode  +
      62             :                         //aEvent.KeyChar  +
      63             :                         //aEvent.KeyFunc  +
      64       99754 :                         aEvent.Modifiers);
      65             :     }
      66             : };
      67             : 
      68             : struct KeyEventEqualsFunc
      69             : {
      70       15886 :     bool operator()(const css::awt::KeyEvent aKey1,
      71             :                     const css::awt::KeyEvent aKey2) const
      72             :     {
      73             :         return (
      74       15886 :                 (aKey1.KeyCode   == aKey2.KeyCode  ) &&
      75             :                 //(aKey1.KeyChar   == aKey2.KeyChar  ) &&
      76             :                 //(aKey1.KeyFunc   == aKey2.KeyFunc  ) &&
      77           0 :                 (aKey1.Modifiers == aKey2.Modifiers)
      78       15886 :                );
      79             :     }
      80             : };
      81             : 
      82             : //_________________________________________________________________________________________________________________
      83             : 
      84             : /**
      85             :     Basic string list based on a std::vector()
      86             :     It implements some additional funtionality which can be useful but
      87             :     is missing at the normal vector implementation.
      88             : */
      89       97804 : class OUStringList : public ::comphelper::SequenceAsVector< OUString >
      90             : {
      91             :     public:
      92             : 
      93             :         // insert given element as the first one into the vector
      94             :         void push_front( const OUString& sElement )
      95             :         {
      96             :             insert( begin(), sElement );
      97             :         }
      98             : 
      99             :         // search for given element
     100       19652 :         iterator find( const OUString& sElement )
     101             :         {
     102       19652 :             return ::std::find(begin(), end(), sElement);
     103             :         }
     104             : 
     105        4418 :         const_iterator findConst( const OUString& sElement ) const
     106             :         {
     107        4418 :             return ::std::find(begin(), end(), sElement);
     108             :         }
     109             : 
     110             :         // the only way to free used memory realy!
     111             :         void free()
     112             :         {
     113             :             OUStringList().swap( *this );
     114             :         }
     115             : };
     116             : 
     117             : //_________________________________________________________________________________________________________________
     118             : 
     119             : /**
     120             :     Basic string queue based on a std::queue()
     121             :     It implements some additional funtionality which can be useful but
     122             :     is missing at the normal std implementation.
     123             : */
     124             : typedef ::std::queue< OUString > OUStringQueue;
     125             : 
     126             : //_________________________________________________________________________________________________________________
     127             : 
     128             : /**
     129             :     Basic hash based on a boost::unordered_map() which provides key=[OUString] and value=[template type] pairs
     130             :     It implements some additional funtionality which can be useful but
     131             :     is missing at the normal hash implementation.
     132             : */
     133             : template< class TType >
     134       41055 : class BaseHash : public ::boost::unordered_map< OUString                    ,
     135             :                                          TType                              ,
     136             :                                          OUStringHash                  ,
     137             :                                          ::std::equal_to< OUString > >
     138             : {
     139             :     public:
     140             : 
     141             :         // the only way to free used memory realy!
     142        1359 :         void free()
     143             :         {
     144        1359 :             BaseHash().swap( *this );
     145        1359 :         }
     146             : };
     147             : 
     148             : //_________________________________________________________________________________________________________________
     149             : 
     150             : /**
     151             :     Basic OUString hash.
     152             :     Key and values are OUStrings.
     153             : */
     154             : typedef BaseHash< OUString > OUStringHashMap;
     155             : 
     156             : //_________________________________________________________________________________________________________________
     157             : 
     158             : /**
     159             :     It can be used to map names (e.g. of properties) to her corresponding handles.
     160             :     Our helper class OPropertySetHelper works optimized with handles but sometimes we have only a property name.
     161             :     Mapping between these two parts of a property should be done in the fastest way :-)
     162             : */
     163             : typedef BaseHash< sal_Int32 > NameToHandleHash;
     164             : 
     165             : //_________________________________________________________________________________________________________________
     166             : 
     167             : /**
     168             :     Sometimes we need this template to implement listener container ...
     169             :     and we need it at different positions ...
     170             :     So it's better to declare it one times only!
     171             : */
     172             : typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<  OUString                    ,
     173             :                                                         OUStringHash,
     174             :                                                         ::std::equal_to< OUString > >    ListenerHash;
     175             : 
     176             : }       // namespace framework
     177             : 
     178             : #endif  // #ifndef __FRAMEWORK_STDTYPES_H_
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10