LibreOffice Module svl (master) 1
sharedstring.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
10#ifndef INCLUDED_SVL_SHAREDSTRING_HXX
11#define INCLUDED_SVL_SHAREDSTRING_HXX
12
13#include <svl/svldllapi.h>
14#include <rtl/ustring.hxx>
15
16#include <utility>
17
18namespace svl {
19
21{
22 rtl_uString* mpData = nullptr;
23 rtl_uString* mpDataIgnoreCase = nullptr;
24public:
25
26 static const SharedString & getEmptyString();
27 static const OUString EMPTY_STRING;
28
29 SharedString() = default;
30 SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase );
31 explicit SharedString( const OUString& rStr );
32 SharedString( const SharedString& r );
33 SharedString(SharedString&& r) noexcept;
35
36 SharedString& operator= ( const SharedString& r );
37 SharedString& operator=(SharedString&& r) noexcept;
38
39 bool operator== ( const SharedString& r ) const;
40 bool operator!= ( const SharedString& r ) const;
41
42 const OUString & getString() const;
43 const OUString & getIgnoreCaseString() const;
44
45 rtl_uString* getData();
46 const rtl_uString* getData() const;
47
48 rtl_uString* getDataIgnoreCase();
49 const rtl_uString* getDataIgnoreCase() const;
50
51 bool isValid() const;
52 bool isEmpty() const;
53
54 sal_Int32 getLength() const;
55};
56
57inline SharedString::SharedString( rtl_uString* pData, rtl_uString* pDataIgnoreCase ) :
58 mpData(pData), mpDataIgnoreCase(pDataIgnoreCase)
59{
60 if (mpData)
61 rtl_uString_acquire(mpData);
63 rtl_uString_acquire(mpDataIgnoreCase);
64}
65
66inline SharedString::SharedString( const OUString& rStr ) : mpData(rStr.pData)
67{
68 rtl_uString_acquire(mpData);
69}
70
71inline SharedString::SharedString( const SharedString& r ) : mpData(r.mpData), mpDataIgnoreCase(r.mpDataIgnoreCase)
72{
73 if (mpData)
74 rtl_uString_acquire(mpData);
76 rtl_uString_acquire(mpDataIgnoreCase);
77}
78
80 : mpData(std::exchange(r.mpData, nullptr))
81 , mpDataIgnoreCase(std::exchange(r.mpDataIgnoreCase, nullptr))
82{
83}
84
86{
87 if (mpData)
88 rtl_uString_release(mpData);
90 rtl_uString_release(mpDataIgnoreCase);
91}
92
94{
95 // Having this inline helps Calc's mdds::multi_type_vector to do some operations
96 // much faster.
97 if (mpData)
98 rtl_uString_release(mpData);
99 if (mpDataIgnoreCase)
100 rtl_uString_release(mpDataIgnoreCase);
101
102 mpData = std::exchange(r.mpData, nullptr);
103 mpDataIgnoreCase = std::exchange(r.mpDataIgnoreCase, nullptr);
104
105 return *this;
106}
107
108inline bool SharedString::operator!= ( const SharedString& r ) const
109{
110 return !operator== (r);
111}
112
113inline const OUString & SharedString::getString() const
114{
115 return mpData ? OUString::unacquired(&mpData) : EMPTY_STRING;
116}
117
118inline const OUString & SharedString::getIgnoreCaseString() const
119{
120 return mpDataIgnoreCase ? OUString::unacquired(&mpDataIgnoreCase) : EMPTY_STRING;
121}
122
123inline rtl_uString* SharedString::getData()
124{
125 return mpData;
126}
127
128inline const rtl_uString* SharedString::getData() const
129{
130 return mpData;
131}
132
134{
135 return mpDataIgnoreCase;
136}
137
138inline const rtl_uString* SharedString::getDataIgnoreCase() const
139{
140 return mpDataIgnoreCase;
141}
142
143inline bool SharedString::isValid() const
144{
145 return mpData != nullptr;
146}
147
148inline bool SharedString::isEmpty() const
149{
150 return mpData == nullptr || mpData->length == 0;
151}
152
153inline sal_Int32 SharedString::getLength() const
154{
155 return mpData ? mpData->length : 0;
156}
157
158}
159
160#endif
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl_uString * mpDataIgnoreCase
static const OUString EMPTY_STRING
const OUString & getString() const
SharedString & operator=(const SharedString &r)
rtl_uString * getDataIgnoreCase()
const OUString & getIgnoreCaseString() const
bool isEmpty() const
SharedString()=default
bool operator==(const SharedString &r) const
rtl_uString * mpData
bool isValid() const
sal_Int32 getLength() const
rtl_uString * getData()
bool operator!=(const SharedString &r) const
std::unique_ptr< sal_Int32[]> pData
double getLength(const B2DPolygon &rCandidate)
OUString getString(const Any &_rAny)
#define SVL_DLLPUBLIC
Definition: svldllapi.h:28
constexpr bool operator!=(TypedWhichId< T > const &lhs, TypedWhichId< T > rhs)
Definition: typedwhich.hxx:47
constexpr bool operator==(TypedWhichId< T > const &lhs, TypedWhichId< T > rhs)
Definition: typedwhich.hxx:43