Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/utility - CTypeWrapper.h (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 14 14 100.0 %
Date: 2012-04-09 Functions: 7 7 100.0 %
Branches: 6 12 50.0 %

           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                 :            :  *     https://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                 :       1097 : 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                 :            :       this->reset(_target, deleter);
      49                 :            :     }
      50                 :            :   }
      51                 :            : 
      52                 :            :   template<typename init_parameter>
      53                 :         23 :   explicit CTypeWrapper(const init_parameter & value) : super(), _target(0) {
      54                 :            :     init_type initialize;
      55                 :            :     delete_type deleter;
      56                 :            : 
      57         [ +  - ]:         23 :     _err = initialize(&_target, value);
      58         [ +  - ]:         23 :     if(_target) {
      59         [ +  - ]:         23 :       this->reset(_target, deleter);
      60                 :            :     }
      61                 :         23 :   }
      62                 :            : 
      63                 :            :   template<typename init_parameter, typename custom_initializer>
      64                 :        868 :   CTypeWrapper(const init_parameter & value,
      65                 :            :                const custom_initializer & initialize) :
      66                 :        868 :     super(), _target(0)
      67                 :            :   {
      68                 :            :     delete_type deleter;
      69                 :            : 
      70         [ +  - ]:        868 :     _err = initialize(&_target, value);
      71         [ +  - ]:        868 :     if(_target) {
      72         [ +  - ]:        868 :       this->reset(_target, deleter);
      73                 :            :     }
      74                 :        868 :   }
      75                 :            : 
      76                 :            :   template<typename init_parameter,
      77                 :            :            typename custom_initializer,
      78                 :            :            typename custom_deleter>
      79                 :            :   explicit CTypeWrapper(const init_parameter & value,
      80                 :            :                         const custom_initializer & initialize,
      81                 :            :                         const custom_deleter & deleter) :
      82                 :            :     super(), _target(0)
      83                 :            :   {
      84                 :            :     _err = initialize(&_target, value);
      85                 :            :     if(_target) {
      86                 :            :       this->reset(_target, deleter);
      87                 :            :     }
      88                 :            :   }
      89                 :            : 
      90                 :            :   using super::operator typename super::unspecified_bool_type;
      91                 :            :   using super::operator!;
      92                 :            :   using super::operator*;
      93                 :            :   using super::operator->;
      94                 :            :   using super::get;
      95                 :            : 
      96                 :        891 :   error_type init_error() {
      97                 :        891 :     return _err;
      98                 :            :   }
      99                 :            : };
     100                 :            : 
     101                 :            : __END_NS_SSRC_WSPR_UTILITY
     102                 :            : 
     103                 :            : #endif