-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyException.h
More file actions
82 lines (67 loc) · 1.5 KB
/
myException.h
File metadata and controls
82 lines (67 loc) · 1.5 KB
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
#pragma once
#include <utility>
#include <array>
#include <initializer_list>
#include <exception>
using std::array;
using std::initializer_list;
using std::pair;
template <size_t count, typename t1, typename t2>
class myException : public std::exception
{
public:
myException() : resChar(nullptr) {};
myException(initializer_list<pair<t1, t2>> inList) : resChar(nullptr)
{
for (size_t a = 0; a < inList.size(); ++a)
{
arr[a].first = (inList.begin() + a)->first;
arr[a].second = (inList.begin() + a)->second;
}
}
virtual const char* what() const override
{
string res;
for (size_t a = 0; a < arr.size(); ++a)
{
res += string(arr[a].first) + " - " + std::to_string(arr[a].second) + "\n";
}
resChar = new char[res.size() + 1];
memcpy_s(resChar, res.size() + 1, res.c_str(), res.size());
resChar[res.size()] = '\0';
return resChar;
}
bool setPair(size_t index, const pair<t1, t2> &p)
{
if (index >= arr.size())
return false;
arr[index].first = p.first;
arr[index].second = p.second;
return true;
}
bool setPair(size_t index, const t1 &val1, const t2 &val2)
{
if (index >= arr.size())
return false;
arr[index].first = val1;
arr[index].second = val2;
return true;
}
const pair<t1, t2> * getPtrPair(size_t index) const
{
if (index >= arr.size())
return nullptr;
return &arr[index];
}
const size_t getSize() const
{
return arr.size();
}
~myException()
{
delete[] resChar;
}
private:
array<pair<t1, t2>, count> arr;
mutable char * resChar;
};