]> git.saurik.com Git - cycript.git/blame - Pooling.hpp
Slightly reorganized code, fixed @class to work with NoBF principal, integrated the...
[cycript.git] / Pooling.hpp
CommitLineData
5999c315
JF
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
17class CYPool {
18 private:
19 apr_pool_t *pool_;
20
21 public:
22 CYPool() {
1ef7d061 23 _aprcall(apr_pool_create(&pool_, NULL));
5999c315
JF
24 }
25
26 ~CYPool() {
27 apr_pool_destroy(pool_);
28 }
29
b1ff2d78
JF
30 void Clear() {
31 apr_pool_clear(pool_);
32 }
33
5999c315
JF
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
1ef7d061
JF
47struct 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
5999c315 71#endif/*CYPOOLING_HPP*/