]> git.saurik.com Git - cycript.git/blob - Pooling.hpp
Changed the syntax error arrow to start at the beginning of the line to setup for...
[cycript.git] / Pooling.hpp
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 _aprcall(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 struct CYData {
48 apr_pool_t *pool_;
49
50 virtual ~CYData() {
51 }
52
53 static void *operator new(size_t size, apr_pool_t *pool) {
54 void *data(apr_palloc(pool, size));
55 reinterpret_cast<CYData *>(data)->pool_ = pool;
56 return data;
57 }
58
59 static void *operator new(size_t size) {
60 apr_pool_t *pool;
61 _aprcall(apr_pool_create(&pool, NULL));
62 return operator new(size, pool);
63 }
64
65 static void operator delete(void *data) {
66 apr_pool_destroy(reinterpret_cast<CYData *>(data)->pool_);
67 }
68
69 };
70
71 #endif/*CYPOOLING_HPP*/