xref: /aoo4110/main/store/source/object.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_store.hxx"
26 
27 #include "object.hxx"
28 
29 #include "sal/types.h"
30 #include "rtl/alloc.h"
31 #include "rtl/ref.hxx"
32 #include "osl/diagnose.h"
33 #include "osl/interlck.h"
34 
35 namespace store
36 {
37 
38 /*========================================================================
39  *
40  * OStoreObject implementation.
41  *
42  *======================================================================*/
43 const sal_uInt32 OStoreObject::m_nTypeId = sal_uInt32(0x58190322);
44 
45 /*
46  * OStoreObject.
47  */
OStoreObject(void)48 OStoreObject::OStoreObject (void)
49 	: m_nRefCount (0)
50 {
51 }
52 
53 /*
54  * ~OStoreObject.
55  */
~OStoreObject(void)56 OStoreObject::~OStoreObject (void)
57 {
58 	OSL_ASSERT(m_nRefCount == 0);
59 }
60 
61 /*
62  * operator new.
63  */
operator new(size_t n)64 void* OStoreObject::operator new (size_t n)
65 {
66 	return rtl_allocateMemory (n);
67 }
68 
69 /*
70  * operator delete.
71  */
operator delete(void * p,size_t)72 void OStoreObject::operator delete (void *p, size_t)
73 {
74 	rtl_freeMemory (p);
75 }
76 
77 /*
78  * isKindOf.
79  */
isKindOf(sal_uInt32 nTypeId)80 sal_Bool SAL_CALL OStoreObject::isKindOf (sal_uInt32 nTypeId)
81 {
82 	return (nTypeId == m_nTypeId);
83 }
84 
85 /*
86  * acquire.
87  */
acquire(void)88 oslInterlockedCount SAL_CALL OStoreObject::acquire (void)
89 {
90 	oslInterlockedCount result = osl_incrementInterlockedCount (&m_nRefCount);
91 	return (result);
92 }
93 
94 /*
95  * release.
96  */
release(void)97 oslInterlockedCount SAL_CALL OStoreObject::release (void)
98 {
99 	oslInterlockedCount result = osl_decrementInterlockedCount (&m_nRefCount);
100 	if (result == 0)
101 	{
102 		// Last reference released.
103 		delete this;
104 	}
105 	return (result);
106 }
107 
108 } // namespace store
109