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