/src/libreoffice/svl/source/items/cintitem.cxx
Line | Count | Source |
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 | | |
20 | | #include <com/sun/star/uno/Any.hxx> |
21 | | #include <o3tl/hash_combine.hxx> |
22 | | #include <svl/cintitem.hxx> |
23 | | #include <sal/log.hxx> |
24 | | |
25 | | |
26 | | // virtual |
27 | | bool CntByteItem::operator ==(const SfxPoolItem & rItem) const |
28 | 431k | { |
29 | 431k | assert(SfxPoolItem::operator==(rItem)); |
30 | 431k | return m_nValue == static_cast< const CntByteItem * >(&rItem)->m_nValue; |
31 | 431k | } |
32 | | |
33 | | // virtual |
34 | | bool CntByteItem::supportsHashCode() const |
35 | 3 | { |
36 | 3 | return true; |
37 | 3 | } |
38 | | |
39 | | // virtual |
40 | | size_t CntByteItem::hashCode() const |
41 | 33.5k | { |
42 | 33.5k | std::size_t seed(0); |
43 | 33.5k | o3tl::hash_combine(seed, Which()); |
44 | 33.5k | o3tl::hash_combine(seed, m_nValue); |
45 | 33.5k | return seed; |
46 | 33.5k | } |
47 | | |
48 | | // virtual |
49 | | bool CntByteItem::GetPresentation(SfxItemPresentation, MapUnit, MapUnit, |
50 | | OUString & rText, |
51 | | const IntlWrapper&) const |
52 | 0 | { |
53 | 0 | rText = OUString::number( m_nValue ); |
54 | 0 | return true; |
55 | 0 | } |
56 | | |
57 | | // virtual |
58 | | bool CntByteItem::QueryValue(css::uno::Any& rVal, sal_uInt8) const |
59 | 66 | { |
60 | 66 | sal_Int8 nValue = m_nValue; |
61 | 66 | rVal <<= nValue; |
62 | 66 | return true; |
63 | 66 | } |
64 | | |
65 | | // virtual |
66 | | bool CntByteItem::PutValue(const css::uno::Any& rVal, sal_uInt8) |
67 | 20.0k | { |
68 | 20.0k | sal_Int8 nValue = sal_Int8(); |
69 | 20.0k | if (rVal >>= nValue) |
70 | 20.0k | { |
71 | 20.0k | m_nValue = nValue; |
72 | 20.0k | return true; |
73 | 20.0k | } |
74 | | |
75 | 0 | SAL_WARN("svl.items", "CntByteItem::PutValue - Wrong type!"); |
76 | 0 | return false; |
77 | 0 | } |
78 | | |
79 | | // virtual |
80 | | CntByteItem* CntByteItem::Clone(SfxItemPool *) const |
81 | 0 | { |
82 | 0 | return new CntByteItem(*this); |
83 | 0 | } |
84 | | |
85 | | // virtual |
86 | | bool CntUInt16Item::operator ==(const SfxPoolItem & rItem) const |
87 | 4.74M | { |
88 | 4.74M | assert(SfxPoolItem::operator==(rItem)); |
89 | 4.74M | return m_nValue == static_cast<const CntUInt16Item *>(&rItem)->m_nValue; |
90 | 4.74M | } |
91 | | |
92 | | // virtual |
93 | | bool CntUInt16Item::supportsHashCode() const |
94 | 591k | { |
95 | 591k | return true; |
96 | 591k | } |
97 | | |
98 | | // virtual |
99 | | size_t CntUInt16Item::hashCode() const |
100 | 1.82M | { |
101 | 1.82M | std::size_t seed(0); |
102 | 1.82M | o3tl::hash_combine(seed, Which()); |
103 | 1.82M | o3tl::hash_combine(seed, m_nValue); |
104 | 1.82M | return seed; |
105 | 1.82M | } |
106 | | |
107 | | // virtual |
108 | | bool CntUInt16Item::GetPresentation(SfxItemPresentation, |
109 | | MapUnit, MapUnit, |
110 | | OUString & rText, |
111 | | const IntlWrapper&) |
112 | | const |
113 | 0 | { |
114 | 0 | rText = OUString::number( m_nValue ); |
115 | 0 | return true; |
116 | 0 | } |
117 | | |
118 | | // virtual |
119 | | bool CntUInt16Item::QueryValue(css::uno::Any& rVal, sal_uInt8) const |
120 | 1.36k | { |
121 | 1.36k | rVal <<= m_nValue; |
122 | 1.36k | return true; |
123 | 1.36k | } |
124 | | |
125 | | // virtual |
126 | | bool CntUInt16Item::PutValue(const css::uno::Any& rVal, sal_uInt8) |
127 | 2.18k | { |
128 | 2.18k | if (rVal >>= m_nValue) |
129 | 1.69k | return true; |
130 | | // Legacy: for a long time, CntUInt16Item::PutValue accepted sal_Int32; play safe and accept |
131 | | // if someone passes that |
132 | 489 | if (sal_Int32 nValue; rVal >>= nValue) |
133 | 489 | { |
134 | 489 | SAL_WARN("svl.items", "Passing sal_uInt16 in sal_Int32!"); |
135 | 489 | SAL_WARN_IF(nValue < 0 || nValue > SAL_MAX_UINT16, "svl.items", |
136 | 489 | "Overflow in UInt16 value!"); |
137 | 489 | m_nValue = static_cast<sal_uInt16>(nValue); |
138 | 489 | return true; |
139 | 489 | } |
140 | 0 | SAL_WARN("svl.items", "CntUInt16Item::PutValue - Wrong type!"); |
141 | 0 | return false; |
142 | 0 | } |
143 | | |
144 | | // virtual |
145 | | CntUInt16Item* CntUInt16Item::Clone(SfxItemPool *) const |
146 | 136k | { |
147 | 136k | return new CntUInt16Item(*this); |
148 | 136k | } |
149 | | |
150 | | // virtual |
151 | | bool CntInt32Item::operator ==(const SfxPoolItem & rItem) const |
152 | 7.71M | { |
153 | 7.71M | assert(SfxPoolItem::operator==(rItem)); |
154 | 7.71M | return m_nValue == static_cast<const CntInt32Item *>(&rItem)->m_nValue; |
155 | 7.71M | } |
156 | | |
157 | | // virtual |
158 | | bool CntInt32Item::supportsHashCode() const |
159 | 248k | { |
160 | 248k | return true; |
161 | 248k | } |
162 | | |
163 | | // virtual |
164 | | size_t CntInt32Item::hashCode() const |
165 | 6.23M | { |
166 | 6.23M | std::size_t seed(0); |
167 | 6.23M | o3tl::hash_combine(seed, Which()); |
168 | 6.23M | o3tl::hash_combine(seed, m_nValue); |
169 | 6.23M | return seed; |
170 | 6.23M | } |
171 | | |
172 | | // virtual |
173 | | bool CntInt32Item::GetPresentation(SfxItemPresentation, |
174 | | MapUnit, MapUnit, |
175 | | OUString & rText, |
176 | | const IntlWrapper&) const |
177 | 0 | { |
178 | 0 | rText = OUString::number( m_nValue ); |
179 | 0 | return true; |
180 | 0 | } |
181 | | |
182 | | // virtual |
183 | | bool CntInt32Item::QueryValue(css::uno::Any& rVal, sal_uInt8) const |
184 | 6.22k | { |
185 | 6.22k | sal_Int32 nValue = m_nValue; |
186 | 6.22k | rVal <<= nValue; |
187 | 6.22k | return true; |
188 | 6.22k | } |
189 | | |
190 | | // virtual |
191 | | bool CntInt32Item::PutValue(const css::uno::Any& rVal, sal_uInt8) |
192 | 294k | { |
193 | 294k | sal_Int32 nValue = 0; |
194 | 294k | if (rVal >>= nValue) |
195 | 294k | { |
196 | 294k | m_nValue = nValue; |
197 | 294k | return true; |
198 | 294k | } |
199 | | |
200 | 0 | SAL_WARN("svl.items", "CntInt32Item::PutValue - Wrong type!"); |
201 | 0 | return false; |
202 | 0 | } |
203 | | |
204 | | // virtual |
205 | | CntInt32Item* CntInt32Item::Clone(SfxItemPool *) const |
206 | 0 | { |
207 | 0 | return new CntInt32Item(*this); |
208 | 0 | } |
209 | | |
210 | | // virtual |
211 | | bool CntUInt32Item::operator ==(const SfxPoolItem & rItem) const |
212 | 4.60M | { |
213 | 4.60M | assert(SfxPoolItem::operator==(rItem)); |
214 | 4.60M | return m_nValue == static_cast<const CntUInt32Item *>(&rItem)->m_nValue; |
215 | 4.60M | } |
216 | | |
217 | | // virtual |
218 | | bool CntUInt32Item::supportsHashCode() const |
219 | 718k | { |
220 | 718k | return true; |
221 | 718k | } |
222 | | |
223 | | // virtual |
224 | | size_t CntUInt32Item::hashCode() const |
225 | 1.51M | { |
226 | 1.51M | std::size_t seed(0); |
227 | 1.51M | o3tl::hash_combine(seed, Which()); |
228 | 1.51M | o3tl::hash_combine(seed, m_nValue); |
229 | 1.51M | return seed; |
230 | 1.51M | } |
231 | | |
232 | | // virtual |
233 | | bool CntUInt32Item::GetPresentation(SfxItemPresentation, |
234 | | MapUnit, MapUnit, |
235 | | OUString & rText, |
236 | | const IntlWrapper&) |
237 | | const |
238 | 0 | { |
239 | 0 | rText = OUString::number(m_nValue); |
240 | 0 | return true; |
241 | 0 | } |
242 | | |
243 | | // virtual |
244 | | bool CntUInt32Item::QueryValue(css::uno::Any& rVal, sal_uInt8) const |
245 | 0 | { |
246 | 0 | sal_Int32 nValue = m_nValue; |
247 | 0 | SAL_WARN_IF(nValue < 0, "svl.items", "Overflow in UInt32 value!"); |
248 | 0 | rVal <<= nValue; |
249 | 0 | return true; |
250 | 0 | } |
251 | | |
252 | | // virtual |
253 | | bool CntUInt32Item::PutValue(const css::uno::Any& rVal, sal_uInt8) |
254 | 0 | { |
255 | 0 | sal_Int32 nValue = 0; |
256 | 0 | if (rVal >>= nValue) |
257 | 0 | { |
258 | 0 | SAL_WARN_IF(nValue < 0, "svl.items", "Overflow in UInt32 value!"); |
259 | 0 | m_nValue = nValue; |
260 | 0 | return true; |
261 | 0 | } |
262 | | |
263 | 0 | SAL_WARN("svl.items", "CntUInt32Item::PutValue - Wrong type!"); |
264 | 0 | return false; |
265 | 0 | } |
266 | | |
267 | | // virtual |
268 | | CntUInt32Item* CntUInt32Item::Clone(SfxItemPool *) const |
269 | 0 | { |
270 | 0 | return new CntUInt32Item(*this); |
271 | 0 | } |
272 | | |
273 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |