merge the formfield patch from ooo-build
[ooovba.git] / vos / source / object.cxx
blob2ededc2cacfd85e79e8c68a8c92e8d602903cd1f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: object.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <string.h>
33 #include <rtl/alloc.h>
34 #include <rtl/memory.h>
36 #include <vos/diagnose.hxx>
38 #include <vos/object.hxx>
40 using namespace vos;
42 /////////////////////////////////////////////////////////////////////////////
43 // Object super class
45 VOS_NAMESPACE(OClassInfo, vos) VOS_NAMESPACE(OObject, vos)::__ClassInfo__(VOS_CLASSNAME(OObject, vos), sizeof(VOS_NAMESPACE(OObject, vos)));
47 OObject::OObject()
51 OObject::OObject(const OCreateParam&)
55 OObject::~OObject()
59 void* OObject::operator new(size_t size)
61 void* p = rtl_allocateMemory(size);
63 VOS_ASSERT(p != NULL);
65 return (p);
68 void* OObject::operator new(size_t, void* p)
70 return (p);
73 void OObject::operator delete(void* p)
75 rtl_freeMemory(p);
78 const OClassInfo& OObject::classInfo()
80 return (__ClassInfo__);
83 const OClassInfo& OObject::getClassInfo() const
85 return (VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos)));
88 sal_Bool OObject::isKindOf(const OClassInfo& rClass) const
90 VOS_ASSERT(this != NULL);
92 const OClassInfo& rClassThis = getClassInfo();
94 return (rClassThis.isDerivedFrom(rClass));
97 /////////////////////////////////////////////////////////////////////////////
98 // Basic class information
100 OClassInfo::OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize,
101 const OClassInfo* pBaseClass, sal_uInt32 Schema,
102 OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&))
104 m_pClassName = pClassName;
105 m_nObjectSize = ObjectSize;
106 m_wSchema = Schema;
108 m_pfnCreateObject = fnCreateObject;
110 m_pBaseClass = pBaseClass;
111 m_pNextClass = NULL;
114 OObject* OClassInfo::createObject(const OCreateParam& rParam) const
116 if (m_pfnCreateObject == NULL)
117 return NULL;
119 OObject* pObject = NULL;
120 pObject = (*m_pfnCreateObject)(rParam);
122 return (pObject);
125 sal_Bool OClassInfo::isDerivedFrom(const OClassInfo& rClass) const
127 VOS_ASSERT(this != NULL);
129 const OClassInfo* pClassThis = this;
131 while (pClassThis != NULL)
133 if (pClassThis == &rClass)
134 return (sal_True);
136 pClassThis = pClassThis->m_pBaseClass;
139 return (sal_False); // walked to the top, no match
142 const OClassInfo* OClassInfo::getClassInfo(const sal_Char* pClassName)
144 VOS_ASSERT(pClassName != NULL);
146 const OClassInfo* pClass = &VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos));
148 while (pClass != NULL)
150 if (strcmp(pClassName, pClass->m_pClassName) == 0)
151 break;
153 pClass = pClass->m_pNextClass;
156 return (pClass);
159 VOS_CLASSINIT::VOS_CLASSINIT(register OClassInfo* pNewClass)
161 VOS_ASSERT(pNewClass != NULL);
163 OClassInfo* pClassRoot = (OClassInfo*)&VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos));
165 pNewClass->m_pNextClass = pClassRoot->m_pNextClass;
167 pClassRoot->m_pNextClass = pNewClass;