-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddrVal.cpp
56 lines (49 loc) · 1.05 KB
/
addrVal.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
#include <string>
#include <cstring>
#include <iomanip>
#include <sstream>
#include "addrVal.hpp"
addrVal::addrVal(void *newVal, void *newBaseVal, std::string newName, bool newNeedToFree) : absVal<void*>(newVal, newName)
{
baseVal = newBaseVal;
needToFree = newNeedToFree;
}
addrVal::~addrVal()
{
if (needToFree)
{
delete[] static_cast<char*>(getVal());
}
}
bool addrVal::equalsSameType(spAbsVal<void*> cmpVal)
{
addrVal *ptrCmpVal = dynamic_cast<addrVal*>(cmpVal.get());
if (ptrCmpVal != nullptr)
{
return ((getVal() == nullptr && ptrCmpVal->getVal() == nullptr) ||
((char*)getVal() - (char*)baseVal) == ((char*)ptrCmpVal->getVal() - (char*)ptrCmpVal->baseVal));
}
else
{
return false;
}
}
void addrVal::setVal(void *newVal)
{
if (needToFree && getVal() != nullptr && getVal() != newVal)
{
delete[] static_cast<char*>(getVal());
}
absVal::setVal(newVal);
}
std::string addrVal::valToString()
{
if (getVal() == nullptr)
{
return "addrdif : NULL";
}
else
{
return "addrdif : " + std::to_string((char*)getVal() - (char*)baseVal);
}
}