]>
Commit | Line | Data |
---|---|---|
1 | #ifndef CYPOOLING_HPP | |
2 | #define CYPOOLING_HPP | |
3 | ||
4 | #include <apr-1/apr_pools.h> | |
5 | #include <apr-1/apr_strings.h> | |
6 | ||
7 | #include <minimal/stdlib.h> | |
8 | ||
9 | _finline void *operator new(size_t size, apr_pool_t *pool) { | |
10 | return apr_palloc(pool, size); | |
11 | } | |
12 | ||
13 | _finline void *operator new [](size_t size, apr_pool_t *pool) { | |
14 | return apr_palloc(pool, size); | |
15 | } | |
16 | ||
17 | class CYPool { | |
18 | private: | |
19 | apr_pool_t *pool_; | |
20 | ||
21 | public: | |
22 | CYPool() { | |
23 | apr_pool_create(&pool_, NULL); | |
24 | } | |
25 | ||
26 | ~CYPool() { | |
27 | apr_pool_destroy(pool_); | |
28 | } | |
29 | ||
30 | void Clear() { | |
31 | apr_pool_clear(pool_); | |
32 | } | |
33 | ||
34 | operator apr_pool_t *() const { | |
35 | return pool_; | |
36 | } | |
37 | ||
38 | char *operator ()(const char *data) const { | |
39 | return apr_pstrdup(pool_, data); | |
40 | } | |
41 | ||
42 | char *operator ()(const char *data, size_t size) const { | |
43 | return apr_pstrndup(pool_, data, size); | |
44 | } | |
45 | }; | |
46 | ||
47 | #endif/*CYPOOLING_HPP*/ |