xref: /aoo4110/main/vos/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 #include <string.h>
25 
26 #include <rtl/alloc.h>
27 #include <rtl/memory.h>
28 
29 #include <vos/diagnose.hxx>
30 
31 #include <vos/object.hxx>
32 
33 using namespace vos;
34 
35 /////////////////////////////////////////////////////////////////////////////
36 // Object super class
37 
38 VOS_NAMESPACE(OClassInfo, vos) VOS_NAMESPACE(OObject, vos)::__ClassInfo__(VOS_CLASSNAME(OObject, vos), sizeof(VOS_NAMESPACE(OObject, vos)));
39 
OObject()40 OObject::OObject()
41 {
42 }
43 
OObject(const OCreateParam &)44 OObject::OObject(const OCreateParam&)
45 {
46 }
47 
~OObject()48 OObject::~OObject()
49 {
50 }
51 
operator new(size_t size)52 void* OObject::operator new(size_t size)
53 {
54    void* p = rtl_allocateMemory(size);
55 
56    VOS_ASSERT(p != NULL);
57 
58    return (p);
59 }
60 
operator new(size_t,void * p)61 void* OObject::operator new(size_t, void* p)
62 {
63    return (p);
64 }
65 
operator delete(void * p)66 void OObject::operator delete(void* p)
67 {
68    rtl_freeMemory(p);
69 }
70 
classInfo()71 const OClassInfo& OObject::classInfo()
72 {
73 	return (__ClassInfo__);
74 }
75 
getClassInfo() const76 const OClassInfo& OObject::getClassInfo() const
77 {
78 	return (VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos)));
79 }
80 
isKindOf(const OClassInfo & rClass) const81 sal_Bool OObject::isKindOf(const OClassInfo& rClass) const
82 {
83     VOS_ASSERT(this != NULL);
84 
85     const OClassInfo& rClassThis = getClassInfo();
86 
87     return (rClassThis.isDerivedFrom(rClass));
88 }
89 
90 /////////////////////////////////////////////////////////////////////////////
91 // Basic class information
92 
OClassInfo(const sal_Char * pClassName,sal_Int32 ObjectSize,const OClassInfo * pBaseClass,sal_uInt32 Schema,OObject * (SAL_CALL * fnCreateObject)(const OCreateParam &))93 OClassInfo::OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize,
94 		               const OClassInfo* pBaseClass, sal_uInt32 Schema,
95 			           OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&))
96 {
97 	m_pClassName  = pClassName;
98 	m_nObjectSize = ObjectSize;
99 	m_wSchema     = Schema;
100 
101 	m_pfnCreateObject = fnCreateObject;
102 
103 	m_pBaseClass = pBaseClass;
104 	m_pNextClass = NULL;
105 }
106 
createObject(const OCreateParam & rParam) const107 OObject* OClassInfo::createObject(const OCreateParam& rParam) const
108 {
109 	if (m_pfnCreateObject == NULL)
110 		return NULL;
111 
112     OObject* pObject = NULL;
113 	pObject = (*m_pfnCreateObject)(rParam);
114 
115 	return (pObject);
116 }
117 
isDerivedFrom(const OClassInfo & rClass) const118 sal_Bool OClassInfo::isDerivedFrom(const OClassInfo& rClass) const
119 {
120 	VOS_ASSERT(this != NULL);
121 
122 	const OClassInfo* pClassThis = this;
123 
124 	while (pClassThis != NULL)
125 	{
126 		if (pClassThis == &rClass)
127 			return (sal_True);
128 
129 		pClassThis = pClassThis->m_pBaseClass;
130 	}
131 
132 	return (sal_False);      // walked to the top, no match
133 }
134 
getClassInfo(const sal_Char * pClassName)135 const OClassInfo* OClassInfo::getClassInfo(const sal_Char* pClassName)
136 {
137 	VOS_ASSERT(pClassName != NULL);
138 
139 	const OClassInfo* pClass = &VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos));
140 
141 	while (pClass != NULL)
142 	{
143 		if (strcmp(pClassName, pClass->m_pClassName) == 0)
144 			break;
145 
146 		pClass = pClass->m_pNextClass;
147 	}
148 
149 	return (pClass);
150 }
151 
VOS_CLASSINIT(register OClassInfo * pNewClass)152 VOS_CLASSINIT::VOS_CLASSINIT(register OClassInfo* pNewClass)
153 {
154 	VOS_ASSERT(pNewClass != NULL);
155 
156 	OClassInfo* pClassRoot = (OClassInfo*)&VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos));
157 
158 	pNewClass->m_pNextClass = pClassRoot->m_pNextClass;
159 
160 	pClassRoot->m_pNextClass = pNewClass;
161 }
162