monotone

monotone Mtn Source Tree

Root/cleanup.hh

1#ifndef __CLEANUP_HH__
2#define __CLEANUP_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9// this is a little "auto-cleanup" container, used to ensure things
10// from librsync, sqlite, etc. are deallocated when we leave a scope.
11
12template <typename T, typename R>
13struct cleanup_ptr {
14 T ptr;
15 R (* cleanup)(T);
16 explicit cleanup_ptr(T p, R (*c)(T)) : ptr(p), cleanup(c) {}
17 ~cleanup_ptr()
18 {
19 if (cleanup && ptr)
20 cleanup(ptr);
21 }
22 T operator()()
23 {
24 return ptr;
25 }
26 T * paddr()
27 {
28 return &ptr;
29 }
30};
31
32#endif // __CLEANUP_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status