LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/comphelper - stl_types.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 50 80.0 %
Date: 2012-08-25 Functions: 21 33 63.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     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                 :            : #ifndef _COMPHELPER_STLTYPES_HXX_
      20                 :            : #define _COMPHELPER_STLTYPES_HXX_
      21                 :            : 
      22                 :            : #include <vector>
      23                 :            : #include <map>
      24                 :            : 
      25                 :            : #include <stack>
      26                 :            : #include <set>
      27                 :            : 
      28                 :            : #ifdef _MSC_VER
      29                 :            : # ifndef _USE_MATH_DEFINES
      30                 :            : #  define _USE_MATH_DEFINES // needed by Visual C++ for math constants
      31                 :            : # endif
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include <math.h> // prevent conflict between exception and std::exception
      35                 :            : #include <functional>
      36                 :            : 
      37                 :            : 
      38                 :            : #include <rtl/ustring.hxx>
      39                 :            : #include <rtl/ustrbuf.hxx>
      40                 :            : #include <com/sun/star/uno/Reference.hxx>
      41                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      42                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      43                 :            : 
      44                 :            : //... namespace comphelper ................................................
      45                 :            : namespace comphelper
      46                 :            : {
      47                 :            : //.........................................................................
      48                 :            : 
      49                 :            : //========================================================================
      50                 :            : // comparisation functions
      51                 :            : 
      52                 :            : //------------------------------------------------------------------------
      53                 :            :     struct UStringLess : public ::std::binary_function< ::rtl::OUString, ::rtl::OUString, bool>
      54                 :            : {
      55                 :    3975074 :     bool operator() (const ::rtl::OUString& x, const ::rtl::OUString& y) const { return x < y ? true : false;}      // construct prevents a MSVC6 warning
      56                 :            : };
      57                 :            : //------------------------------------------------------------------------
      58                 :            : struct UStringMixLess : public ::std::binary_function< ::rtl::OUString, ::rtl::OUString, bool>
      59                 :            : {
      60                 :            :     bool m_bCaseSensitive;
      61                 :            : public:
      62                 :       1190 :     UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
      63                 :     133150 :     bool operator() (const ::rtl::OUString& x, const ::rtl::OUString& y) const
      64                 :            :     {
      65         [ +  - ]:     133150 :         if (m_bCaseSensitive)
      66                 :     133150 :             return rtl_ustr_compare(x.getStr(), y.getStr()) < 0 ? true : false;
      67                 :            :         else
      68                 :     133150 :             return rtl_ustr_compareIgnoreAsciiCase(x.getStr(), y.getStr()) < 0 ? true : false;
      69                 :            :     }
      70                 :            : 
      71                 :       1208 :     bool isCaseSensitive() const {return m_bCaseSensitive;}
      72                 :            : };
      73                 :            : //------------------------------------------------------------------------
      74                 :            : struct UStringEqual
      75                 :            : {
      76                 :       9320 :     sal_Bool operator() (const ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const { return lhs.equals( rhs );}
      77                 :            : };
      78                 :            : 
      79                 :            : //------------------------------------------------------------------------
      80                 :            : struct UStringIEqual
      81                 :            : {
      82                 :            :     sal_Bool operator() (const ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const { return lhs.equalsIgnoreAsciiCase( rhs );}
      83                 :            : };
      84                 :            : 
      85                 :            : //------------------------------------------------------------------------
      86                 :            : class UStringMixEqual
      87                 :            : {
      88                 :            :     sal_Bool m_bCaseSensitive;
      89                 :            : 
      90                 :            : public:
      91                 :       9040 :     UStringMixEqual(sal_Bool bCaseSensitive = sal_True):m_bCaseSensitive(bCaseSensitive){}
      92                 :      73600 :     sal_Bool operator() (const ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const
      93                 :            :     {
      94         [ +  - ]:      73600 :         return m_bCaseSensitive ? lhs.equals( rhs ) : lhs.equalsIgnoreAsciiCase( rhs );
      95                 :            :     }
      96                 :         12 :     sal_Bool isCaseSensitive() const {return m_bCaseSensitive;}
      97                 :            : };
      98                 :            : //------------------------------------------------------------------------
      99                 :            : class TStringMixEqualFunctor : public ::std::binary_function< ::rtl::OUString,::rtl::OUString,bool>
     100                 :            : {
     101                 :            :     sal_Bool m_bCaseSensitive;
     102                 :            : 
     103                 :            : public:
     104                 :         48 :     TStringMixEqualFunctor(sal_Bool bCaseSensitive = sal_True)
     105                 :         48 :         :m_bCaseSensitive(bCaseSensitive)
     106                 :         48 :     {}
     107                 :          0 :     bool operator() (const ::rtl::OUString& lhs, const ::rtl::OUString& rhs) const
     108                 :            :     {
     109         [ #  # ]:          0 :         return !!(m_bCaseSensitive ? lhs.equals( rhs ) : lhs.equalsIgnoreAsciiCase( rhs ));
     110                 :            :     }
     111                 :            :     sal_Bool isCaseSensitive() const {return m_bCaseSensitive;}
     112                 :            : };
     113                 :            : //------------------------------------------------------------------------
     114                 :            : class TPropertyValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::PropertyValue,::rtl::OUString,bool>
     115                 :            : {
     116                 :            : public:
     117                 :        100 :     TPropertyValueEqualFunctor()
     118                 :        100 :     {}
     119                 :         48 :     bool operator() (const ::com::sun::star::beans::PropertyValue& lhs, const ::rtl::OUString& rhs) const
     120                 :            :     {
     121                 :         48 :         return !!(lhs.Name == rhs);
     122                 :            :     }
     123                 :            : };
     124                 :            : //------------------------------------------------------------------------
     125                 :            : class TNamedValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::NamedValue,::rtl::OUString,bool>
     126                 :            : {
     127                 :            : public:
     128                 :          0 :     TNamedValueEqualFunctor()
     129                 :          0 :     {}
     130                 :          0 :     bool operator() (const ::com::sun::star::beans::NamedValue& lhs, const ::rtl::OUString& rhs) const
     131                 :            :     {
     132                 :          0 :         return !!(lhs.Name == rhs);
     133                 :            :     }
     134                 :            : };
     135                 :            : //------------------------------------------------------------------------
     136                 :            : class UStringMixHash
     137                 :            : {
     138                 :            :     sal_Bool m_bCaseSensitive;
     139                 :            : 
     140                 :            : public:
     141                 :            :     UStringMixHash(sal_Bool bCaseSensitive = sal_True):m_bCaseSensitive(bCaseSensitive){}
     142                 :            :     size_t operator() (const ::rtl::OUString& rStr) const
     143                 :            :     {
     144                 :            :         return m_bCaseSensitive ? rStr.hashCode() : rStr.toAsciiUpperCase().hashCode();
     145                 :            :     }
     146                 :            :     sal_Bool isCaseSensitive() const {return m_bCaseSensitive;}
     147                 :            : };
     148                 :            : 
     149                 :            : //=====================================================================
     150                 :            : //= OInterfaceCompare
     151                 :            : //=====================================================================
     152                 :            : /** is stl-compliant structure for comparing Reference&lt; &lt;iface&gt; &gt; instances
     153                 :            : */
     154                 :            : template < class IAFCE >
     155                 :            : struct OInterfaceCompare
     156                 :            :     :public ::std::binary_function  <   ::com::sun::star::uno::Reference< IAFCE >
     157                 :            :                                     ,   ::com::sun::star::uno::Reference< IAFCE >
     158                 :            :                                     ,   bool
     159                 :            :                                     >
     160                 :            : {
     161                 :       6666 :     bool operator() (const ::com::sun::star::uno::Reference< IAFCE >& lhs, const ::com::sun::star::uno::Reference< IAFCE >& rhs) const
     162                 :            :     {
     163                 :       6666 :         return lhs.get() < rhs.get();
     164                 :            :             // this does not make any sense if you see the semantics of the pointer returned by get:
     165                 :            :             // It's a pointer to a point in memory where an interface implementation lies.
     166                 :            :             // But for our purpose (provide a reliable less-operator which can be used with the STL), this is
     167                 :            :             // sufficient ....
     168                 :            :     }
     169                 :            : };
     170                 :            : 
     171                 :            : template <class _Tp, class _Arg>
     172                 :            : class mem_fun1_t : public ::std::binary_function<_Tp*,_Arg,void>
     173                 :            : {
     174                 :            :     typedef void (_Tp::*_fun_type)(_Arg);
     175                 :            : public:
     176                 :          0 :     explicit mem_fun1_t(_fun_type __pf) : _M_f(__pf) {}
     177         [ #  # ]:          0 :     void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
     178                 :            : private:
     179                 :            :     _fun_type _M_f;
     180                 :            : };
     181                 :            : 
     182                 :            : template <class _Tp, class _Arg>
     183                 :          0 : inline mem_fun1_t<_Tp,_Arg> mem_fun(void (_Tp::*__f)(_Arg))
     184                 :            : {
     185                 :          0 :     return mem_fun1_t<_Tp,_Arg>(__f);
     186                 :            : }
     187                 :            : 
     188                 :            : //.........................................................................
     189                 :            : /** output iterator that appends OUStrings into an OUStringBuffer.
     190                 :            :  */
     191                 :            : class OUStringBufferAppender :
     192                 :            :     public ::std::iterator< ::std::output_iterator_tag, void, void, void, void>
     193                 :            : {
     194                 :            : public:
     195                 :            :     typedef OUStringBufferAppender Self;
     196                 :            :     typedef ::std::output_iterator_tag iterator_category;
     197                 :            :     typedef void value_type;
     198                 :            :     typedef void reference;
     199                 :            :     typedef void pointer;
     200                 :            :     typedef size_t difference_type;
     201                 :            : 
     202                 :        123 :     OUStringBufferAppender(::rtl::OUStringBuffer & i_rBuffer)
     203                 :        123 :         : m_rBuffer(i_rBuffer) { }
     204                 :         55 :     Self & operator=(::rtl::OUString const & i_rStr)
     205                 :            :     {
     206                 :         55 :         m_rBuffer.append( i_rStr );
     207                 :         55 :         return *this;
     208                 :            :     }
     209                 :         55 :     Self & operator*() { return *this; } // so operator= works
     210                 :         55 :     Self & operator++() { return *this; }
     211                 :            :     Self & operator++(int) { return *this; }
     212                 :            : 
     213                 :            : private:
     214                 :            :     ::rtl::OUStringBuffer & m_rBuffer;
     215                 :            : };
     216                 :            : 
     217                 :            : //.........................................................................
     218                 :            : /** algorithm similar to std::copy, but inserts a separator between elements.
     219                 :            :  */
     220                 :            : template< typename ForwardIter, typename OutputIter, typename T >
     221                 :        123 : OutputIter intersperse(
     222                 :            :     ForwardIter start, ForwardIter end, OutputIter out, T const & separator)
     223                 :            : {
     224      [ +  +  - ]:        123 :     if (start != end) {
     225         [ +  - ]:         37 :         *out = *start;
     226                 :         37 :         ++start;
     227                 :         37 :         ++out;
     228                 :            :     }
     229                 :            : 
     230      [ +  +  + ]:        132 :     while (start != end) {
     231                 :          9 :         *out = separator;
     232                 :          9 :         ++out;
     233         [ +  - ]:          9 :         *out = *start;
     234                 :          9 :         ++start;
     235                 :          9 :         ++out;
     236                 :            :     }
     237                 :            : 
     238                 :        123 :     return out;
     239                 :            : }
     240                 :            : 
     241                 :            : //.........................................................................
     242                 :            : }
     243                 :            : //... namespace comphelper ................................................
     244                 :            : 
     245                 :            : //==================================================================
     246                 :            : // consistently defining stl-types
     247                 :            : //==================================================================
     248                 :            : 
     249                 :            : #define DECLARE_STL_ITERATORS(classname)                            \
     250                 :            :     typedef classname::iterator         classname##Iterator;        \
     251                 :            :     typedef classname::const_iterator   Const##classname##Iterator  \
     252                 :            : 
     253                 :            : #define DECLARE_STL_MAP(keytype, valuetype, comparefct, classname)  \
     254                 :            :     typedef std::map< keytype, valuetype, comparefct >  classname;  \
     255                 :            :     DECLARE_STL_ITERATORS(classname)                                \
     256                 :            : 
     257                 :            : #define DECLARE_STL_STDKEY_MAP(keytype, valuetype, classname)               \
     258                 :            :     DECLARE_STL_MAP(keytype, valuetype, std::less< keytype >, classname)    \
     259                 :            : 
     260                 :            : #define DECLARE_STL_VECTOR(valuetyp, classname)     \
     261                 :            :     typedef std::vector< valuetyp >     classname;  \
     262                 :            :     DECLARE_STL_ITERATORS(classname)                \
     263                 :            : 
     264                 :            : #define DECLARE_STL_USTRINGACCESS_MAP(valuetype, classname)                 \
     265                 :            :     DECLARE_STL_MAP(::rtl::OUString, valuetype, ::comphelper::UStringLess, classname)   \
     266                 :            : 
     267                 :            : #define DECLARE_STL_STDKEY_SET(valuetype, classname)    \
     268                 :            :     typedef ::std::set< valuetype > classname;          \
     269                 :            :     DECLARE_STL_ITERATORS(classname)                    \
     270                 :            : 
     271                 :            : #define DECLARE_STL_SET(valuetype, comparefct, classname)               \
     272                 :            :     typedef ::std::set< valuetype, comparefct > classname;  \
     273                 :            :     DECLARE_STL_ITERATORS(classname)                        \
     274                 :            : 
     275                 :            : #endif  // _COMPHELPER_STLTYPES_HXX_
     276                 :            : 
     277                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10