-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathphp_swoole_cxx.h
91 lines (78 loc) · 1.22 KB
/
php_swoole_cxx.h
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
82
83
84
85
86
87
88
89
90
#pragma once
#include "php_swoole.h"
namespace zend
{
class string
{
public:
static char* dup(zval *v)
{
string str(v);
return sw_strndup(str.val(), str.len());
}
static char* edup(zval *v)
{
string str(v);
return estrndup(str.val(), str.len());
}
string()
{
str = nullptr;
}
string(zval *v)
{
str = zval_get_string(v);
}
string(zend_string *v)
{
str = zend_string_copy(v);
}
void operator =(zval* v)
{
if (str)
{
zend_string_release(str);
}
str = zval_get_string(v);
}
inline char* val()
{
return ZSTR_VAL(str);
}
inline size_t len()
{
return ZSTR_LEN(str);
}
~string()
{
if (str)
{
zend_string_release(str);
}
}
private:
zend_string *str;
};
class string_ptr
{
public:
string_ptr(zend_string *str) :
str(str)
{
}
string_ptr(string_ptr &&o)
{
str = o.str;
o.str = nullptr;
}
~string_ptr()
{
if (str)
{
zend_string_release(str);
}
}
private:
zend_string *str;
};
}