-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFail.Object.cpp
executable file
·81 lines (70 loc) · 1.55 KB
/
Fail.Object.cpp
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
#include "Fail.Object.hpp"
bool Fail::object::operator == (const object& Other) const
{
unsigned int i = 0;
while(i < sizeof(*this))
{
if(reinterpret_cast<unsigned char*>(const_cast<object*>(this))[i] != reinterpret_cast<unsigned char*>(const_cast<object*>(&Other))[i])
{
return false;
}
}
return true;
}
bool Fail::object::operator != (const object& Other) const
{
return !this->operator==(Other);
}
Fail::object& Fail::object::operator = (const object& Other)
{
if(sizeof(*this) != sizeof(Other))
{
throw Fail::exception("Attempt to copy an object to an object of an incompatible type.", __FUNCTION__);
}
unsigned int i = 0;
if(sizeof(*this) % 4 != 0)
{
// Use bytes so that only the object is copied
while(i < sizeof(*this))
{
reinterpret_cast<unsigned char*>(this)[i] = reinterpret_cast<unsigned char*>(const_cast<object*>(&Other))[i];
i++;
}
}
else
{
// Use 4-byte integers if possible for faster copy speed
while(i < sizeof(*this) / 4)
{
reinterpret_cast<unsigned int*>(this)[i] = reinterpret_cast<unsigned int*>(const_cast<object*>(&Other))[i];
i++;
}
}
return *this;
}
unsigned int Fail::object::Type() const
{
return typeid(*this).hash_code();
}
const char* Fail::object::TypeName() const
{
return typeid(*this).name();
}
void Fail::object::Zero ()
{
memset(this, 0, sizeof(*this));
return;
}
bool Fail::object::IsNullOrEmpty () const
{
unsigned int i = 0;
while(i < sizeof(*this))
{
if(*reinterpret_cast<unsigned char*>(const_cast<object*>(this)) != 0)
{
return false;
}
i++;
}
return true;
}