1*2037b4deSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2037b4deSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2037b4deSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2037b4deSAndrew Rist * distributed with this work for additional information 6*2037b4deSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2037b4deSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2037b4deSAndrew Rist * "License"); you may not use this file except in compliance 9*2037b4deSAndrew Rist * with the License. You may obtain a copy of the License at 10*2037b4deSAndrew Rist * 11*2037b4deSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2037b4deSAndrew Rist * 13*2037b4deSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2037b4deSAndrew Rist * software distributed under the License is distributed on an 15*2037b4deSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2037b4deSAndrew Rist * KIND, either express or implied. See the License for the 17*2037b4deSAndrew Rist * specific language governing permissions and limitations 18*2037b4deSAndrew Rist * under the License. 19*2037b4deSAndrew Rist * 20*2037b4deSAndrew Rist *************************************************************/ 21*2037b4deSAndrew Rist 22*2037b4deSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_CODEMAKER_TYPEMANAGER_HXX 25cdf0e10cSrcweir #define INCLUDED_CODEMAKER_TYPEMANAGER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "codemaker/global.hxx" 28cdf0e10cSrcweir #include "registry/registry.hxx" 29cdf0e10cSrcweir #include "registry/types.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <hash_map> 32cdf0e10cSrcweir #include <list> 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace typereg { class Reader; } 35cdf0e10cSrcweir 36cdf0e10cSrcweir //typedef ::std::list< Registry* > RegistryList; 37cdf0e10cSrcweir typedef ::std::vector< Registry* > RegistryList; 38cdf0e10cSrcweir typedef ::std::pair< RegistryKey, sal_Bool > KeyPair; 39cdf0e10cSrcweir typedef ::std::vector< KeyPair > RegistryKeyList; 40cdf0e10cSrcweir 41cdf0e10cSrcweir #if defined( _MSC_VER ) && ( _MSC_VER < 1200 ) 42cdf0e10cSrcweir typedef ::std::__hash_map__ 43cdf0e10cSrcweir < 44cdf0e10cSrcweir ::rtl::OString, // Typename 45cdf0e10cSrcweir RTTypeClass, // TypeClass 46cdf0e10cSrcweir HashString, 47cdf0e10cSrcweir EqualString, 48cdf0e10cSrcweir NewAlloc 49cdf0e10cSrcweir > T2TypeClassMap; 50cdf0e10cSrcweir #else 51cdf0e10cSrcweir typedef ::std::hash_map 52cdf0e10cSrcweir < 53cdf0e10cSrcweir ::rtl::OString, // Typename 54cdf0e10cSrcweir RTTypeClass, // TypeClass 55cdf0e10cSrcweir HashString, 56cdf0e10cSrcweir EqualString 57cdf0e10cSrcweir > T2TypeClassMap; 58cdf0e10cSrcweir #endif 59cdf0e10cSrcweir 60cdf0e10cSrcweir struct TypeManagerImpl 61cdf0e10cSrcweir { TypeManagerImplTypeManagerImpl62cdf0e10cSrcweir TypeManagerImpl() 63cdf0e10cSrcweir : m_refCount(0) 64cdf0e10cSrcweir {} 65cdf0e10cSrcweir 66cdf0e10cSrcweir sal_Int32 m_refCount; 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir class TypeManager 70cdf0e10cSrcweir { 71cdf0e10cSrcweir public: 72cdf0e10cSrcweir TypeManager(); 73cdf0e10cSrcweir virtual ~TypeManager(); 74cdf0e10cSrcweir TypeManager(const TypeManager & value)75cdf0e10cSrcweir TypeManager( const TypeManager& value ) 76cdf0e10cSrcweir : m_pImpl( value.m_pImpl ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir acquire(); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir operator =(const TypeManager & value)81cdf0e10cSrcweir TypeManager& operator = ( const TypeManager& value ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir release(); 84cdf0e10cSrcweir m_pImpl = value.m_pImpl; 85cdf0e10cSrcweir acquire(); 86cdf0e10cSrcweir return *this; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir isValidType(const::rtl::OString &) const89cdf0e10cSrcweir virtual sal_Bool isValidType(const ::rtl::OString&) const 90cdf0e10cSrcweir { return sal_False; } 91cdf0e10cSrcweir getTypeName(RegistryKey &) const92cdf0e10cSrcweir virtual ::rtl::OString getTypeName(RegistryKey&) const 93cdf0e10cSrcweir { return ::rtl::OString(); } 94cdf0e10cSrcweir getTypeKey(const::rtl::OString &,sal_Bool * =0) const95cdf0e10cSrcweir virtual RegistryKey getTypeKey(const ::rtl::OString&, sal_Bool * = 0 ) const 96cdf0e10cSrcweir { return RegistryKey(); } getTypeKeys(const::rtl::OString &) const97cdf0e10cSrcweir virtual RegistryKeyList getTypeKeys(const ::rtl::OString&) const 98cdf0e10cSrcweir { return RegistryKeyList(); } 99cdf0e10cSrcweir virtual typereg::Reader getTypeReader( 100cdf0e10cSrcweir const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const = 0; 101cdf0e10cSrcweir virtual typereg::Reader getTypeReader(RegistryKey& rTypeKey) const = 0; getTypeClass(const::rtl::OString &) const102cdf0e10cSrcweir virtual RTTypeClass getTypeClass(const ::rtl::OString&) const 103cdf0e10cSrcweir { return RT_TYPE_INVALID; } getTypeClass(RegistryKey &) const104cdf0e10cSrcweir virtual RTTypeClass getTypeClass(RegistryKey&) const 105cdf0e10cSrcweir { return RT_TYPE_INVALID; } 106cdf0e10cSrcweir setBase(const::rtl::OString &)107cdf0e10cSrcweir virtual void setBase(const ::rtl::OString&) {} getBase() const108cdf0e10cSrcweir virtual ::rtl::OString getBase() const { return ::rtl::OString(); } 109cdf0e10cSrcweir getSize() const110cdf0e10cSrcweir virtual sal_Int32 getSize() const { return 0; } 111cdf0e10cSrcweir 112cdf0e10cSrcweir static sal_Bool isBaseType(const ::rtl::OString& name); 113cdf0e10cSrcweir protected: 114cdf0e10cSrcweir sal_Int32 acquire(); 115cdf0e10cSrcweir sal_Int32 release(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir protected: 118cdf0e10cSrcweir TypeManagerImpl* m_pImpl; 119cdf0e10cSrcweir }; 120cdf0e10cSrcweir 121cdf0e10cSrcweir struct RegistryTypeManagerImpl 122cdf0e10cSrcweir { RegistryTypeManagerImplRegistryTypeManagerImpl123cdf0e10cSrcweir RegistryTypeManagerImpl() 124cdf0e10cSrcweir : m_base("/") 125cdf0e10cSrcweir {} 126cdf0e10cSrcweir 127cdf0e10cSrcweir T2TypeClassMap m_t2TypeClass; 128cdf0e10cSrcweir RegistryList m_registries; 129cdf0e10cSrcweir RegistryList m_extra_registries; 130cdf0e10cSrcweir ::rtl::OString m_base; 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir 133cdf0e10cSrcweir class RegistryTypeManager : public TypeManager 134cdf0e10cSrcweir { 135cdf0e10cSrcweir public: 136cdf0e10cSrcweir RegistryTypeManager(); 137cdf0e10cSrcweir virtual ~RegistryTypeManager(); 138cdf0e10cSrcweir RegistryTypeManager(const RegistryTypeManager & value)139cdf0e10cSrcweir RegistryTypeManager( const RegistryTypeManager& value ) 140cdf0e10cSrcweir : TypeManager(value) 141cdf0e10cSrcweir , m_pImpl( value.m_pImpl ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir acquire(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir sal_Bool init(const StringVector& regFiles, const StringVector& extraFiles = StringVector() ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir ::rtl::OString getTypeName(RegistryKey& rTypeKey) const; 149cdf0e10cSrcweir isValidType(const::rtl::OString & name) const150cdf0e10cSrcweir sal_Bool isValidType(const ::rtl::OString& name) const 151cdf0e10cSrcweir { return searchTypeKey(name, 0).isValid(); } getTypeKey(const::rtl::OString & name,sal_Bool * pIsExtraType=0) const152cdf0e10cSrcweir RegistryKey getTypeKey( 153cdf0e10cSrcweir const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const 154cdf0e10cSrcweir { return searchTypeKey(name, pIsExtraType); } 155cdf0e10cSrcweir RegistryKeyList getTypeKeys(const ::rtl::OString& name) const; 156cdf0e10cSrcweir typereg::Reader getTypeReader( 157cdf0e10cSrcweir const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const; 158cdf0e10cSrcweir typereg::Reader getTypeReader(RegistryKey& rTypeKey) const; 159cdf0e10cSrcweir RTTypeClass getTypeClass(const ::rtl::OString& name) const; 160cdf0e10cSrcweir RTTypeClass getTypeClass(RegistryKey& rTypeKey) const; 161cdf0e10cSrcweir 162cdf0e10cSrcweir void setBase(const ::rtl::OString& base); getBase() const163cdf0e10cSrcweir ::rtl::OString getBase() const { return m_pImpl->m_base; } 164cdf0e10cSrcweir getSize() const165cdf0e10cSrcweir sal_Int32 getSize() const { return m_pImpl->m_t2TypeClass.size(); } 166cdf0e10cSrcweir protected: 167cdf0e10cSrcweir RegistryKey searchTypeKey( 168cdf0e10cSrcweir const ::rtl::OString& name, sal_Bool * pIsExtraType = 0 ) const; 169cdf0e10cSrcweir void freeRegistries(); 170cdf0e10cSrcweir 171cdf0e10cSrcweir void acquire(); 172cdf0e10cSrcweir void release(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir protected: 175cdf0e10cSrcweir RegistryTypeManagerImpl* m_pImpl; 176cdf0e10cSrcweir }; 177cdf0e10cSrcweir 178cdf0e10cSrcweir #endif // INCLUDED_CODEMAKER_TYPEMANAGER_HXX 179