blob: 1eb5efedbed58129b599aee482fd0e962442b88f (
plain)
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
|
#pragma once
#include "../../std/algorithm.hpp"
struct json_struct_t;
namespace my
{
class JsonHandle
{
void IncRef();
void DecRef();
public:
JsonHandle(json_struct_t * pJson = 0) : m_pJson(pJson)
{
IncRef();
}
JsonHandle(JsonHandle const & json) : m_pJson(json.m_pJson)
{
IncRef();
}
~JsonHandle()
{
DecRef();
}
JsonHandle & operator = (JsonHandle const & json)
{
JsonHandle tmp(json);
tmp.swap(*this);
return *this;
}
void swap(JsonHandle & json)
{
::swap(m_pJson, json.m_pJson);
}
json_struct_t * get() const
{
return m_pJson;
}
json_struct_t * operator -> () const
{
return m_pJson;
}
operator bool () const
{
return m_pJson != 0;
}
/// Attach newly created object without incrementing ref count (it's already == 1).
void AttachNew(json_struct_t * pJson)
{
DecRef();
m_pJson = pJson;
}
private:
json_struct_t * m_pJson;
};
}
|