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