LibreOffice Module comphelper (master)  1
stl_types.hxx
Go to the documentation of this file.
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 <algorithm>
25 #include <memory>
26 #include <string_view>
27 
28 #include <rtl/ustring.hxx>
29 #include <rtl/ustrbuf.hxx>
30 
31 namespace com::sun::star::uno { template <typename > class Reference; }
32 
33 namespace comphelper
34 {
35 
36 // comparison functors
37 
39 {
41 public:
42  UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
43  bool operator() (const OUString& x, std::u16string_view y) const
44  {
45  if (m_bCaseSensitive)
46  return x.compareTo(y) < 0;
47  else
48  return x.compareToIgnoreAsciiCase(y) < 0;
49  }
50 
51  bool isCaseSensitive() const {return m_bCaseSensitive;}
52 };
53 
55 {
56  bool const m_bCaseSensitive;
57 
58 public:
59  UStringMixEqual(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
60  bool operator() (const OUString& lhs, std::u16string_view rhs) const
61  {
62  return m_bCaseSensitive ? lhs == rhs : lhs.equalsIgnoreAsciiCase( rhs );
63  }
64  bool isCaseSensitive() const {return m_bCaseSensitive;}
65 };
66 
68 template<class T> struct UniquePtrValueLess
69 {
70  bool operator()(std::unique_ptr<T> const& lhs,
71  std::unique_ptr<T> const& rhs) const
72  {
73  assert(lhs.get());
74  assert(rhs.get());
75  return (*lhs) < (*rhs);
76  }
77 };
78 
80 template<template<typename, typename...> class C, typename T, typename... Etc>
82  C<std::unique_ptr<T>, Etc...> const& lhs,
83  C<std::unique_ptr<T>, Etc...> const& rhs)
84 {
85  return lhs.size() == rhs.size()
86  && std::equal(lhs.begin(), lhs.end(), rhs.begin(),
87  [](auto& p1, auto& p2) { return *p1 == *p2; });
88 };
89 
90 
91 template <class Tp, class Arg>
92 class mem_fun1_t
93 {
94  typedef void (Tp::*_fun_type)(Arg);
95 public:
96  explicit mem_fun1_t(_fun_type pf) : M_f(pf) {}
97  void operator()(Tp* p, Arg x) const { (p->*M_f)(x); }
98 private:
99  _fun_type const M_f;
100 };
101 
102 template <class Tp, class Arg>
103 inline mem_fun1_t<Tp,Arg> mem_fun(void (Tp::*f)(Arg))
104 {
105  return mem_fun1_t<Tp,Arg>(f);
106 }
107 
111 {
112 public:
114  typedef ::std::output_iterator_tag iterator_category;
115  typedef void value_type;
116  typedef void reference;
117  typedef void pointer;
118  typedef size_t difference_type;
119 
120  OUStringBufferAppender(OUStringBuffer & i_rBuffer)
121  : m_rBuffer(&i_rBuffer) { }
122  Self & operator=(OUString const & i_rStr)
123  {
124  m_rBuffer->append( i_rStr );
125  return *this;
126  }
127  Self & operator*() { return *this; } // so operator= works
128  Self & operator++() { return *this; }
129 
130 private:
131  OUStringBuffer * m_rBuffer;
132 };
133 
136 template< typename ForwardIter, typename OutputIter, typename T >
137 OutputIter intersperse(
138  ForwardIter start, ForwardIter end, OutputIter out, T const & separator)
139 {
140  if (start != end) {
141  *out = *start;
142  ++start;
143  ++out;
144  }
145 
146  while (start != end) {
147  *out = separator;
148  ++out;
149  *out = *start;
150  ++start;
151  ++out;
152  }
153 
154  return out;
155 }
156 
157 }
158 
159 #endif // INCLUDED_COMPHELPER_STL_TYPES_HXX
160 
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator()(const OUString &lhs, std::u16string_view rhs) const
Definition: stl_types.hxx:60
UStringMixEqual(bool bCaseSensitive=true)
Definition: stl_types.hxx:59
OutputIter intersperse(ForwardIter start, ForwardIter end, OutputIter out, T const &separator)
algorithm similar to std::copy, but inserts a separator between elements.
Definition: stl_types.hxx:137
Reference
#define C
bool operator()(std::unique_ptr< T > const &lhs, std::unique_ptr< T > const &rhs) const
Definition: stl_types.hxx:70
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
output iterator that appends OUStrings into an OUStringBuffer.
Definition: stl_types.hxx:110
UStringMixLess(bool bCaseSensitive=true)
Definition: stl_types.hxx:42
bool ContainerUniquePtrEquals(C< std::unique_ptr< T >, Etc... > const &lhs, C< std::unique_ptr< T >, Etc... > const &rhs)
by-value implementation of std::foo>operator==
Definition: stl_types.hxx:81
by-value less functor for std::set>
Definition: stl_types.hxx:68
bool isCaseSensitive() const
Definition: stl_types.hxx:64
mem_fun1_t< Tp, Arg > mem_fun(void(Tp::*f)(Arg))
Definition: stl_types.hxx:103
OUStringBufferAppender Self
Definition: stl_types.hxx:113
Self & operator=(OUString const &i_rStr)
Definition: stl_types.hxx:122
bool operator()(const OUString &x, std::u16string_view y) const
Definition: stl_types.hxx:43
bool isCaseSensitive() const
Definition: stl_types.hxx:51
::std::output_iterator_tag iterator_category
Definition: stl_types.hxx:114
OUStringBufferAppender(OUStringBuffer &i_rBuffer)
Definition: stl_types.hxx:120
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo