~karsten.klagges/openwns-allinone/trunk

« back to all changes in this revision

Viewing changes to framework/library/src/SmartPtr.hpp

  • Committer: Karsten Klagges
  • Date: 2014-08-06 13:03:56 UTC
  • Revision ID: kks@comnets.rwth-aachen.de-20140806130356-aiav38l8m4mm7wup
fixed indentation and precompiled header issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 *
26
26
 ******************************************************************************/
27
27
 
28
 
#ifndef WNS_SMARTPTR_HPP
29
 
#define WNS_SMARTPTR_HPP
30
 
 
31
 
#include "SmartPtrBase.hpp"
32
 
#include "RefCountable.hpp"
33
 
#include "TypeInfo.hpp"
 
28
#pragma once
 
29
#include <openwns/SmartPtrBase.hpp>
 
30
#include <openwns/RefCountable.hpp>
 
31
#include <openwns/TypeInfo.hpp>
34
32
 
35
33
#include <cassert>
36
34
#include <cstdlib>
46
44
 * @ingroup group_main_classes
47
45
 *
48
46
 * SmartPtr is a template that supports automatic memory
49
 
 * management. Once a SmartPtr is allocated you don't need to care about
50
 
 * deallocation.
 
47
 * management. Once a SmartPtr is allocated you don't need to care
 
48
 * about deallocation.
51
49
 */
52
50
template <typename T>
53
51
class SmartPtr
69
67
#ifdef WNS_SMARTPTR_DEBUGGING
70
68
        SmartPtrBase(),
71
69
        id(++getCounter()),
72
 
        // file(""),
73
 
        // line(0),
74
70
#endif
75
71
        ptr(NULL)
76
72
    {
92
88
        if (ptr)
93
89
        {
94
90
            ptr->incRefCount();
95
 
// #ifdef WNS_SMART_PTR_DEBUGGING
96
 
//             this->created("", 0);
97
 
// #endif
98
91
        }
99
92
    }
100
93
 
106
99
#ifdef WNS_SMARTPTR_DEBUGGING
107
100
        SmartPtrBase(),
108
101
        id(++getCounter()),
109
 
        // file(""),
110
 
        // line(0),
111
102
#endif
112
103
        ptr(s.ptr)
113
104
    {
114
105
        if(ptr) {
115
106
            ptr->incRefCount();
116
107
        }
117
 
// #ifdef WNS_SMARTPTR_DEBUGGING
118
 
//         this->created("", 0);
119
 
// #endif
120
108
    }
121
109
 
122
110
 
128
116
#ifdef WNS_SMARTPTR_DEBUGGING
129
117
        SmartPtrBase(),
130
118
        id(++getCounter()),
131
 
        // file(""),
132
 
        // line(0),
133
119
#endif
134
120
        ptr(s.getPtr())
135
121
    {
136
122
        if(ptr) {
137
123
            ptr->incRefCount();
138
124
        }
139
 
// #ifdef WNS_SMARTPTR_DEBUGGING
140
 
//         this->created("", 0);
141
 
// #endif
142
125
    }
143
126
 
144
 
// #ifdef WNS_SMARTPTR_DEBUGGING
145
 
//     /**
146
 
//      * @brief Construct NULL pointer (additional debugging support)
147
 
//      */
148
 
//     SmartPtr(const std::string& file, int line) :
149
 
//         SmartPtrBase(),
150
 
//         id(++getCounter()),
151
 
//         file(""),
152
 
//         line(0),
153
 
//         ptr(NULL)
154
 
//     {
155
 
//         this->created(file, line);
156
 
//     }
157
 
 
158
 
//     /**
159
 
//      * @brief Pointer p will be stored in / handled by SmartPtr
160
 
//      * (additional debugging support)
161
 
//      */
162
 
//     explicit
163
 
//     SmartPtr(const std::string& file, int line, T* p) :
164
 
//         SmartPtrBase(),
165
 
//         id(++getCounter()),
166
 
//         file(""),
167
 
//         line(0),
168
 
//         ptr(p)
169
 
//     {
170
 
//         assert(ptr);
171
 
//         ptr->incRefCount();
172
 
//         this->created(file, line);
173
 
//     }
174
 
 
175
 
//     /**
176
 
//      * @brief "Copy-constructor" from same SmartPtr type (additional
177
 
//      * debugging support)
178
 
//      */
179
 
