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