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