bump product version to 4.1.6.2
[LibreOffice.git] / include / salhelper / refobj.hxx
blob5d7d322b61407613e956697bbe3c053258603afa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SALHELPER_REFOBJ_HXX_
21 #define _SALHELPER_REFOBJ_HXX_
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>
29 namespace salhelper
32 //----------------------------------------------------------------------------
34 class ReferenceObject : public rtl::IReference
36 /** Representation.
38 oslInterlockedCount m_nReferenceCount;
40 /** Not implemented.
42 ReferenceObject (const ReferenceObject&);
43 ReferenceObject& operator= (const ReferenceObject&);
45 public:
46 /** Allocation.
48 static void* operator new (size_t n) SAL_THROW(())
50 return ::rtl_allocateMemory (n);
52 static void operator delete (void* p) SAL_THROW(())
54 ::rtl_freeMemory (p);
56 static void* operator new (size_t, void* p) SAL_THROW(())
58 return (p);
60 static void operator delete (void*, void*) SAL_THROW(())
63 public:
64 /** Construction.
66 inline ReferenceObject() SAL_THROW(()) : m_nReferenceCount (0)
70 /** IReference.
72 virtual oslInterlockedCount SAL_CALL acquire() SAL_THROW(())
74 return ::osl_incrementInterlockedCount (&m_nReferenceCount);
77 virtual oslInterlockedCount SAL_CALL release() SAL_THROW(())
79 oslInterlockedCount result;
80 result = ::osl_decrementInterlockedCount (&m_nReferenceCount);
81 if (result == 0)
83 // Last reference released.
84 delete this;
86 return (result);
89 protected:
90 /** Destruction.
92 virtual ~ReferenceObject() SAL_THROW(())
94 OSL_ASSERT(m_nReferenceCount == 0);
98 //----------------------------------------------------------------------------
100 } // namespace salhelper
102 #endif /* !_SALHELPER_REFOBJ_HXX_ */
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */