/
object.cpp
62 lines (51 loc) · 1.08 KB
/
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
#include "object_data.h"
#include <stdexcept>
#include <sstream>
object::object()
{
}
object::~object()
{
}
object::object(object::data* new_data)
: m_data(new_data)
{
}
object::object(const object& another)
: m_data(another.is_null() ? nullptr : another.m_data->clone())
{
}
object& object::operator = (const object& another)
{
m_data.reset(another.is_null() ? nullptr : another.m_data->clone());
return *this;
}
bool object::is_null() const
{
return !m_data;
}
object object::clone() const
{
return is_null() ? object() : object(m_data->clone());
}
const object::data* object::get_data() const
{
return m_data.get();
}
const char* object::data_class() const
{
return is_null() ? "null" : m_data->class_name();
}
void object::reset(object::data* new_data)
{
m_data.reset(new_data);
}
void object::assert_not_null(const char* file, int line) const
{
if (is_null())
{
std::stringstream output;
output << "Assert 'object is not null' failed at file: '" << file << "' line: " << line;
throw std::runtime_error(output.str());
}
}