LibreOffice LibreOffice 4.3 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
refobj.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #ifndef INCLUDED_SALHELPER_REFOBJ_HXX
21 #define INCLUDED_SALHELPER_REFOBJ_HXX
22
23 #include <sal/types.h>
24 #include <rtl/alloc.h>
25 #include <rtl/ref.hxx>
26 #include <osl/diagnose.h>
27 #include <osl/interlck.h>
28
29 namespace salhelper
30 {
31
32
33
34 class ReferenceObject : public rtl::IReference
35 {
38 oslInterlockedCount m_nReferenceCount;
39
42 ReferenceObject (const ReferenceObject&);
43 ReferenceObject& operator= (const ReferenceObject&);
44
45 public:
48 static void* operator new (size_t n) SAL_THROW(())
49 {
50 return ::rtl_allocateMemory (n);
51 }
52 static void operator delete (void* p) SAL_THROW(())
53 {
54 ::rtl_freeMemory (p);
55 }
56 static void* operator new (size_t, void* p) SAL_THROW(())
57 {
58 return (p);
59 }
60 static void operator delete (void*, void*) SAL_THROW(())
61 {}
62
63 public:
66 inline ReferenceObject() SAL_THROW(()) : m_nReferenceCount (0)
67 {}
68
69
72 virtual oslInterlockedCount SAL_CALL acquire() SAL_THROW(()) SAL_OVERRIDE
73 {
74 return osl_atomic_increment (&m_nReferenceCount);
75 }
76
77 virtual oslInterlockedCount SAL_CALL release() SAL_THROW(()) SAL_OVERRIDE
78 {
79 oslInterlockedCount result;
80 result = ::osl_atomic_decrement (&m_nReferenceCount);
81 if (result == 0)
82 {
83 // Last reference released.
84 delete this;
85 }
86 return (result);
87 }
88
89 protected:
92 virtual ~ReferenceObject() SAL_THROW(())
93 {
94 OSL_ASSERT(m_nReferenceCount == 0);
95 }
96 };
97
98
99
100 } // namespace salhelper
101
102 #endif /* ! INCLUDED_SALHELPER_REFOBJ_HXX */
103
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition: interlck.h:32
alloc.h
types.h
ref.hxx
salhelper::ReferenceObject
Definition: refobj.hxx:34
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
salhelper::ReferenceObject::release
virtual oslInterlockedCount release() SAL_THROW(()) SAL_OVERRIDE
Definition: refobj.hxx:77
diagnose.h
salhelper::ReferenceObject::~ReferenceObject
virtual ~ReferenceObject() SAL_THROW(())
Destruction.
Definition: refobj.hxx:92
salhelper
Definition: condition.hxx:29
SAL_OVERRIDE
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:423
salhelper::ReferenceObject::ReferenceObject
ReferenceObject() SAL_THROW(())
Construction.
Definition: refobj.hxx:66
salhelper::ReferenceObject::acquire
virtual oslInterlockedCount acquire() SAL_THROW(()) SAL_OVERRIDE
IReference.
Definition: refobj.hxx:72
SAL_THROW
#define SAL_THROW(x)
Exception specification documentation.
Definition: types.h:361
rtl::IReference
Interface for a reference type.
Definition: ref.hxx:32
OSL_ASSERT
#define OSL_ASSERT(c)
Definition: diagnose.h:105
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
interlck.h