LCOV - code coverage report
Current view: top level - include/comphelper - stl_types.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 43 86.0 %
Date: 2015-06-13 12:38:46 Functions: 20 29 69.0 %
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             : #ifndef INCLUDED_COMPHELPER_STL_TYPES_HXX
      20             : #define INCLUDED_COMPHELPER_STL_TYPES_HXX
      21             : 
      22             : #include <sal/config.h>
      23             : 
      24             : #include <stack>
      25             : 
      26             : #include <math.h>
      27             : #include <functional>
      28             : 
      29             : #include <rtl/ustring.hxx>
      30             : #include <rtl/ustrbuf.hxx>
      31             : #include <com/sun/star/uno/Reference.hxx>
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <com/sun/star/beans/NamedValue.hpp>
      34             : 
      35             : namespace comphelper
      36             : {
      37             : 
      38             : // comparison functors
      39             : 
      40             : struct UStringMixLess : public ::std::binary_function< OUString, OUString, bool>
      41             : {
      42             :     bool m_bCaseSensitive;
      43             : public:
      44       15451 :     UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
      45      113329 :     bool operator() (const OUString& x, const OUString& y) const
      46             :     {
      47      113329 :         if (m_bCaseSensitive)
      48       81586 :             return rtl_ustr_compare(x.getStr(), y.getStr()) < 0;
      49             :         else
      50       31743 :             return rtl_ustr_compareIgnoreAsciiCase(x.getStr(), y.getStr()) < 0;
      51             :     }
      52             : 
      53       14590 :     bool isCaseSensitive() const {return m_bCaseSensitive;}
      54             : };
      55             : 
      56             : class UStringMixEqual: public std::binary_function<OUString, OUString, bool>
      57             : {
      58             :     bool m_bCaseSensitive;
      59             : 
      60             : public:
      61        6819 :     UStringMixEqual(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
      62       48855 :     bool operator() (const OUString& lhs, const OUString& rhs) const
      63             :     {
      64       48855 :         return m_bCaseSensitive ? lhs.equals( rhs ) : lhs.equalsIgnoreAsciiCase( rhs );
      65             :     }
      66           6 :     bool isCaseSensitive() const {return m_bCaseSensitive;}
      67             : };
      68             : 
      69             : class TPropertyValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::PropertyValue,OUString,bool>
      70             : {
      71             : public:
      72          82 :     TPropertyValueEqualFunctor()
      73          82 :     {}
      74          36 :     bool operator() (const ::com::sun::star::beans::PropertyValue& lhs, const OUString& rhs) const
      75             :     {
      76          36 :         return !!(lhs.Name == rhs);
      77             :     }
      78             : };
      79             : 
      80             : class TNamedValueEqualFunctor : public ::std::binary_function< ::com::sun::star::beans::NamedValue,OUString,bool>
      81             : {
      82             : public:
      83           0 :     TNamedValueEqualFunctor()
      84           0 :     {}
      85           0 :     bool operator() (const ::com::sun::star::beans::NamedValue& lhs, const OUString& rhs) const
      86             :     {
      87           0 :         return !!(lhs.Name == rhs);
      88             :     }
      89             : };
      90             : 
      91             : /** STL-compliant structure for comparing Reference&lt; &lt;iface&gt; &gt; instances
      92             : */
      93             : template < class IAFCE >
      94             : struct OInterfaceCompare
      95             :     :public ::std::binary_function  <   ::com::sun::star::uno::Reference< IAFCE >
      96             :                                     ,   ::com::sun::star::uno::Reference< IAFCE >
      97             :                                     ,   bool
      98             :                                     >
      99             : {
     100        2010 :     bool operator() (const ::com::sun::star::uno::Reference< IAFCE >& lhs, const ::com::sun::star::uno::Reference< IAFCE >& rhs) const
     101             :     {
     102        2010 :         return lhs.get() < rhs.get();
     103             :             // this does not make any sense if you see the semantics of the pointer returned by get:
     104             :             // It's a pointer to a point in memory where an interface implementation lies.
     105             :             // But for our purpose (provide a reliable less-operator which can be used with the STL), this is
     106             :             // sufficient ....
     107             :     }
     108             : };
     109             : 
     110             : template <class _Tp, class _Arg>
     111             : class mem_fun1_t : public ::std::binary_function<_Tp*,_Arg,void>
     112             : {
     113             :     typedef void (_Tp::*_fun_type)(_Arg);
     114             : public:
     115          21 :     explicit mem_fun1_t(_fun_type __pf) : _M_f(__pf) {}
     116          18 :     void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
     117             : private:
     118             :     _fun_type _M_f;
     119             : };
     120             : 
     121             : template <class _Tp, class _Arg>
     122           0 : inline mem_fun1_t<_Tp,_Arg> mem_fun(void (_Tp::*__f)(_Arg))
     123             : {
     124           0 :     return mem_fun1_t<_Tp,_Arg>(__f);
     125             : }
     126             : 
     127             : /** output iterator that appends OUStrings into an OUStringBuffer.
     128             :  */
     129             : class OUStringBufferAppender :
     130             :     public ::std::iterator< ::std::output_iterator_tag, void, void, void, void>
     131             : {
     132             : public:
     133             :     typedef OUStringBufferAppender Self;
     134             :     typedef ::std::output_iterator_tag iterator_category;
     135             :     typedef void value_type;
     136             :     typedef void reference;
     137             :     typedef void pointer;
     138             :     typedef size_t difference_type;
     139             : 
     140         181 :     OUStringBufferAppender(OUStringBuffer & i_rBuffer)
     141         181 :         : m_rBuffer(i_rBuffer) { }
     142          26 :     Self & operator=(OUString const & i_rStr)
     143             :     {
     144          26 :         m_rBuffer.append( i_rStr );
     145          26 :         return *this;
     146             :     }
     147          26 :     Self & operator*() { return *this; } // so operator= works
     148          26 :     Self & operator++() { return *this; }
     149             :     Self & operator++(int) { return *this; }
     150             : 
     151             : private:
     152             :     OUStringBuffer & m_rBuffer;
     153             : };
     154             : 
     155             : /** algorithm similar to std::copy, but inserts a separator between elements.
     156             :  */
     157             : template< typename ForwardIter, typename OutputIter, typename T >
     158         181 : OutputIter intersperse(
     159             :     ForwardIter start, ForwardIter end, OutputIter out, T const & separator)
     160             : {
     161         181 :     if (start != end) {
     162          18 :         *out = *start;
     163          18 :         ++start;
     164          18 :         ++out;
     165             :     }
     166             : 
     167         366 :     while (start != end) {
     168           4 :         *out = separator;
     169           4 :         ++out;
     170           4 :         *out = *start;
     171           4 :         ++start;
     172           4 :         ++out;
     173             :     }
     174             : 
     175         181 :     return out;
     176             : }
     177             : 
     178             : }
     179             : 
     180             : #endif // INCLUDED_COMPHELPER_STL_TYPES_HXX
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11