//     SmartPtr(const std::string& file, int line, const SmartPtr& s) :
180
 
//         SmartPtrBase(),
181
 
//         id(++getCounter()),
182
 
//         file(""),
183
 
//         line(0),
184
 
//         ptr(s.ptr)
185
 
//     {
186
 
//         if(ptr) {
187
 
//             ptr->incRefCount();
188
 
//         }
189
 
//         this->created(file, line);
190
 
//     }
191
 
 
192
 
//     /**
193
 
//      * @brief Copy-constructor from other SmartPtr type (additional
194
 
//      * debugging support)
195
 
//      */
196
 
//     template <typename OtherType>
197
 
//     SmartPtr(const std::string& file,  int line, const SmartPtr<OtherType>& s) :
198
 
//         SmartPtrBase(),
199
 
//         id(++getCounter()),
200
 
//         file(""),
201
 
//         line(0),
202
 
//         ptr(s.getPtr())
203
 
//     {
204
 
//         if(ptr) {
205
 
//             ptr->incRefCount();
206
 
//         }
207
 
//         this->created(file, line);
208
 
//     }
209
 
// #endif // defined WNS_SMARTPTR_DEBUGGING
210
 
 
211
127
    /**
212
128
     * @brief Assign operator for same SmartPtr type
213
129
     */
262
178
     */
263
179
    ~SmartPtr()
264
180
    {
265
 
// #ifdef WNS_SMARTPTR_DEBUGGING
266
 
//         this->deleted();
267
 
// #endif
268
181
        if(ptr) {
269
182
            ptr->decRefCount();
270
183
        }
372
285
    static void
373
286
    printAllExistingPointers()
374
287
    {
375
 
// #ifdef WNS_SMARTPTR_DEBUGGING
376
 
//         std::cout << "Curently existing SmartPtr<"
377
 
//                   << wns::TypeInfo::create<T>()
378
 
//                   <<  ">: " << "\n";
379
 
 
380
 
//         for(typename std::list<SmartPtr*>::const_iterator itr = getAllPointers().begin();
381
 
//             itr != getAllPointers().end();
382
 
//             ++itr) {
383
 
//             std::cout << "Pointer id: " << (*itr)->id << "\n"
384
 
//                       << "Created at: " << (*itr)->file << ":" << (*itr)->line << "\n";
385
 
 
386
 
//         }
387
 
// #endif
388
288
    }
389
289
 
390
290
    /**
393
293
    static void
394
294
    printNumberOfExistingPointers()
395
295
    {
396
 
// #ifdef WNS_SMARTPTR_DEBUGGING
397
 
//         std::cout << "Number of curently existing SmartPtr<"
398
 
//                   << wns::TypeInfo::create<T>()
399
 
//                   <<  ">: " << getAllPointers().size() << "\n";
400
 
// #endif
401
296
    }
402
297
 
403
298
 
405
300
#ifdef WNS_SMARTPTR_DEBUGGING
406
301
    boost::int64_t id;
407
302
 
408
 
//     std::string file;
409
 
//     int line;
410
 
 
411
 
//     void
412
 
//     created(const std::string& _file, int _line)
413
 
//     {
414
 
//         this->getAllPointers().push_back(this);
415
 
//         this->file = _file;
416
 
//         this->line = _line;
417
 
//     }
418
 
 
419
 
//     void
420
 
//     deleted()
421
 
//     {
422
 
//         SmartPtr::getAllPointers().remove(this);
423
 
//     }
424
 
 
425
303
    static boost::int64_t&
426
304
    getCounter()
427
305
    {
429
307
        return counter;
430
308
    }
431
309
 
432
 
//     static std::list<SmartPtr*>&
433
 
//     getAllPointers()
434
 
//     {
435
 
//         static std::list<SmartPtr*> allPointers;
436
 
//         return allPointers;
437
 
//     }
438
310
    wns::TypeInfo
439
311
    getTypeInfo() const
440
312
    {
446
318
    {
447
319
        return id;
448
320
    }
449
 
#endif // defined WNS_SMARTPTR_DEBUGGING
 
321
#endif
450
322
 
451
323
    /**
452
324
     * @brief Less than
571
443
}
572
444
//@}
573
445
 
574
 
} // wns
575
 
 
576
 
#endif // NOT defined WNS_SMARTPTR_HPP
577
 
 
578
 
 
 
446
}