CTypeWrapper.h
Go to the documentation of this file.00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WSPR_UTILITY_C_TYPE_WRAPPER_H 00023 #define __SSRC_WSPR_UTILITY_C_TYPE_WRAPPER_H 00024 00025 #include <ssrc/wispers-packages.h> 00026 00027 #include <boost/shared_ptr.hpp> 00028 00029 __BEGIN_NS_SSRC_WSPR_UTILITY 00030 00031 template<typename target_type, typename error_type, 00032 typename init_type, typename delete_type, 00033 template <typename t> class smart_ptr_type = boost::shared_ptr> 00034 class CTypeWrapper : protected smart_ptr_type<target_type> { 00035 typedef smart_ptr_type<target_type> super; 00036 00037 target_type *_target; 00038 error_type _err; 00039 00040 public: 00041 00042 CTypeWrapper() : super(), _target(0) { 00043 init_type initialize; 00044 delete_type deleter; 00045 00046 _err = initialize(&_target); 00047 if(_target) 00048 reset(_target, deleter); 00049 } 00050 00051 template<typename init_parameter> 00052 explicit CTypeWrapper(const init_parameter & value) : super(), _target(0) { 00053 init_type initialize; 00054 delete_type deleter; 00055 00056 _err = initialize(&_target, value); 00057 if(_target) 00058 reset(_target, deleter); 00059 } 00060 00061 template<typename init_parameter, typename custom_initializer> 00062 CTypeWrapper(const init_parameter & value, 00063 const custom_initializer & initialize) : 00064 super(), _target(0) 00065 { 00066 delete_type deleter; 00067 00068 _err = initialize(&_target, value); 00069 if(_target) 00070 reset(_target, deleter); 00071 } 00072 00073 template<typename init_parameter, 00074 typename custom_initializer, 00075 typename custom_deleter> 00076 explicit CTypeWrapper(const init_parameter & value, 00077 const custom_initializer & initialize, 00078 const custom_deleter & deleter) : 00079 super(), _target(0) 00080 { 00081 _err = initialize(&_target, value); 00082 if(_target) 00083 reset(_target, deleter); 00084 } 00085 00086 using super::operator typename super::unspecified_bool_type; 00087 using super::operator!; 00088 using super::operator*; 00089 using super::operator->; 00090 using super::get; 00091 00092 error_type init_error() { 00093 return _err; 00094 } 00095 }; 00096 00097 __END_NS_SSRC_WSPR_UTILITY 00098 00099 #endif
Copyright © 2006-2010 Savarese Software Research Corporation. All rights reserved.
Copyright © 2011 Savarese Software Research Corporation. All rights reserved