1 | /* |
2 | * SPDX-FileCopyrightText: 2019 Jonathan Rubenstein <jrubcop@gmail.com> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "binary_data_p.h" |
8 | #include "unit_p.h" |
9 | |
10 | #include <KLocalizedString> |
11 | |
12 | #include <math.h> |
13 | |
14 | namespace KUnitConversion |
15 | { |
16 | class BinaryPowerOfTwoUnitPrivate : public UnitPrivate |
17 | { |
18 | public: |
19 | BinaryPowerOfTwoUnitPrivate(CategoryId categoryId, |
20 | UnitId id, |
21 | qreal multiplier, |
22 | const QString &symbol, |
23 | const QString &description, |
24 | const QString &matchString, |
25 | const KLocalizedString &symbolString, |
26 | const KLocalizedString &realString, |
27 | const KLocalizedString &integerString) |
28 | : UnitPrivate(categoryId, id, multiplier, symbol, description, matchString, symbolString, realString, integerString) |
29 | { |
30 | } |
31 | |
32 | qreal toDefault(qreal value) const override |
33 | { |
34 | return value * pow(x: 2.0, y: m_multiplier); |
35 | } |
36 | qreal fromDefault(qreal value) const override |
37 | { |
38 | return value / pow(x: 2.0, y: m_multiplier); |
39 | } |
40 | }; |
41 | |
42 | UnitCategory BinaryData::makeCategory() |
43 | { |
44 | auto c = UnitCategoryPrivate::makeCategory(id: BinaryDataCategory, i18n("Binary Data" ), i18n("Binary Data Size" )); |
45 | auto d = UnitCategoryPrivate::get(category: c); |
46 | KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (binary data)" , "%1 %2" ); |
47 | |
48 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
49 | Yobibyte, |
50 | 83, |
51 | i18nc("binary data unit symbol" , "YiB" ), |
52 | i18nc("unit description in lists" , "yobibytes" ), |
53 | i18nc("unit synonyms for matching user input" , "YiB;yobibyte;yobibytes" ), |
54 | symbolString, |
55 | ki18nc("amount in units (real)" , "%1 yobibytes" ), |
56 | ki18ncp("amount in units (integer)" , "%1 yobibyte" , "%1 yobibytes" )))); |
57 | |
58 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
59 | Yobibit, |
60 | 80, |
61 | i18nc("binary data unit symbol" , "Yib" ), |
62 | i18nc("unit description in lists" , "yobibits" ), |
63 | i18nc("unit synonyms for matching user input" , "Yib;yobibit;yobibits" ), |
64 | symbolString, |
65 | ki18nc("amount in units (real)" , "%1 yobibits" ), |
66 | ki18ncp("amount in units (integer)" , "%1 yobibit" , "%1 yobibits" )))); |
67 | |
68 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
69 | id: Yottabyte, |
70 | multiplier: 8e+24, |
71 | i18nc("binary data unit symbol" , "YB" ), |
72 | i18nc("unit description in lists" , "yottabytes" ), |
73 | i18nc("unit synonyms for matching user input" , "YB;yottabyte;yottabytes" ), |
74 | symbolString, |
75 | ki18nc("amount in units (real)" , "%1 yottabytes" ), |
76 | ki18ncp("amount in units (integer)" , "%1 yottabyte" , "%1 yottabytes" ))); |
77 | |
78 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
79 | id: Yottabit, |
80 | multiplier: 1e+24, |
81 | i18nc("binary data unit symbol" , "Yb" ), |
82 | i18nc("unit description in lists" , "yottabits" ), |
83 | i18nc("unit synonyms for matching user input" , "Yb;yottabit;yottabits" ), |
84 | symbolString, |
85 | ki18nc("amount in units (real)" , "%1 yottabits" ), |
86 | ki18ncp("amount in units (integer)" , "%1 yottabit" , "%1 yottabits" ))); |
87 | |
88 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
89 | Zebibyte, |
90 | 73, |
91 | i18nc("binary data unit symbol" , "ZiB" ), |
92 | i18nc("unit description in lists" , "zebibytes" ), |
93 | i18nc("unit synonyms for matching user input" , "ZiB;zebibyte;zebibytes" ), |
94 | symbolString, |
95 | ki18nc("amount in units (real)" , "%1 zebibytes" ), |
96 | ki18ncp("amount in units (integer)" , "%1 zebibyte" , "%1 zebibytes" )))); |
97 | |
98 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
99 | Zebibit, |
100 | 70, |
101 | i18nc("binary data unit symbol" , "Zib" ), |
102 | i18nc("unit description in lists" , "zebibits" ), |
103 | i18nc("unit synonyms for matching user input" , "Zib;zebibit;zebibits" ), |
104 | symbolString, |
105 | ki18nc("amount in units (real)" , "%1 zebibits" ), |
106 | ki18ncp("amount in units (integer)" , "%1 zebibit" , "%1 zebibits" )))); |
107 | |
108 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
109 | id: Zettabyte, |
110 | multiplier: 8e+21, |
111 | i18nc("binary data unit symbol" , "ZB" ), |
112 | i18nc("unit description in lists" , "zettabytes" ), |
113 | i18nc("unit synonyms for matching user input" , "ZB;zettabyte;zettabytes" ), |
114 | symbolString, |
115 | ki18nc("amount in units (real)" , "%1 zettabytes" ), |
116 | ki18ncp("amount in units (integer)" , "%1 zettabyte" , "%1 zettabytes" ))); |
117 | |
118 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
119 | id: Zettabit, |
120 | multiplier: 1e+21, |
121 | i18nc("binary data unit symbol" , "Zb" ), |
122 | i18nc("unit description in lists" , "zettabits" ), |
123 | i18nc("unit synonyms for matching user input" , "Zb;zettabit;zettabits" ), |
124 | symbolString, |
125 | ki18nc("amount in units (real)" , "%1 zettabits" ), |
126 | ki18ncp("amount in units (integer)" , "%1 zettabit" , "%1 zettabits" ))); |
127 | |
128 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
129 | Exbibyte, |
130 | 63, |
131 | i18nc("binary data unit symbol" , "EiB" ), |
132 | i18nc("unit description in lists" , "exbibytes" ), |
133 | i18nc("unit synonyms for matching user input" , "EiB;exbibyte;exbibytes" ), |
134 | symbolString, |
135 | ki18nc("amount in units (real)" , "%1 exbibytes" ), |
136 | ki18ncp("amount in units (integer)" , "%1 exbibyte" , "%1 exbibytes" )))); |
137 | |
138 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
139 | Exbibit, |
140 | 60, |
141 | i18nc("binary data unit symbol" , "Eib" ), |
142 | i18nc("unit description in lists" , "exbibits" ), |
143 | i18nc("unit synonyms for matching user input" , "Eib;exbibit;exbibits" ), |
144 | symbolString, |
145 | ki18nc("amount in units (real)" , "%1 exbibits" ), |
146 | ki18ncp("amount in units (integer)" , "%1 exbibit" , "%1 exbibits" )))); |
147 | |
148 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
149 | id: Exabyte, |
150 | multiplier: 8e+18, |
151 | i18nc("binary data unit symbol" , "EB" ), |
152 | i18nc("unit description in lists" , "exabytes" ), |
153 | i18nc("unit synonyms for matching user input" , "EB;exabyte;exabytes" ), |
154 | symbolString, |
155 | ki18nc("amount in units (real)" , "%1 exabytes" ), |
156 | ki18ncp("amount in units (integer)" , "%1 exabyte" , "%1 exabytes" ))); |
157 | |
158 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
159 | id: Exabit, |
160 | multiplier: 1e+18, |
161 | i18nc("binary data unit symbol" , "Eb" ), |
162 | i18nc("unit description in lists" , "exabits" ), |
163 | i18nc("unit synonyms for matching user input" , "Eb;exabit;exabits" ), |
164 | symbolString, |
165 | ki18nc("amount in units (real)" , "%1 exabits" ), |
166 | ki18ncp("amount in units (integer)" , "%1 exabit" , "%1 exabits" ))); |
167 | |
168 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
169 | Pebibyte, |
170 | 53, |
171 | i18nc("binary data unit symbol" , "PiB" ), |
172 | i18nc("unit description in lists" , "pebibytes" ), |
173 | i18nc("unit synonyms for matching user input" , "PiB;pebibyte;pebibytes" ), |
174 | symbolString, |
175 | ki18nc("amount in units (real)" , "%1 pebibytes" ), |
176 | ki18ncp("amount in units (integer)" , "%1 pebibyte" , "%1 pebibytes" )))); |
177 | |
178 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
179 | Pebibit, |
180 | 50, |
181 | i18nc("binary data unit symbol" , "Pib" ), |
182 | i18nc("unit description in lists" , "pebibits" ), |
183 | i18nc("unit synonyms for matching user input" , "Pib;pebibit;pebibits" ), |
184 | symbolString, |
185 | ki18nc("amount in units (real)" , "%1 pebibits" ), |
186 | ki18ncp("amount in units (integer)" , "%1 pebibit" , "%1 pebibits" )))); |
187 | |
188 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
189 | id: Petabyte, |
190 | multiplier: 8e+15, |
191 | i18nc("binary data unit symbol" , "PB" ), |
192 | i18nc("unit description in lists" , "petabytes" ), |
193 | i18nc("unit synonyms for matching user input" , "PB;petabyte;petabytes" ), |
194 | symbolString, |
195 | ki18nc("amount in units (real)" , "%1 petabytes" ), |
196 | ki18ncp("amount in units (integer)" , "%1 petabyte" , "%1 petabytes" ))); |
197 | |
198 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
199 | id: Petabit, |
200 | multiplier: 1e+15, |
201 | i18nc("binary data unit symbol" , "Pb" ), |
202 | i18nc("unit description in lists" , "petabits" ), |
203 | i18nc("unit synonyms for matching user input" , "Pb;petabit;petabits" ), |
204 | symbolString, |
205 | ki18nc("amount in units (real)" , "%1 petabits" ), |
206 | ki18ncp("amount in units (integer)" , "%1 petabit" , "%1 petabits" ))); |
207 | |
208 | d->addCommonUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
209 | Tebibyte, |
210 | 43, |
211 | i18nc("binary data unit symbol" , "TiB" ), |
212 | i18nc("unit description in lists" , "tebibytes" ), |
213 | i18nc("unit synonyms for matching user input" , "TiB;tebibyte;tebibytes" ), |
214 | symbolString, |
215 | ki18nc("amount in units (real)" , "%1 tebibytes" ), |
216 | ki18ncp("amount in units (integer)" , "%1 tebibyte" , "%1 tebibytes" )))); |
217 | |
218 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
219 | Tebibit, |
220 | 40, |
221 | i18nc("binary data unit symbol" , "Tib" ), |
222 | i18nc("unit description in lists" , "tebibits" ), |
223 | i18nc("unit synonyms for matching user input" , "Tib;tebibit;tebibits" ), |
224 | symbolString, |
225 | ki18nc("amount in units (real)" , "%1 tebibits" ), |
226 | ki18ncp("amount in units (integer)" , "%1 tebibit" , "%1 tebibits" )))); |
227 | |
228 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
229 | id: Terabyte, |
230 | multiplier: 8e+12, |
231 | i18nc("binary data unit symbol" , "TB" ), |
232 | i18nc("unit description in lists" , "terabytes" ), |
233 | i18nc("unit synonyms for matching user input" , "TB;terabyte;terabytes" ), |
234 | symbolString, |
235 | ki18nc("amount in units (real)" , "%1 terabytes" ), |
236 | ki18ncp("amount in units (integer)" , "%1 terabyte" , "%1 terabytes" ))); |
237 | |
238 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
239 | id: Terabit, |
240 | multiplier: 1e+12, |
241 | i18nc("binary data unit symbol" , "Tb" ), |
242 | i18nc("unit description in lists" , "terabits" ), |
243 | i18nc("unit synonyms for matching user input" , "Tb;terabit;terabits" ), |
244 | symbolString, |
245 | ki18nc("amount in units (real)" , "%1 terabits" ), |
246 | ki18ncp("amount in units (integer)" , "%1 terabit" , "%1 terabits" ))); |
247 | |
248 | d->addCommonUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
249 | Gibibyte, |
250 | 33, |
251 | i18nc("binary data unit symbol" , "GiB" ), |
252 | i18nc("unit description in lists" , "gibibytes" ), |
253 | i18nc("unit synonyms for matching user input" , "GiB;gibibyte;gibibytes" ), |
254 | symbolString, |
255 | ki18nc("amount in units (real)" , "%1 gibibytes" ), |
256 | ki18ncp("amount in units (integer)" , "%1 gibibyte" , "%1 gibibytes" )))); |
257 | |
258 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
259 | Gibibit, |
260 | 30, |
261 | i18nc("binary data unit symbol" , "Gib" ), |
262 | i18nc("unit description in lists" , "gibibits" ), |
263 | i18nc("unit synonyms for matching user input" , "Gib;gibibit;gibibits" ), |
264 | symbolString, |
265 | ki18nc("amount in units (real)" , "%1 gibibits" ), |
266 | ki18ncp("amount in units (integer)" , "%1 gibibit" , "%1 gibibits" )))); |
267 | |
268 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
269 | id: Gigabyte, |
270 | multiplier: 8e+09, |
271 | i18nc("binary data unit symbol" , "GB" ), |
272 | i18nc("unit description in lists" , "gigabytes" ), |
273 | i18nc("unit synonyms for matching user input" , "GB;gigabyte;gigabytes" ), |
274 | symbolString, |
275 | ki18nc("amount in units (real)" , "%1 gigabytes" ), |
276 | ki18ncp("amount in units (integer)" , "%1 gigabyte" , "%1 gigabytes" ))); |
277 | |
278 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
279 | id: Gigabit, |
280 | multiplier: 1e+09, |
281 | i18nc("binary data unit symbol" , "Gb" ), |
282 | i18nc("unit description in lists" , "gigabits" ), |
283 | i18nc("unit synonyms for matching user input" , "Gb;gigabit;gigabits" ), |
284 | symbolString, |
285 | ki18nc("amount in units (real)" , "%1 gigabits" ), |
286 | ki18ncp("amount in units (integer)" , "%1 gigabit" , "%1 gigabits" ))); |
287 | |
288 | d->addCommonUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
289 | Mebibyte, |
290 | 23, |
291 | i18nc("binary data unit symbol" , "MiB" ), |
292 | i18nc("unit description in lists" , "mebibytes" ), |
293 | i18nc("unit synonyms for matching user input" , "MiB;mebibyte;mebibytes" ), |
294 | symbolString, |
295 | ki18nc("amount in units (real)" , "%1 mebibytes" ), |
296 | ki18ncp("amount in units (integer)" , "%1 mebibyte" , "%1 mebibytes" )))); |
297 | |
298 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BinaryPowerOfTwoUnitPrivate(BinaryDataCategory, |
299 | Mebibit, |
300 | 20, |
301 | i18nc("binary data unit symbol" , "Mib" ), |
302 | i18nc("unit description in lists" , "mebibits" ), |
303 | i18nc("unit synonyms for matching user input" , "Mib;mebibit;mebibits" ), |
304 | symbolString, |
305 | ki18nc("amount in units (real)" , "%1 mebibits" ), |
306 | ki18ncp("amount in units (integer)" , "%1 mebibit" , "%1 mebibits" )))); |
307 | |
308 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
309 | id: Megabyte, |
310 | multiplier: 8e+06, |
311 | i18nc("binary data unit symbol" , "MB" ), |
312 | i18nc("unit description in lists" , "megabytes" ), |
313 | i18nc("unit synonyms for matching user input" , "MB;megabyte;megabytes" ), |
314 | symbolString, |
315 | ki18nc("amount in units (real)" , "%1 megabytes" ), |
316 | ki18ncp("amount in units (integer)" , "%1 megabyte" , "%1 megabytes" ))); |
317 | |
318 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
319 | id: Megabit, |
320 | multiplier: 1e+06, |
321 | i18nc("binary data unit symbol" , "Mb" ), |
322 | i18nc("unit description in lists" , "megabits" ), |
323 | i18nc("unit synonyms for matching user input" , "Mb;megabit;megabits" ), |
324 | symbolString, |
325 | ki18nc("amount in units (real)" , "%1 megabits" ), |
326 | ki18ncp("amount in units (integer)" , "%1 megabit" , "%1 megabits" ))); |
327 | |
328 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
329 | id: Kibibyte, |
330 | multiplier: 8192, |
331 | i18nc("binary data unit symbol" , "KiB" ), |
332 | i18nc("unit description in lists" , "kibibytes" ), |
333 | i18nc("unit synonyms for matching user input" , "KiB;kiB;kibibyte;kibibytes" ), |
334 | symbolString, |
335 | ki18nc("amount in units (real)" , "%1 kibibytes" ), |
336 | ki18ncp("amount in units (integer)" , "%1 kibibyte" , "%1 kibibytes" ))); |
337 | |
338 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
339 | id: Kibibit, |
340 | multiplier: 1024, |
341 | i18nc("binary data unit symbol" , "Kib" ), |
342 | i18nc("unit description in lists" , "kibibits" ), |
343 | i18nc("unit synonyms for matching user input" , "Kib;kib;kibibit;kibibits" ), |
344 | symbolString, |
345 | ki18nc("amount in units (real)" , "%1 kibibits" ), |
346 | ki18ncp("amount in units (integer)" , "%1 kibibit" , "%1 kibibits" ))); |
347 | |
348 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
349 | id: Kilobyte, |
350 | multiplier: 8000, |
351 | i18nc("binary data unit symbol" , "kB" ), |
352 | i18nc("unit description in lists" , "kilobytes" ), |
353 | i18nc("unit synonyms for matching user input" , "kB;KB;kilobyte;kilobytes" ), |
354 | symbolString, |
355 | ki18nc("amount in units (real)" , "%1 kilobytes" ), |
356 | ki18ncp("amount in units (integer)" , "%1 kilobyte" , "%1 kilobytes" ))); |
357 | |
358 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
359 | id: Kilobit, |
360 | multiplier: 1000, |
361 | i18nc("binary data unit symbol" , "kb" ), |
362 | i18nc("unit description in lists" , "kilobits" ), |
363 | i18nc("unit synonyms for matching user input" , "kb;Kb;kilobit;kilobits" ), |
364 | symbolString, |
365 | ki18nc("amount in units (real)" , "%1 kilobits" ), |
366 | ki18ncp("amount in units (integer)" , "%1 kilobit" , "%1 kilobits" ))); |
367 | |
368 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
369 | id: Byte, |
370 | multiplier: 8, |
371 | i18nc("binary data unit symbol" , "B" ), |
372 | i18nc("unit description in lists" , "bytes" ), |
373 | i18nc("unit synonyms for matching user input" , "B;byte;bytes" ), |
374 | symbolString, |
375 | ki18nc("amount in units (real)" , "%1 bytes" ), |
376 | ki18ncp("amount in units (integer)" , "%1 byte" , "%1 bytes" ))); |
377 | |
378 | d->addDefaultUnit(unit: UnitPrivate::makeUnit(categoryId: BinaryDataCategory, |
379 | id: Bit, |
380 | multiplier: 1, |
381 | i18nc("binary data unit symbol" , "b" ), |
382 | i18nc("unit description in lists" , "bits" ), |
383 | i18nc("unit synonyms for matching user input" , "b;bit;bits" ), |
384 | symbolString, |
385 | ki18nc("amount in units (real)" , "%1 bits" ), |
386 | ki18ncp("amount in units (integer)" , "%1 bit" , "%1 bits" ))); |
387 | |
388 | return c; |
389 | } |
390 | |
391 | } // KUnitConversion namespace |
392 | |