1*e8c8fa4bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e8c8fa4bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e8c8fa4bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e8c8fa4bSAndrew Rist * distributed with this work for additional information 6*e8c8fa4bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e8c8fa4bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e8c8fa4bSAndrew Rist * "License"); you may not use this file except in compliance 9*e8c8fa4bSAndrew Rist * with the License. You may obtain a copy of the License at 10*e8c8fa4bSAndrew Rist * 11*e8c8fa4bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e8c8fa4bSAndrew Rist * 13*e8c8fa4bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e8c8fa4bSAndrew Rist * software distributed under the License is distributed on an 15*e8c8fa4bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e8c8fa4bSAndrew Rist * KIND, either express or implied. See the License for the 17*e8c8fa4bSAndrew Rist * specific language governing permissions and limitations 18*e8c8fa4bSAndrew Rist * under the License. 19*e8c8fa4bSAndrew Rist * 20*e8c8fa4bSAndrew Rist *************************************************************/ 21*e8c8fa4bSAndrew Rist 22*e8c8fa4bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <string.h> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <rtl/alloc.h> 27cdf0e10cSrcweir #include <rtl/memory.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <vos/diagnose.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <vos/object.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace vos; 34cdf0e10cSrcweir 35cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 36cdf0e10cSrcweir // Object super class 37cdf0e10cSrcweir 38cdf0e10cSrcweir VOS_NAMESPACE(OClassInfo, vos) VOS_NAMESPACE(OObject, vos)::__ClassInfo__(VOS_CLASSNAME(OObject, vos), sizeof(VOS_NAMESPACE(OObject, vos))); 39cdf0e10cSrcweir 40cdf0e10cSrcweir OObject::OObject() 41cdf0e10cSrcweir { 42cdf0e10cSrcweir } 43cdf0e10cSrcweir 44cdf0e10cSrcweir OObject::OObject(const OCreateParam&) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir OObject::~OObject() 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir void* OObject::operator new(size_t size) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir void* p = rtl_allocateMemory(size); 55cdf0e10cSrcweir 56cdf0e10cSrcweir VOS_ASSERT(p != NULL); 57cdf0e10cSrcweir 58cdf0e10cSrcweir return (p); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir void* OObject::operator new(size_t, void* p) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir return (p); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir void OObject::operator delete(void* p) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir rtl_freeMemory(p); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir const OClassInfo& OObject::classInfo() 72cdf0e10cSrcweir { 73cdf0e10cSrcweir return (__ClassInfo__); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir const OClassInfo& OObject::getClassInfo() const 77cdf0e10cSrcweir { 78cdf0e10cSrcweir return (VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos))); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_Bool OObject::isKindOf(const OClassInfo& rClass) const 82cdf0e10cSrcweir { 83cdf0e10cSrcweir VOS_ASSERT(this != NULL); 84cdf0e10cSrcweir 85cdf0e10cSrcweir const OClassInfo& rClassThis = getClassInfo(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir return (rClassThis.isDerivedFrom(rClass)); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 91cdf0e10cSrcweir // Basic class information 92cdf0e10cSrcweir 93cdf0e10cSrcweir OClassInfo::OClassInfo(const sal_Char *pClassName, sal_Int32 ObjectSize, 94cdf0e10cSrcweir const OClassInfo* pBaseClass, sal_uInt32 Schema, 95cdf0e10cSrcweir OObject* (SAL_CALL * fnCreateObject)(const OCreateParam&)) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir m_pClassName = pClassName; 98cdf0e10cSrcweir m_nObjectSize = ObjectSize; 99cdf0e10cSrcweir m_wSchema = Schema; 100cdf0e10cSrcweir 101cdf0e10cSrcweir m_pfnCreateObject = fnCreateObject; 102cdf0e10cSrcweir 103cdf0e10cSrcweir m_pBaseClass = pBaseClass; 104cdf0e10cSrcweir m_pNextClass = NULL; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir OObject* OClassInfo::createObject(const OCreateParam& rParam) const 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if (m_pfnCreateObject == NULL) 110cdf0e10cSrcweir return NULL; 111cdf0e10cSrcweir 112cdf0e10cSrcweir OObject* pObject = NULL; 113cdf0e10cSrcweir pObject = (*m_pfnCreateObject)(rParam); 114cdf0e10cSrcweir 115cdf0e10cSrcweir return (pObject); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir sal_Bool OClassInfo::isDerivedFrom(const OClassInfo& rClass) const 119cdf0e10cSrcweir { 120cdf0e10cSrcweir VOS_ASSERT(this != NULL); 121cdf0e10cSrcweir 122cdf0e10cSrcweir const OClassInfo* pClassThis = this; 123cdf0e10cSrcweir 124cdf0e10cSrcweir while (pClassThis != NULL) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if (pClassThis == &rClass) 127cdf0e10cSrcweir return (sal_True); 128cdf0e10cSrcweir 129cdf0e10cSrcweir pClassThis = pClassThis->m_pBaseClass; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir return (sal_False); // walked to the top, no match 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir const OClassInfo* OClassInfo::getClassInfo(const sal_Char* pClassName) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir VOS_ASSERT(pClassName != NULL); 138cdf0e10cSrcweir 139cdf0e10cSrcweir const OClassInfo* pClass = &VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos)); 140cdf0e10cSrcweir 141cdf0e10cSrcweir while (pClass != NULL) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir if (strcmp(pClassName, pClass->m_pClassName) == 0) 144cdf0e10cSrcweir break; 145cdf0e10cSrcweir 146cdf0e10cSrcweir pClass = pClass->m_pNextClass; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir return (pClass); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir VOS_CLASSINIT::VOS_CLASSINIT(register OClassInfo* pNewClass) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir VOS_ASSERT(pNewClass != NULL); 155cdf0e10cSrcweir 156cdf0e10cSrcweir OClassInfo* pClassRoot = (OClassInfo*)&VOS_CLASSINFO(VOS_NAMESPACE(OObject, vos)); 157cdf0e10cSrcweir 158cdf0e10cSrcweir pNewClass->m_pNextClass = pClassRoot->m_pNextClass; 159cdf0e10cSrcweir 160cdf0e10cSrcweir pClassRoot->m_pNextClass = pNewClass; 161cdf0e10cSrcweir } 162