LibreOffice
LibreOffice 26.2 SDK C/C++ API Reference
Toggle main menu visibility
Loading...
Searching...
No Matches
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
/*
21
* This file is part of LibreOffice published API.
22
*/
23
24
#ifndef INCLUDED_SALHELPER_REFOBJ_HXX
25
#define INCLUDED_SALHELPER_REFOBJ_HXX
26
27
#include <cassert>
28
29
#include "
sal/types.h
"
30
#include "
rtl/alloc.h
"
31
#include "
osl/interlck.h
"
32
33
namespace
salhelper
34
{
35
40
class
ReferenceObject
41
{
44
oslInterlockedCount
m_nReferenceCount;
45
46
ReferenceObject
(
const
ReferenceObject&)
SAL_DELETED_FUNCTION
;
47
ReferenceObject& operator= (
const
ReferenceObject&)
SAL_DELETED_FUNCTION
;
48
49
public
:
52
static
void
*
operator
new
(
size_t
n)
53
{
54
return ::rtl_allocateMemory (n);
55
}
56
static
void
operator
delete
(
void
* p)
57
{
58
::rtl_freeMemory
(p);
59
}
60
static
void
*
operator
new
(size_t,
void
* p)
61
{
62
return
p;
63
}
64
static
void
operator
delete
(
void
*,
void
*)
65
{}
66
67
public
:
70
ReferenceObject
() : m_nReferenceCount(0)
71
{}
72
73
74
void
SAL_CALL
acquire
()
75
{
76
osl_atomic_increment(&m_nReferenceCount);
77
}
78
79
void
SAL_CALL
release
()
80
{
81
if
(osl_atomic_decrement(&m_nReferenceCount) == 0)
82
{
83
// Last reference released.
84
delete
this
;
85
}
86
}
87
88
protected
:
91
virtual
~ReferenceObject
()
92
{
93
assert(m_nReferenceCount == 0);
94
}
95
};
96
97
98
}
// namespace salhelper
99
100
#endif
/* ! INCLUDED_SALHELPER_REFOBJ_HXX */
101
102
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
types.h
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition
types.h:396
alloc.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
interlck.h
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition
interlck.h:44
salhelper
Definition
condition.hxx:34
salhelper::ReferenceObject::acquire
void acquire()
Definition
refobj.hxx:74
salhelper::ReferenceObject::~ReferenceObject
virtual ~ReferenceObject()
Destruction.
Definition
refobj.hxx:91
salhelper::ReferenceObject::ReferenceObject
ReferenceObject()
Construction.
Definition
refobj.hxx:70
salhelper::ReferenceObject::release
void release()
Definition
refobj.hxx:79
salhelper
refobj.hxx
Generated by
1.17.0