~ubuntu-branches/debian/sid/qpdf/sid

« back to all changes in this revision

Viewing changes to include/qpdf/PointerHolder.hh

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2011-08-11 16:43:32 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110811164332-4nhf2v7kcd4t66r8
Tags: 2.3.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#ifndef __POINTERHOLDER_HH__
9
9
#define __POINTERHOLDER_HH__
10
10
 
11
 
#include <iostream>
12
 
 
13
11
// This class is basically boost::shared_pointer but predates that by
14
12
// several years.
15
13
 
45
43
    class Data
46
44
    {
47
45
      public:
48
 
        Data(T* pointer, bool tracing) :
 
46
        Data(T* pointer, bool array) :
49
47
            pointer(pointer),
50
 
            tracing(tracing),
 
48
            array(array),
51
49
            refcount(0)
52
50
            {
53
 
                static int next_id = 0;
54
 
                this->unique_id = ++next_id;
55
51
            }
56
52
        ~Data()
57
53
            {
58
 
                if (this->tracing)
 
54
                if (array)
59
55
                {
60
 
                    std::cerr << "PointerHolder deleting pointer "
61
 
                         << (void*)pointer
62
 
                         << std::endl;
 
56
                    delete [] this->pointer;
63
57
                }
64
 
                delete this->pointer;
65
 
                if (this->tracing)
 
58
                else
66
59
                {
67
 
                    std::cerr << "PointerHolder done deleting pointer "
68
 
                         << (void*)pointer
69
 
                         << std::endl;
 
60
                    delete this->pointer;
70
61
                }
71
62
            }
72
63
        T* pointer;
73
 
        bool tracing;
 
64
        bool array;
74
65
        int refcount;
75
 
        int unique_id;
76
66
      private:
77
67
        Data(Data const&);
78
68
        Data& operator=(Data const&);
79
69
    };
80
70
 
81
71
  public:
 
72
    // "tracing" is not used but is kept for interface backward compatbility
82
73
    PointerHolder(T* pointer = 0, bool tracing = false)
83
74
        {
84
 
            this->init(new Data(pointer, tracing));
 
75
            this->init(new Data(pointer, false));
 
76
        }
 
77
    // Special constructor indicating to free memory with delete []
 
78
    // instead of delete
 
79
    PointerHolder(bool, T* pointer)
 
80
        {
 
81
            this->init(new Data(pointer, true));
85
82
        }
86
83
    PointerHolder(PointerHolder const& rhs)
87
84
        {
148
145
            this->data = data;
149
146
            {
150
147
                ++this->data->refcount;
151
 
                if (this->data->tracing)
152
 
                {
153
 
                    std::cerr << "PointerHolder " << this->data->unique_id
154
 
                         << " refcount increased to " << this->data->refcount
155
 
                         << std::endl;
156
 
                }
157
148
            }
158
149
        }
159
150
    void copy(PointerHolder const& rhs)
168
159
                {
169
160
                    gone = true;
170
161
                }
171
 
                if (this->data->tracing)
172
 
                {
173
 
                    std::cerr << "PointerHolder " << this->data->unique_id
174
 
                         << " refcount decreased to "
175
 
                         << this->data->refcount
176
 
                         << std::endl;
177
 
                }
178
162
            }
179
163
            if (gone)
180
164
            {