LCOV - code coverage report
Current view: top level - simgear/props - SGReferenced.hxx (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 3 3 100.0 %
Date: 2010-08-24 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 92 8.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*-c++-*-
       2                 :            :  *
       3                 :            :  * Copyright (C) 2005-2006 Mathias Froehlich 
       4                 :            :  *
       5                 :            :  * This program is free software; you can redistribute it and/or
       6                 :            :  * modify it under the terms of the GNU Lesser General Public License as
       7                 :            :  * published by the Free Software Foundation; either version 2 of the
       8                 :            :  * License, or (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This program is distributed in the hope that it will be useful, but
      11                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :            :  * Lesser General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU Lesser General Public License
      16                 :            :  * along with this program; if not, write to the Free Software
      17                 :            :  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      18                 :            :  *
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef SGReferenced_HXX
      22                 :            : #define SGReferenced_HXX
      23                 :            : 
      24                 :            : /// Base class for all reference counted SimGear objects
      25                 :            : /// Classes derived from this one are meant to be managed with
      26                 :            : /// the SGSharedPtr class.
      27                 :            : /// For more info see @SGSharedPtr.
      28                 :            : 
      29                 :            : class SGReferenced {
      30                 :            : public:
      31                 :        702 :   SGReferenced(void) : _refcount(0u)
      32                 :            :   {}
      33                 :            :   /// Do not copy reference counts. Each new object has it's own counter
      34                 :            :   SGReferenced(const SGReferenced&) : _refcount(0u)
      35                 :            :   {}
      36                 :            :   /// Do not copy reference counts. Each object has it's own counter
      37                 :            :   SGReferenced& operator=(const SGReferenced&)
      38                 :            :   { return *this; }
      39                 :            : 
      40                 :            :   static unsigned get(const SGReferenced* ref)
      41 [ +  - ][ #  # ]:      89600 :   { if (ref) return ++(ref->_refcount); else return ~0u; }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ #  # ][ #  # ]
         [ +  - ][ +  - ]
         [ #  # ][ +  - ]
         [ -  + ][ #  # ]
      42                 :            :   static unsigned put(const SGReferenced* ref)
      43 [ +  - ][ -  + ]:      88297 :   { if (ref) return --(ref->_refcount); else return ~0u; }
      44                 :            :   static unsigned count(const SGReferenced* ref)
      45                 :            :   { if (ref) return ref->_refcount; else return ~0u; }
      46                 :            :   static bool shared(const SGReferenced* ref)
      47                 :            :   { if (ref) return 1u < ref->_refcount; else return false; }
      48                 :            : 
      49                 :            : private:
      50                 :            :   mutable unsigned _refcount;
      51                 :            : };
      52                 :            : 
      53                 :            : #endif

Generated by: LCOV version 1.9