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#include <o3tl/string_view.hxx>
31
32namespace com::sun::star::uno { template <typename > class Reference; }
33
34namespace comphelper
35{
36
37// comparison functors
38
40{
42public:
43 UStringMixLess(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
44 bool operator() (std::u16string_view x, std::u16string_view y) const
45 {
47 return x < y;
48 else
50 }
51
52 bool isCaseSensitive() const {return m_bCaseSensitive;}
53};
54
56{
57 bool const m_bCaseSensitive;
58
59public:
60 UStringMixEqual(bool bCaseSensitive = true):m_bCaseSensitive(bCaseSensitive){}
61 bool operator() (std::u16string_view lhs, std::u16string_view rhs) const
62 {
63 return m_bCaseSensitive ? lhs == rhs : o3tl::equalsIgnoreAsciiCase( lhs, rhs );
64 }
65 bool isCaseSensitive() const {return m_bCaseSensitive;}
66};
67
69template<class T> struct UniquePtrValueLess
70{
71 bool operator()(std::unique_ptr<T> const& lhs,
72 std::unique_ptr<T> const& rhs) const
73 {
74 assert(lhs.get());
75 assert(rhs.get());
76 return (*lhs) < (*rhs);
77 }
78 // The following are so we can search in std::set without allocating a temporary entry on the heap
79 typedef bool is_transparent;
80 bool operator()(T const& lhs,
81 std::unique_ptr<T> const& rhs) const
82 {
83 assert(rhs.get());
84 return lhs < (*rhs);
85 }
86 bool operator()(std::unique_ptr<T> const& lhs,
87 T const& rhs) const
88 {
89 assert(lhs.get());
90 return (*lhs) < rhs;
91 }
92};
93
95template<template<typename, typename...> class C, typename T, typename... Etc>
97 C<std::unique_ptr<T>, Etc...> const& lhs,
98 C<std::unique_ptr<T>, Etc...> const& rhs)
99{
100 return lhs.size() == rhs.size()
101 && std::equal(lhs.begin(), lhs.end(), rhs.begin(),
102 [](const auto& p1, const auto& p2) { return *p1 == *p2; });
103};
104
105
106template <class Tp, class Arg>
107class mem_fun1_t
108{
109 typedef void (Tp::*_fun_type)(Arg);
110public:
111 explicit mem_fun1_t(_fun_type pf) : M_f(pf) {}
112 void operator()(Tp* p, Arg x) const { (p->*M_f)(x); }
113private:
114 _fun_type const M_f;
115};
116
117template <class Tp, class Arg>
118inline mem_fun1_t<Tp,Arg> mem_fun(void (Tp::*f)(Arg))
119{
120 return mem_fun1_t<Tp,Arg>(f);
121}
122
126{
127public:
129 typedef ::std::output_iterator_tag iterator_category;
130 typedef void value_type;
131 typedef void reference;
132 typedef void pointer;
133 typedef size_t difference_type;
134
135 OUStringBufferAppender(OUStringBuffer & i_rBuffer)
136 : m_rBuffer(&i_rBuffer) { }
137 Self & operator=(std::u16string_view i_rStr)
138 {
139 m_rBuffer->append( i_rStr );
140 return *this;
141 }
142 Self & operator*() { return *this; } // so operator= works
143 Self & operator++() { return *this; }
144
145private:
146 OUStringBuffer * m_rBuffer;
147};
148
151template< typename ForwardIter, typename OutputIter, typename T >
152OutputIter intersperse(
153 ForwardIter start, ForwardIter end, OutputIter out, T const & separator)
154{
155 if (start != end) {
156 *out = *start;
157 ++start;
158 ++out;
159 }
160
161 while (start != end) {
162 *out = separator;
163 ++out;
164 *out = *start;
165 ++start;
166 ++out;
167 }
168
169 return out;
170}
171
172}
173
174#endif // INCLUDED_COMPHELPER_STL_TYPES_HXX
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
output iterator that appends OUStrings into an OUStringBuffer.
Definition: stl_types.hxx:126
::std::output_iterator_tag iterator_category
Definition: stl_types.hxx:129
OUStringBufferAppender(OUStringBuffer &i_rBuffer)
Definition: stl_types.hxx:135
OUStringBufferAppender Self
Definition: stl_types.hxx:128
Self & operator=(std::u16string_view i_rStr)
Definition: stl_types.hxx:137
bool operator()(std::u16string_view lhs, std::u16string_view rhs) const
Definition: stl_types.hxx:61
bool isCaseSensitive() const
Definition: stl_types.hxx:65
UStringMixEqual(bool bCaseSensitive=true)
Definition: stl_types.hxx:60
float y
float x
void * p
bool ContainerUniquePtrEquals(C< std::unique_ptr< T >, Etc... > const &lhs, C< std::unique_ptr< T >, Etc... > const &rhs)
by-value implementation of std::foo<std::unique_ptr<T>>::operator==
Definition: stl_types.hxx:96
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:152
mem_fun1_t< Tp, Arg > mem_fun(void(Tp::*f)(Arg))
Definition: stl_types.hxx:118
Reference
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
int compareToIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
end
void(* f)(TrueTypeTable *)
bool isCaseSensitive() const
Definition: stl_types.hxx:52
bool operator()(std::u16string_view x, std::u16string_view y) const
Definition: stl_types.hxx:44
UStringMixLess(bool bCaseSensitive=true)
Definition: stl_types.hxx:43
by-value less functor for std::set<std::unique_ptr<T>>
Definition: stl_types.hxx:70
bool operator()(T const &lhs, std::unique_ptr< T > const &rhs) const
Definition: stl_types.hxx:80
bool operator()(std::unique_ptr< T > const &lhs, T const &rhs) const
Definition: stl_types.hxx:86
bool operator()(std::unique_ptr< T > const &lhs, std::unique_ptr< T > const &rhs) const
Definition: stl_types.hxx:71
#define C