forked from SomeSupport/eMule
-
Notifications
You must be signed in to change notification settings - Fork 97
/
Debug_FileSize.h
134 lines (116 loc) · 8.29 KB
/
Debug_FileSize.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
//this file is part of eMule
//Copyright (C)2002-2005 Merkur ( [email protected] / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
enum E_DebugFSAtion{
DFSA_ADD = 0,
DFSA_SUB,
DFSA_MUL,
DFSA_DIV
};
class CEMFileSize {
public:
CEMFileSize() {m_nSize = (uint64)(-1);}
CEMFileSize(uint64 nSize) {m_nSize = nSize; Check();}
__declspec(deprecated) CEMFileSize(uint32 nSize) {m_nSize = nSize; Check();}
CEMFileSize& operator=(const CEMFileSize& k1) {m_nSize = k1.m_nSize; Check(); return *this; }
CEMFileSize& operator=(uint64 k1) {m_nSize = k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator=(sint64 k1) {m_nSize = k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator=(uint32 k1) {m_nSize = k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator=(sint32 k1) {m_nSize = k1; Check(); return *this; }
CEMFileSize& operator-=(const CEMFileSize& k1) {Check(); m_nSize -= k1.m_nSize; Check(); return *this; }
CEMFileSize& operator-=(uint64 k1) {Check(); m_nSize -= k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator-=(sint64 k1) {Check(); m_nSize -= k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator-=(uint32 k1) {Check(); m_nSize -= k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator-=(sint32 k1) {Check(); m_nSize -= k1; Check(); return *this; }
CEMFileSize& operator+=(const CEMFileSize& k1) {Check(); m_nSize += k1.m_nSize; Check(); return *this; }
CEMFileSize& operator+=(uint64 k1) {Check(); m_nSize += k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator+=(sint64 k1) {Check(); m_nSize += k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator+=(uint32 k1) {Check(); m_nSize += k1; Check(); return *this; }
__declspec(deprecated) CEMFileSize& operator+=(sint32 k1) {Check(); m_nSize += k1; Check(); return *this; }
operator uint64() const {return m_nSize;}
operator double() const {return (double)m_nSize;}
/*__declspec(deprecated)*/ operator float() const {return (float)m_nSize;}
/*__declspec(deprecated)*/ operator sint64() const {return (sint64)m_nSize;}
__declspec(deprecated) operator uint32() const {ASSERT( m_nSize < 0xFFFFFFFF ); return (uint32)m_nSize;}
__declspec(deprecated) operator sint32() const {ASSERT( m_nSize < 0x7FFFFFFF ); return (sint32)m_nSize;}
friend bool operator==(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize == k2.m_nSize;}
friend bool operator==(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize == k2;}
friend bool operator==(uint64 k1,const CEMFileSize& k2) {return k1 == k2.m_nSize;}
__declspec(deprecated) friend bool operator==(uint32 k1,const CEMFileSize& k2) {return k1 == k2.m_nSize;}
__declspec(deprecated) friend bool operator==(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize == k2;}
friend bool operator!=(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize != k2.m_nSize;}
friend bool operator!=(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize != k2;}
friend bool operator!=(uint64 k1,const CEMFileSize& k2) {return k1 != k2.m_nSize;}
__declspec(deprecated) friend bool operator!=(uint32 k1,const CEMFileSize& k2) {return k1 != k2.m_nSize;}
__declspec(deprecated) friend bool operator!=(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize != k2;}
friend bool operator>(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize > k2.m_nSize;}
friend bool operator>(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize > k2;}
friend bool operator>(uint64 k1,const CEMFileSize& k2) {return k1 > k2.m_nSize;}
__declspec(deprecated) friend bool operator>(uint32 k1,const CEMFileSize& k2) {return k1 > k2.m_nSize;}
__declspec(deprecated) friend bool operator>(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize > k2;}
friend bool operator<(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize < k2.m_nSize;}
friend bool operator<(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize < k2;}
friend bool operator<(uint64 k1,const CEMFileSize& k2) {return k1 < k2.m_nSize;}
__declspec(deprecated) friend bool operator<(uint32 k1,const CEMFileSize& k2) {return k1 < k2.m_nSize;}
__declspec(deprecated) friend bool operator<(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize < k2;}
friend bool operator>=(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize >= k2.m_nSize;}
friend bool operator>=(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize >= k2;}
friend bool operator>=(uint64 k1,const CEMFileSize& k2) {return k1 >= k2.m_nSize;}
__declspec(deprecated) friend bool operator>=(uint32 k1,const CEMFileSize& k2) {return k1 >= k2.m_nSize;}
__declspec(deprecated) friend bool operator>=(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize >= k2;}
friend bool operator<=(const CEMFileSize& k1,const CEMFileSize& k2) {return k1.m_nSize <= k2.m_nSize;}
friend bool operator<=(const CEMFileSize& k1,uint64 k2) {return k1.m_nSize <= k2;}
friend bool operator<=(uint64 k1,const CEMFileSize& k2) {return k1 <= k2.m_nSize;}
__declspec(deprecated) friend bool operator<=(uint32 k1,const CEMFileSize& k2) {return k1 <= k2.m_nSize;}
__declspec(deprecated) friend bool operator<=(const CEMFileSize& k1,uint32 k2) {return k1.m_nSize <= k2;}
friend CEMFileSize operator+(const CEMFileSize& k1,const CEMFileSize& k2) {return CEMFileSize(k1.m_nSize, k2.m_nSize, DFSA_ADD);}
friend CEMFileSize operator+(const CEMFileSize& k1,uint64 k2) {return CEMFileSize(k1.m_nSize, k2, DFSA_ADD);}
friend CEMFileSize operator+(uint64 k1,const CEMFileSize& k2) {return CEMFileSize(k1, k2.m_nSize, DFSA_ADD);}
friend CEMFileSize operator-(const CEMFileSize& k1,const CEMFileSize& k2) {return CEMFileSize(k1.m_nSize, k2.m_nSize, DFSA_SUB);}
friend CEMFileSize operator-(const CEMFileSize& k1,uint64 k2) {return CEMFileSize(k1.m_nSize, k2, DFSA_SUB);}
friend CEMFileSize operator-(uint64 k1,const CEMFileSize& k2) {return CEMFileSize(k1, k2.m_nSize, DFSA_SUB);}
__declspec(deprecated) friend CEMFileSize operator-(uint32 k1,const CEMFileSize& k2) {return CEMFileSize(k1, k2.m_nSize, DFSA_SUB);}
friend CEMFileSize operator*(const CEMFileSize& k1,const CEMFileSize& k2) {return CEMFileSize(k1.m_nSize, k2.m_nSize, DFSA_MUL);}
friend CEMFileSize operator*(const CEMFileSize& k1,uint64 k2) {return CEMFileSize(k1.m_nSize, k2, DFSA_MUL);}
friend CEMFileSize operator*(uint64 k1,const CEMFileSize& k2) {return CEMFileSize(k1, k2.m_nSize, DFSA_MUL);}
friend CEMFileSize operator/(const CEMFileSize& k1,const CEMFileSize& k2) {return CEMFileSize(k1.m_nSize, k2.m_nSize, DFSA_DIV);}
friend CEMFileSize operator/(const CEMFileSize& k1,uint64 k2) {return CEMFileSize(k1.m_nSize, k2, DFSA_DIV);}
friend CEMFileSize operator/(uint64 k1,const CEMFileSize& k2) {return CEMFileSize(k1, k2.m_nSize, DFSA_DIV);}
private:
CEMFileSize(uint64 nSize1, uint64 nSize2, E_DebugFSAtion edfsAction) {
if (edfsAction == DFSA_ADD){
m_nSize = nSize1 + nSize2;
ASSERT( m_nSize >= nSize1 && m_nSize >= nSize2 && m_nSize <= 0x4000000000 );
}
else if (edfsAction == DFSA_SUB){
m_nSize = nSize1 - nSize2;
ASSERT( m_nSize <= nSize1 && m_nSize <= 0x4000000000 );
}
else if (edfsAction == DFSA_DIV){
if ( nSize2 != 0 )
m_nSize = nSize1 / nSize2;
else
ASSERT( false );
}
else if (edfsAction == DFSA_MUL){
m_nSize = nSize1 * nSize2;
ASSERT( m_nSize >= nSize1 && m_nSize >= nSize2 && m_nSize <= 0x4000000000 );
}
}
void Check() { ASSERT( m_nSize != (uint64)(-1) && m_nSize <= 0x4000000000 ); }
uint64 m_nSize;
};