LCOV - code coverage report
Current view: top level - src/Utility - my_auto_ptr.h (source / functions) Coverage Total Hit
Test: final_report.info Lines: 90.9 % 11 10
Test Date: 2025-07-10 08:24:38 Functions: 83.3 % 6 5

            Line data    Source code
       1              : // -*- C++ -*-
       2              : /***************************************************************************
       3              :  *
       4              :  * The IPPL Framework
       5              :  *
       6              :  *
       7              :  * Visit http://people.web.psi.ch/adelmann/ for more details
       8              :  *
       9              :  ***************************************************************************/
      10              : 
      11              : #ifndef MY_AUTO_PTR_H
      12              : #define MY_AUTO_PTR_H
      13              : 
      14              : //////////////////////////////////////////////////////////////////////
      15              : /*
      16              :   A simple compliant implementation of auto_ptr.
      17              :   This is from Greg Colvin's implementation posted to comp.std.c++.
      18              : 
      19              :   Instead of using mutable this casts away const in release.
      20              : 
      21              :   We have to do this because we can't build containers of these
      22              :   things otherwise.
      23              :   */
      24              : //////////////////////////////////////////////////////////////////////
      25              : 
      26              : template <class X>
      27              : class my_auto_ptr {
      28              :     X* px;
      29              : 
      30              : public:
      31              :     my_auto_ptr()
      32              :         : px(0) {}
      33          344 :     my_auto_ptr(X* p)
      34          344 :         : px(p) {}
      35          696 :     my_auto_ptr(const my_auto_ptr<X>& r)
      36          696 :         : px(r.release()) {}
      37              :     my_auto_ptr& operator=(const my_auto_ptr<X>& r) {
      38              :         if (&r != this) {
      39              :             delete px;
      40              :             px = r.release();
      41              :         }
      42              :         return *this;
      43              :     }
      44          696 :     ~my_auto_ptr() { delete px; }
      45              :     X& operator*() const { return *px; }
      46          588 :     X* operator->() const { return px; }
      47            0 :     X* get() const { return px; }
      48          696 :     X* release() const {
      49          696 :         X* p                          = px;
      50          696 :         ((my_auto_ptr<X>*)(this))->px = 0;
      51          696 :         return p;
      52              :     }
      53              : };
      54              : 
      55              : #endif  // MY_AUTO_PTR_H
        

Generated by: LCOV version 2.0-1