-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteSize.h
850 lines (696 loc) · 19.4 KB
/
ByteSize.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
/*
Copyright(c) 2018 - 2022 Mbadiwe Nnaemeka Ronald ron2tele@gmail.com
This software is provided 'as-is', without any express or implied
warranty.In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions :
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software.If you use this software
in a product, an acknowledgment in the product documentation must be
specified.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice must not be removed or altered from any source distribution.
*/
#pragma once
#ifndef BYTESIZE_H
#define BYTESIZE_H
#include <string>
#include <memory>
#include <vector>
#include <sstream>
#include <iomanip>
#include <math.h>
using namespace std;
// Unit of representation of byte sizes
enum ByteSizeUnit { BinaryUnit, DecimalUnit };
//////////////////////
//// Exceptions
/////////////////////
class FormatException
{
public:
FormatException(const char * text)
: msg_(text)
{} // end constructor
const char* what() const throw ()
{
return msg_.c_str();
} // end function what
private:
string msg_;
}; // end class FormatException
class ArgumentNullException
{
public:
ArgumentNullException(const char * text)
: msg_(text)
{} // end constructor
const char* what() const throw ()
{
return msg_.c_str();
} // end function what
private:
string msg_;
}; // end class ArgumentNullException
//////////////////////
//// ByteSize Class
/////////////////////
class ByteSize
{
//==================================================================
// Friend class
//==================================================================
friend ostream &operator<<(ostream &, const ByteSize &);
public:
ByteSize(const double byteSize = 0);
inline int64_t GetBits() const
{
return Bits;
}
inline double GetBytes() const
{
return Bytes;
}
inline double GetKiloBytes() const
{
return KiloBytes;
}
inline double GetKibiBytes() const
{
return KibiBytes;
}
inline double GetMegaBytes() const
{
return MegaBytes;
}
inline double GetMebiBytes() const
{
return MebiBytes;
}
inline double GetGigaBytes() const
{
return GigaBytes;
}
inline double GetGibiBytes() const
{
return GibiBytes;
}
inline double GetTeraBytes() const
{
return TeraBytes;
}
inline double GetTebiBytes() const
{
return TebiBytes;
}
inline double GetPetaBytes() const
{
return PetaBytes;
}
inline double GetPebiBytes() const
{
return PebiBytes;
}
static ByteSize FromBits(const int64_t value)
{
double tempDouble = (double)value / (double)BitsInByte;
return ByteSize(tempDouble);
}
static ByteSize FromBytes(const double value)
{
return ByteSize(value);
}
static ByteSize FromKiloBytes(const double value)
{
double tempDouble = double(value * BytesInKiloByte);
return ByteSize(tempDouble);
}
static ByteSize FromKibiBytes(const double value)
{
double tempDouble = double(value * BytesInKibiByte);
return ByteSize(tempDouble);
}
static ByteSize FromMegaBytes(const double value)
{
double tempDouble = double(value * BytesInMegaByte);
return ByteSize(tempDouble);
}
static ByteSize FromMebiBytes(const double value)
{
double tempDouble = double(value * BytesInMebiByte);
return ByteSize(tempDouble);
}
static ByteSize FromGigaBytes(const double value)
{
double tempDouble = double(value * BytesInGigaByte);
return ByteSize(tempDouble);
}
static ByteSize FromGibiBytes(const double value)
{
double tempDouble = double(value * BytesInGibiByte);
return ByteSize(tempDouble);
}
static ByteSize FromTeraBytes(const double value)
{
double tempDouble = double(value * BytesInTeraByte);
return ByteSize(tempDouble);
}
static ByteSize FromTebiBytes(const double value)
{
double tempDouble = double(value * BytesInTebiByte);
return ByteSize(tempDouble);
}
static ByteSize FromPetaBytes(const double value)
{
double tempDouble = double(value * BytesInPetaByte);
return ByteSize(tempDouble);
}
static ByteSize FromPebiBytes(const double value)
{
double tempDouble = double(value * BytesInPebiByte);
return ByteSize(tempDouble);
}
int CompareTo(const ByteSize &bs) const
{
// return an integer
if (Bits == bs.Bits) return 0;
else if (Bits < bs.Bits) return -1;
return 1;
}
ByteSize Add(const ByteSize &bs) const
{
return ByteSize(Bytes + bs.Bytes);
}
ByteSize AddBits(const int64_t value) const
{
return *this + FromBits(value);
}
ByteSize AddBytes(const double value) const
{
return *this + FromBytes(value);
}
ByteSize AddKiloBytes(const double value) const
{
return *this + FromKiloBytes(value);
}
ByteSize AddKibiBytes(const double value) const
{
return *this + FromKibiBytes(value);
}
ByteSize AddMegaBytes(const double value) const
{
return *this + FromMegaBytes(value);
}
ByteSize AddMebiBytes(const double value) const
{
return *this + FromMebiBytes(value);
}
ByteSize AddGigaBytes(const double value) const
{
return *this + FromGigaBytes(value);
}
ByteSize AddGibiBytes(const double value) const
{
return *this + FromGibiBytes(value);
}
ByteSize AddTeraBytes(const double value) const
{
return *this + FromTeraBytes(value);
}
ByteSize AddTebiBytes(const double value) const
{
return *this + FromTebiBytes(value);
}
ByteSize AddPetaBytes(const double value) const
{
return *this + FromPetaBytes(value);
}
ByteSize AddPebiBytes(const double value) const
{
return *this + FromPebiBytes(value);
}
ByteSize Subtract(const ByteSize &bs) const
{
return ByteSize(Bytes - bs.Bytes);
}
bool operator<(const ByteSize &bs) const
{
return Bits < bs.Bits;
}
bool operator<=(const ByteSize &bs) const
{
return Bits <= bs.Bits;
}
bool operator>(const ByteSize &bs) const
{
return Bits > bs.Bits;
}
bool operator>=(const ByteSize &bs) const
{
return Bits >= bs.Bits;
}
bool operator==(const ByteSize &bs) const
{
return Bits == bs.Bits;
}
bool operator!=(const ByteSize &bs) const
{
return Bits != bs.Bits;
}
ByteSize operator+(const ByteSize &bs) const
{
return Add(bs);
}
ByteSize operator+=(const ByteSize &bs)
{
*this = Add(bs);
return *this;
}
ByteSize operator-(const ByteSize &bs) const
{
return Subtract(bs);
}
ByteSize operator-=(const ByteSize &bs)
{
*this = Subtract(bs);
return *this;
}
ByteSize operator+()
{
return *this;
}
ByteSize operator-()
{
*this = ByteSize(-Bytes);
return *this;
}
string ToString(ByteSizeUnit unit_repr = ByteSizeUnit::BinaryUnit, int precision = 2) const
{
if (unit_repr == ByteSizeUnit::BinaryUnit)
return Output(
LargestWholeNumberValue(true, unit_repr),
LargestWholeNumberSymbol(true, unit_repr),
precision);
else if (unit_repr == ByteSizeUnit::DecimalUnit)
return Output(
LargestWholeNumberValue(true, unit_repr),
LargestWholeNumberSymbol(true, unit_repr),
precision);
else throw FormatException("Byte size unit is not in the correct format");
}
string ToString(string unit, int precision = 2) const
{
if (precision < 0) throw FormatException("Precision cannot be negative");
unit = StripAllWhiteSpace(unit, true);
if (unit.empty()) return Output(LargestWholeNumberValue(), LargestWholeNumberSymbol(), precision);
if (unit.size() != 1) {
if (EqualsIgnoreCase(unit, "PiB")) return Output(PebiBytes, "PiB", precision);
else if (EqualsIgnoreCase(unit, "PB")) return Output(PetaBytes, "PB", precision);
else if (EqualsIgnoreCase(unit, "TiB")) return Output(TebiBytes, "TiB", precision);
else if (EqualsIgnoreCase(unit, "TB")) return Output(TeraBytes, "TB", precision);
else if (EqualsIgnoreCase(unit, "GiB")) return Output(GibiBytes, "GiB", precision);
else if (EqualsIgnoreCase(unit, "GB")) return Output(GigaBytes, "GB", precision);
else if (EqualsIgnoreCase(unit, "MiB")) return Output(MebiBytes, "MiB", precision);
else if (EqualsIgnoreCase(unit, "MB")) return Output(MegaBytes, "MB", precision);
else if (EqualsIgnoreCase(unit, "KiB")) return Output(KibiBytes, "KiB", precision);
else if (EqualsIgnoreCase(unit, "KB")) return Output(KiloBytes, "KB", precision);
}
else {
// Byte and Bit symbol must be case-sensitive
if (IndexOf(ByteSymbol, unit, true) != -1) return Output(double(Bytes), "B", precision);
else if (IndexOf(BitSymbol, unit, true) != -1) return Output(double(Bits), "b", precision);
}
throw FormatException("Byte size unit is not in the correct format");
}
static ByteSize Parse(const string &s)
{
ByteSize bs(0);
if (!TryParse(s, bs))
throw FormatException("Value is not in the correct format");
return bs;
}
static bool TryParse(const string& s, ByteSize& bs)
{
string tempS, numberPart, sizePart;
bool found;
size_t count, lastNumber;
int tempInt;
double d1;
// Arg checking
if (IsNullOrWhiteSpace(s))
throw ArgumentNullException("Input String is null or whitespace");
// Get the index of the first non - digit character
tempS = StripAllWhiteSpace(s, true); // Protect against leading spaces
found = false;
// Pick first non - digit number
count = 1;
for (register size_t i = 0; i < tempS.size(); i++)
{
if (!(isdigit(tempS[i]) || tempS[i] == '.'))
{
found = true;
break;
}
count += 1;
}
if (!found) return false;
lastNumber = count - 1;
if (lastNumber == 0) return false;
// Cut the input string in half
numberPart = StripAllWhiteSpace(tempS.substr(0, lastNumber), true);
sizePart = StripAllWhiteSpace(tempS.substr(lastNumber));
// Get the numeric part
double number = atof(numberPart.c_str());
// Get the magnitude part
tempInt = -1;
for (register size_t i = 0; i < mags.size(); i++)
{
if (i > 1 && EqualsIgnoreCase(mags[i], sizePart.c_str()))
{
tempInt = int(i);
break;
}
else if (sizePart == mags[i]) // sensitive comparison for b and B symbols
{
tempInt = int(i);
break;
}
}
switch (tempInt)
{
case -1:
return false;
case 0:
d1 = 1 * 1.0;
if (FloatingMod(number, d1) != 0) // Can't have partial bits
return false;
bs = FromBits(int64_t(number));
return true;
case 1:
bs = FromBytes(number);
return true;
case 2:
bs = FromKibiBytes(number);
return true;
case 3:
bs = FromKiloBytes(number);
return true;
case 4:
bs = FromMebiBytes(number);
return true;
case 5:
bs = FromMegaBytes(number);
return true;
case 6:
bs = FromGibiBytes(number);
return true;
case 7:
bs = FromGigaBytes(number);
return true;
case 8:
bs = FromTebiBytes(number);
return true;
case 9:
bs = FromTeraBytes(number);
return true;
case 10:
bs = FromPebiBytes(number);
return true;
case 11:
bs = FromPetaBytes(number);
return true;
}
return false;
}
private:
static string ToUpper(const string &s)
{
string temp;
temp.resize(s.size());
for (register size_t i = 0; i < s.size(); i++)
temp[i] = toupper(s[i]);
return temp;
}
static bool EqualsIgnoreCase(const string& a, const string& b)
{
return _stricmp(a.c_str(), b.c_str()) == 0; // insensitive comparison
}
static bool Contains(const char InChar, const string &InString)
{
for (register size_t i = 0; i < InString.size(); i++)
{
if (InString[i] == InChar) return true;
}
return false;
}
static string StripAllWhiteSpace(const string &txt, const bool sides = false)
{
string temp = "";
if (txt.empty()) return "";
else if (sides)
{
size_t index1 = 0;
while (txt[index1] == ' ') index1++;
size_t index2 = txt.find_last_not_of(' ');
for (register size_t i = index1; i <= index2; i++)
{
if (txt[i] == ' ')
{
while (txt[i] == ' ') i++;
i--;
temp += ' ';
continue;
}
temp += txt[i];
}
}
else
{
for (register size_t i = 0; i < txt.size(); i++)
{
if (txt[i] == ' ') continue;
temp += txt[i];
}
}
return temp;
}
static int IndexOf(const string &SubStr, const string &Str, const bool caseSensitive)
{
// returns an integer
if (caseSensitive) return (int)Str.find(SubStr);
string _Str = ToUpper(Str);
string _SubStr = ToUpper(SubStr);
return (int)_Str.find(_SubStr);
}
static bool IsNullOrWhiteSpace(const string &InValue)
{
return StripAllWhiteSpace(InValue).size() == 0;
}
static double FloatingMod(const double a, const double b)
{
double tempDouble = (a / b);
return a - b * int64_t(tempDouble);
}
static ByteSize GetMinValue()
{
return FromBits(0);
}
static ByteSize GetMaxValue()
{
return FromBits(Int64MaxValue);
}
static size_t Count(const string &s, const char ch)
{
register size_t count = 0;
for (register size_t i = 0; i < s.size(); i++)
{
if (s[i] == ch) count++;
}
return count;
}
static string Output(const double n, const string &unit, const int precision)
{
double integer_part, decimal_part;
ostringstream ss;
ss.setf(ios::fixed, ios::floatfield);
ss.precision(precision);
decimal_part = modf(n, &integer_part);
if (decimal_part == 0) ss << (int)n;
else ss << n;
ss << " " << unit;
return ss.str();
}
static double ResolveDecimalPrecision(const double n, const int precision = 9)
{
ostringstream ss;
ss.setf(ios::fixed, ios::floatfield);
ss.precision(precision);
ss << n;
return (double)atof(ss.str().c_str());
}
private:
string LargestWholeNumberSymbol(bool check_repr = false, ByteSizeUnit unit_repr = ByteSizeUnit::BinaryUnit) const
{
if (check_repr) {
if (unit_repr == ByteSizeUnit::BinaryUnit)
{
// Absolute value is used to deal with negative values
if (abs(PebiBytes) >= 1) return PebiByteSymbol;
else if (abs(TebiBytes) >= 1) return TebiByteSymbol;
else if (abs(GibiBytes) >= 1) return GibiByteSymbol;
else if (abs(MebiBytes) >= 1) return MebiByteSymbol;
else if (abs(KibiBytes) >= 1) return KibiByteSymbol;
}
else if (unit_repr == ByteSizeUnit::DecimalUnit)
{
// Absolute value is used to deal with negative values
if (abs(PetaBytes) >= 1) return PetaByteSymbol;
else if (abs(TeraBytes) >= 1) return TeraByteSymbol;
else if (abs(GigaBytes) >= 1) return GigaByteSymbol;
else if (abs(MegaBytes) >= 1) return MegaByteSymbol;
else if (abs(KiloBytes) >= 1) return KiloByteSymbol;
}
}
else {
// Absolute value is used to deal with negative values
if (abs(PebiBytes) >= 1) return PebiByteSymbol;
else if (abs(PetaBytes) >= 1) return PetaByteSymbol;
else if (abs(TebiBytes) >= 1) return TebiByteSymbol;
else if (abs(TeraBytes) >= 1) return TeraByteSymbol;
else if (abs(GibiBytes) >= 1) return GibiByteSymbol;
else if (abs(GigaBytes) >= 1) return GigaByteSymbol;
else if (abs(MebiBytes) >= 1) return MebiByteSymbol;
else if (abs(MegaBytes) >= 1) return MegaByteSymbol;
else if (abs(KibiBytes) >= 1) return KibiByteSymbol;
else if (abs(KiloBytes) >= 1) return KiloByteSymbol;
}
if (abs(Bytes) >= 1) return ByteSymbol;
return BitSymbol;
}
double LargestWholeNumberValue(bool check_repr = false, ByteSizeUnit unit_repr = ByteSizeUnit::BinaryUnit) const
{
if (check_repr) {
if (unit_repr == ByteSizeUnit::BinaryUnit)
{
if (abs(PebiBytes) >= 1) return PebiBytes;
else if (abs(TebiBytes) >= 1) return TebiBytes;
else if (abs(GibiBytes) >= 1) return GibiBytes;
else if (abs(MebiBytes) >= 1) return MebiBytes;
else if (abs(KibiBytes) >= 1) return KibiBytes;
}
else if (unit_repr == ByteSizeUnit::DecimalUnit)
{
if (abs(PetaBytes) >= 1) return PetaBytes;
else if (abs(TeraBytes) >= 1) return TeraBytes;
else if (abs(GigaBytes) >= 1) return GigaBytes;
else if (abs(MegaBytes) >= 1) return MegaBytes;
else if (abs(KiloBytes) >= 1) return KiloBytes;
}
}
else {
// Absolute value is used to deal with negative values
if (abs(PebiBytes) >= 1) return PebiBytes;
else if (abs(PetaBytes) >= 1) return PetaBytes;
else if (abs(TebiBytes) >= 1) return TebiBytes;
else if (abs(TeraBytes) >= 1) return TeraBytes;
else if (abs(GibiBytes) >= 1) return GibiBytes;
else if (abs(GigaBytes) >= 1) return GigaBytes;
else if (abs(MebiBytes) >= 1) return MebiBytes;
else if (abs(MegaBytes) >= 1) return MegaBytes;
else if (abs(KibiBytes) >= 1) return KibiBytes;
else if (abs(KiloBytes) >= 1) return KiloBytes;
}
if (abs(Bytes) >= 1) return Bytes;
return double(Bits);
}
private:
// Binary Units
int64_t Bits;
double Bytes;
double KibiBytes;
double MebiBytes;
double GibiBytes;
double TebiBytes;
double PebiBytes;
// Decimal Units
double KiloBytes;
double MegaBytes;
double GigaBytes;
double TeraBytes;
double PetaBytes;
//
static const int64_t Int64MaxValue = 9223372036854775807;
static const int64_t BitsInByte = 8;
static const int64_t BytesInKibiByte = 1024;
static const int64_t BytesInMebiByte = 1048576;
static const int64_t BytesInGibiByte = 1073741824;
static const int64_t BytesInTebiByte = 1099511627776;
static const int64_t BytesInPebiByte = 1125899906842624;
static const int64_t BytesInKiloByte = 1000;
static const int64_t BytesInMegaByte = 1000000;
static const int64_t BytesInGigaByte = 1000000000;
static const int64_t BytesInTeraByte = 1000000000000;
static const int64_t BytesInPetaByte = 1000000000000000;
// Binary Units
static const char * BitSymbol;
static const char * ByteSymbol;
static const char * KibiByteSymbol;
static const char * MebiByteSymbol;
static const char * GibiByteSymbol;
static const char * TebiByteSymbol;
static const char * PebiByteSymbol;
// Decimal Units
static const char * KiloByteSymbol;
static const char * MegaByteSymbol;
static const char * GigaByteSymbol;
static const char * TeraByteSymbol;
static const char * PetaByteSymbol;
static const vector<char*> mags;
};
#pragma region Binary Units
const char* ByteSize::BitSymbol = "b";
const char* ByteSize::ByteSymbol = "B";
const char* ByteSize::KibiByteSymbol = "KiB";
const char* ByteSize::MebiByteSymbol = "MiB";
const char* ByteSize::GibiByteSymbol = "GiB";
const char* ByteSize::TebiByteSymbol = "TiB";
const char* ByteSize::PebiByteSymbol = "PiB";
#pragma endregion
#pragma region Decimal Units
const char* ByteSize::KiloByteSymbol = "KB";
const char* ByteSize::MegaByteSymbol = "MB";
const char* ByteSize::GigaByteSymbol = "GB";
const char* ByteSize::TeraByteSymbol = "TB";
const char* ByteSize::PetaByteSymbol = "PB";
#pragma endregion
//
const vector<char*> ByteSize::mags = vector<char*>({
"b", "B", "KiB", "KB", "MiB", "MB",
"GiB", "GB", "TiB", "TB", "PiB", "PB"});
ByteSize::ByteSize(const double byteSize)
{
double tempDouble = byteSize * BitsInByte;
// Get Truncation because bits are whole units
Bits = int64_t(tempDouble);
Bytes = byteSize;
KibiBytes = byteSize / BytesInKibiByte;
MebiBytes = byteSize / BytesInMebiByte;
GibiBytes = byteSize / BytesInGibiByte;
TebiBytes = byteSize / BytesInTebiByte;
PebiBytes = byteSize / BytesInPebiByte;
// Decimal Units
KiloBytes = byteSize / BytesInKiloByte;
MegaBytes = byteSize / BytesInMegaByte;
GigaBytes = byteSize / BytesInGigaByte;
TeraBytes = byteSize / BytesInTeraByte;
PetaBytes = byteSize / BytesInPetaByte;
}
ostream &operator<<(ostream &output, const ByteSize &value)
{
output << value.ToString();
return output; // enables cout << a << b << c;
} // end function operator<<
#endif // !BYTESIZE_H