2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-05-14 10:50:46 +00:00
|
|
|
|
2013-10-23 19:14:56 +02:00
|
|
|
#ifndef INCLUDED_SALHELPER_REFOBJ_HXX
|
|
|
|
#define INCLUDED_SALHELPER_REFOBJ_HXX
|
2001-05-14 10:50:46 +00:00
|
|
|
|
|
|
|
#include <sal/types.h>
|
|
|
|
#include <rtl/alloc.h>
|
|
|
|
#include <osl/diagnose.h>
|
|
|
|
#include <osl/interlck.h>
|
|
|
|
|
|
|
|
namespace salhelper
|
|
|
|
{
|
|
|
|
|
2015-02-05 16:45:45 +01:00
|
|
|
/** A base implementation for reference-counted objects.
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2015-02-05 16:45:45 +01:00
|
|
|
@deprecated use salhelper::SimpleReferenceObject instead
|
|
|
|
*/
|
2014-07-11 16:32:28 +02:00
|
|
|
class ReferenceObject
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
|
|
|
/** Representation.
|
|
|
|
*/
|
|
|
|
oslInterlockedCount m_nReferenceCount;
|
|
|
|
|
2015-02-07 12:26:56 +01:00
|
|
|
ReferenceObject (const ReferenceObject&) SAL_DELETED_FUNCTION;
|
|
|
|
ReferenceObject& operator= (const ReferenceObject&) SAL_DELETED_FUNCTION;
|
2001-05-14 10:50:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** Allocation.
|
|
|
|
*/
|
2014-06-05 08:16:59 +02:00
|
|
|
static void* operator new (size_t n)
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
|
|
|
return ::rtl_allocateMemory (n);
|
|
|
|
}
|
2014-06-05 08:16:59 +02:00
|
|
|
static void operator delete (void* p)
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
|
|
|
::rtl_freeMemory (p);
|
|
|
|
}
|
2014-06-05 08:16:59 +02:00
|
|
|
static void* operator new (size_t, void* p)
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
2015-02-11 13:20:49 +02:00
|
|
|
return p;
|
2001-05-14 10:50:46 +00:00
|
|
|
}
|
2014-06-05 08:16:59 +02:00
|
|
|
static void operator delete (void*, void*)
|
2001-05-14 10:50:46 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Construction.
|
|
|
|
*/
|
2014-07-11 16:32:28 +02:00
|
|
|
inline ReferenceObject() : m_nReferenceCount(0)
|
2001-05-14 10:50:46 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2014-07-11 16:32:28 +02:00
|
|
|
void SAL_CALL acquire()
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
2014-07-11 16:32:28 +02:00
|
|
|
osl_atomic_increment(&m_nReferenceCount);
|
2001-05-14 10:50:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 16:32:28 +02:00
|
|
|
void SAL_CALL release()
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
2014-07-11 16:32:28 +02:00
|
|
|
if (osl_atomic_decrement(&m_nReferenceCount) == 0)
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
|
|
|
// Last reference released.
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Destruction.
|
|
|
|
*/
|
2014-06-05 08:16:59 +02:00
|
|
|
virtual ~ReferenceObject()
|
2001-05-14 10:50:46 +00:00
|
|
|
{
|
|
|
|
OSL_ASSERT(m_nReferenceCount == 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2001-05-14 10:50:46 +00:00
|
|
|
|
|
|
|
} // namespace salhelper
|
|
|
|
|
2013-10-23 19:14:56 +02:00
|
|
|
#endif /* ! INCLUDED_SALHELPER_REFOBJ_HXX */
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|