~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/zmm/ref.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    ref.h - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: ref.h 1294 2007-05-13 16:28:24Z lww $
 
28
*/
 
29
 
 
30
/// \file ref.h
 
31
 
 
32
#ifndef __ZMM_REF_H__
 
33
#define __ZMM_REF_H__
 
34
 
 
35
#include "nil.h"
 
36
 
 
37
namespace zmm
 
38
{
 
39
 
 
40
template <class T>
 
41
class Ref
 
42
{
 
43
public:
 
44
    Ref(const Ref& other)
 
45
    {
 
46
        _ptr = other._ptr;
 
47
        if(_ptr)
 
48
            _ptr->retain();
 
49
    }
 
50
    explicit Ref(T* ptr = NULL) : _ptr(ptr)
 
51
    {
 
52
        if(ptr)
 
53
            ptr->retain();
 
54
    }
 
55
    Ref(NIL_VAR)
 
56
    {
 
57
        _ptr = NULL;
 
58
    }
 
59
    ~Ref()
 
60
    {
 
61
        if(_ptr)
 
62
            _ptr->release();
 
63
    }
 
64
 
 
65
    Ref& operator=(const Ref& other)
 
66
    {
 
67
        if(_ptr)
 
68
            _ptr->release();
 
69
        _ptr = other._ptr;
 
70
        if(_ptr)
 
71
            _ptr->retain();
 
72
        return *this;
 
73
    }
 
74
    inline Ref& operator=(NIL_VAR)
 
75
    {
 
76
        if(_ptr)
 
77
            _ptr->release();
 
78
        _ptr = NULL;
 
79
        return *this;
 
80
    }
 
81
 
 
82
    inline T& operator*() const
 
83
    {
 
84
        return *_ptr;
 
85
    }
 
86
    inline T* operator->() const
 
87
    {
 
88
        return _ptr;
 
89
    }
 
90
    inline T* getPtr()
 
91
    {
 
92
        return _ptr;
 
93
    }
 
94
    inline int operator==(NIL_VAR)
 
95
    {
 
96
        return (_ptr == NULL);
 
97
    }
 
98
    inline int operator!=(NIL_VAR)
 
99
    {
 
100
        return (_ptr != NULL);
 
101
    }
 
102
    inline int operator==(const Ref& other)
 
103
    {
 
104
        return (_ptr == other._ptr);
 
105
    }
 
106
    inline int operator!=(const Ref& other)
 
107
    {
 
108
        return (_ptr != other._ptr);
 
109
    }
 
110
protected:
 
111
    T* _ptr;
 
112
};
 
113
 
 
114
} // namespace
 
115
 
 
116
#define RefCast(ref, klass) zmm::Ref<klass>((klass *)ref.getPtr())
 
117
 
 
118
#endif // __ZMM_REF_H__