1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _CODEMAKER_DEPENDENCY_HXX_ 29*cdf0e10cSrcweir #define _CODEMAKER_DEPENDENCY_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <hash_map> 32*cdf0e10cSrcweir #include <registry/registry.hxx> 33*cdf0e10cSrcweir #ifndef __REGISTRY_REFLREAD_HXX__ 34*cdf0e10cSrcweir #include <registry/reflread.hxx> 35*cdf0e10cSrcweir #endif 36*cdf0e10cSrcweir #include <codemaker/typemanager.hxx> 37*cdf0e10cSrcweir #include <codemaker/global.hxx> 38*cdf0e10cSrcweir #include <osl/diagnose.h> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define TYPEUSE_NORMAL 0x0001 41*cdf0e10cSrcweir #define TYPEUSE_SUPER 0x0002 42*cdf0e10cSrcweir #define TYPEUSE_MEMBER 0x0004 43*cdf0e10cSrcweir #define TYPEUSE_INPARAM 0x0008 44*cdf0e10cSrcweir #define TYPEUSE_OUTPARAM 0x0010 45*cdf0e10cSrcweir #define TYPEUSE_INOUTPARAM 0x0020 46*cdf0e10cSrcweir #define TYPEUSE_RETURN 0x0040 47*cdf0e10cSrcweir #define TYPEUSE_EXCEPTION 0x0080 48*cdf0e10cSrcweir #define TYPEUSE_SCOPE 0x0100 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /** 51*cdf0e10cSrcweir * Flag shows the state of the code generation. If the Flag is set 52*cdf0e10cSrcweir * the code for this type is generated. 53*cdf0e10cSrcweir */ 54*cdf0e10cSrcweir #define CODEGEN_DEFAULT 0x0001 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir struct TypeUsing 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir TypeUsing(const ::rtl::OString& type, sal_uInt16 use) 59*cdf0e10cSrcweir : m_type(type) 60*cdf0e10cSrcweir , m_use(use) 61*cdf0e10cSrcweir {} 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ::rtl::OString m_type; 64*cdf0e10cSrcweir sal_uInt16 m_use; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir sal_Bool operator == (const TypeUsing & typeUsing) const 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir OSL_ASSERT(0); 69*cdf0e10cSrcweir return m_type == typeUsing.m_type && m_use == typeUsing.m_use; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir }; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir struct LessTypeUsing 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir sal_Bool operator()(const TypeUsing& tuse1, const TypeUsing& tuse2) const 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir return (tuse1.m_type < tuse2.m_type); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir typedef ::std::set< TypeUsing, LessTypeUsing > TypeUsingSet; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir #if (defined( _MSC_VER ) && ( _MSC_VER < 1200 )) 85*cdf0e10cSrcweir typedef ::std::__hash_map__ 86*cdf0e10cSrcweir < 87*cdf0e10cSrcweir ::rtl::OString, 88*cdf0e10cSrcweir TypeUsingSet, 89*cdf0e10cSrcweir HashString, 90*cdf0e10cSrcweir EqualString, 91*cdf0e10cSrcweir NewAlloc 92*cdf0e10cSrcweir > DependencyMap; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir typedef ::std::__hash_map__ 95*cdf0e10cSrcweir < 96*cdf0e10cSrcweir ::rtl::OString, 97*cdf0e10cSrcweir sal_uInt16, 98*cdf0e10cSrcweir HashString, 99*cdf0e10cSrcweir EqualString, 100*cdf0e10cSrcweir NewAlloc 101*cdf0e10cSrcweir > GenerationMap; 102*cdf0e10cSrcweir #else 103*cdf0e10cSrcweir typedef ::std::hash_map 104*cdf0e10cSrcweir < 105*cdf0e10cSrcweir ::rtl::OString, 106*cdf0e10cSrcweir TypeUsingSet, 107*cdf0e10cSrcweir HashString, 108*cdf0e10cSrcweir EqualString 109*cdf0e10cSrcweir > DependencyMap; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir typedef ::std::hash_map 112*cdf0e10cSrcweir < 113*cdf0e10cSrcweir ::rtl::OString, 114*cdf0e10cSrcweir sal_uInt16, 115*cdf0e10cSrcweir HashString, 116*cdf0e10cSrcweir EqualString 117*cdf0e10cSrcweir > GenerationMap; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir #endif 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir struct TypeDependencyImpl 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir TypeDependencyImpl() 124*cdf0e10cSrcweir : m_refCount(0) 125*cdf0e10cSrcweir {} 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir sal_Int32 m_refCount; 128*cdf0e10cSrcweir DependencyMap m_dependencies; 129*cdf0e10cSrcweir GenerationMap m_generatedTypes; 130*cdf0e10cSrcweir }; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir class TypeDependency 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir public: 135*cdf0e10cSrcweir TypeDependency(); 136*cdf0e10cSrcweir ~TypeDependency(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir TypeDependency( const TypeDependency& value ) 139*cdf0e10cSrcweir : m_pImpl( value.m_pImpl ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir acquire(); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir TypeDependency& operator = ( const TypeDependency& value ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir release(); 147*cdf0e10cSrcweir m_pImpl = value.m_pImpl; 148*cdf0e10cSrcweir acquire(); 149*cdf0e10cSrcweir return *this; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir sal_Bool insert(const ::rtl::OString& type, const ::rtl::OString& depend, sal_uInt16); 153*cdf0e10cSrcweir TypeUsingSet getDependencies(const ::rtl::OString& type); 154*cdf0e10cSrcweir sal_Bool hasDependencies(const ::rtl::OString& type); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir void setGenerated(const ::rtl::OString& type, sal_uInt16 genFlag=CODEGEN_DEFAULT); 157*cdf0e10cSrcweir sal_Bool isGenerated(const ::rtl::OString& type, sal_uInt16 genFlag=CODEGEN_DEFAULT); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir sal_Int32 getSize() { return m_pImpl->m_generatedTypes.size(); } 160*cdf0e10cSrcweir protected: 161*cdf0e10cSrcweir void acquire(); 162*cdf0e10cSrcweir void release(); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir protected: 165*cdf0e10cSrcweir TypeDependencyImpl* m_pImpl; 166*cdf0e10cSrcweir }; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir sal_Bool checkTypeDependencies(TypeManager& typeMgr, TypeDependency& dependencies, const ::rtl::OString& type, sal_Bool bDepend = sal_False); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir #endif // _CODEMAKER_DEPENDENCY_HXX_ 171