Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the CTypeWrapper class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WSPR_UTILITY_C_TYPE_WRAPPER_H
23 : : #define __SSRC_WSPR_UTILITY_C_TYPE_WRAPPER_H
24 : :
25 : : #include <ssrc/wispers-packages.h>
26 : :
27 : : #include <boost/shared_ptr.hpp>
28 : :
29 : : __BEGIN_NS_SSRC_WSPR_UTILITY
30 : :
31 : : template<typename target_type, typename error_type,
32 : : typename init_type, typename delete_type,
33 : : template <typename t> class smart_ptr_type = boost::shared_ptr>
34 : 1101 : class CTypeWrapper : protected smart_ptr_type<target_type> {
35 : : typedef smart_ptr_type<target_type> super;
36 : :
37 : : target_type *_target;
38 : : error_type _err;
39 : :
40 : : public:
41 : :
42 : : CTypeWrapper() : super(), _target(0) {
43 : : init_type initialize;
44 : : delete_type deleter;
45 : :
46 : : _err = initialize(&_target);
47 : : if(_target)
48 : : reset(_target, deleter);
49 : : }
50 : :
51 : : template<typename init_parameter>
52 : 24 : explicit CTypeWrapper(const init_parameter & value) : super(), _target(0) {
53 : : init_type initialize;
54 : : delete_type deleter;
55 : :
56 [ + - ]: 24 : _err = initialize(&_target, value);
57 [ + - ]: 24 : if(_target)
58 [ + - ]: 24 : reset(_target, deleter);
59 : 24 : }
60 : :
61 : : template<typename init_parameter, typename custom_initializer>
62 : 871 : CTypeWrapper(const init_parameter & value,
63 : : const custom_initializer & initialize) :
64 : 871 : super(), _target(0)
65 : : {
66 : : delete_type deleter;
67 : :
68 [ + - ]: 871 : _err = initialize(&_target, value);
69 [ + - ]: 871 : if(_target)
70 [ + - ]: 871 : reset(_target, deleter);
71 : 871 : }
72 : :
73 : : template<typename init_parameter,
74 : : typename custom_initializer,
75 : : typename custom_deleter>
76 : : explicit CTypeWrapper(const init_parameter & value,
77 : : const custom_initializer & initialize,
78 : : const custom_deleter & deleter) :
79 : : super(), _target(0)
80 : : {
81 : : _err = initialize(&_target, value);
82 : : if(_target)
83 : : reset(_target, deleter);
84 : : }
85 : :
86 : : using super::operator typename super::unspecified_bool_type;
87 : : using super::operator!;
88 : : using super::operator*;
89 : : using super::operator->;
90 : : using super::get;
91 : :
92 : 895 : error_type init_error() {
93 : 895 : return _err;
94 : : }
95 : : };
96 : :
97 : : __END_NS_SSRC_WSPR_UTILITY
98 : :
99 : : #endif
|