-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.hpp
79 lines (61 loc) · 1.27 KB
/
exceptions.hpp
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
#pragma once
#include <exception>
#include <cwchar>
#include <memory>
#include "ayto/common/typedefs.hpp"
#define NS_BEGIN namespace ayto { namespace v10 { namespace exceptions {
#define NS_END } } }
NS_BEGIN
using namespace ayto::typedefs;
class exception_base
{
protected:
std::unique_ptr<byte[]> data;
protected:
exception_base() = default;
public:
template <typename DataT>
exception_base(const DataT* const in_data, long long data_size)
:
data(std::make_unique<byte[]>(data_size))
{
std::memcpy(data.get(), in_data, data_size);
}
template <typename CharT, std::size_t N>
exception_base(const CharT(& in_data)[N])
:
data(std::make_unique<byte[]>(N))
{
auto size = N;
std::memcpy(data.get(), &in_data, N);
}
public:
template <typename DataType = const char *>
DataType what() const
{
return reinterpret_cast<DataType>(data.get());
}
};
namespace file
{
class not_found : public exception_base
{
public:
template <typename DataT>
not_found(const DataT* const in_data, long long data_size)
:
exception_base(in_data, data_size)
{}
template <typename CharT, std::size_t N>
not_found(const CharT(&in_data)[N])
:
exception_base(in_data)
{}
};
}
class setup_error : public exception_base
{
};
NS_END
#undef NS_BEGIN
#undef NS_END