1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 ============================================================================
18 $Id: basic_counted_ptr.h,v 1.1 2008/08/25 16:20:01 langmead Exp $
19 ==========================================================================*/
21 // THIS FILE IS CURRENTLY NOT USED IN SEQAN
23 #ifndef SEQAN_HEADER_BASIC_COUNTED_PTR_H
24 #define SEQAN_HEADER_BASIC_COUNTED_PTR_H
26 namespace SEQAN_NAMESPACE_MAIN
29 //////////////////////////////////////////////////////////////////////////////
32 template < typename Type >
35 typedef CountedPtr _Self;
36 typedef CountedPtr* _SelfPtr;
37 typedef CountedPtr& _SelfRef;
39 typedef Type& reference;
40 typedef const Type& const_reference;
41 typedef Type* pointer;
43 explicit CountedPtr(pointer p = 0): // allocate a new counter
46 if (p) itsCounter = new counter(p);
49 CountedPtr(const _Self& r) throw() {
50 acquire(r.itsCounter);
57 CountedPtr& operator=(const _Self& r)
61 acquire(r.itsCounter);
66 reference operator*() const throw() {
67 return *itsCounter->ptr;
70 pointer operator->() const throw() {
71 return itsCounter->ptr;
74 pointer get() const throw() {
75 return itsCounter ? itsCounter->ptr : 0;
78 bool unique() const throw() {
79 return (itsCounter ? itsCounter->count == 1 : true);
82 inline operator pointer () const {
91 counter(pointer p = 0, unsigned c = 1):
96 void acquire(counter* c) throw()
97 { // increment the count
103 { // decrement the count, delete if it is 0
105 if (--itsCounter->count == 0) {
106 delete itsCounter->ptr;