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_REGISTRY_HXX_
29*cdf0e10cSrcweir #define _CODEMAKER_REGISTRY_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <rtl/alloc.h>
32*cdf0e10cSrcweir #include <osl/interlck.h>
33*cdf0e10cSrcweir #include	<registry/registry.hxx>
34*cdf0e10cSrcweir #include "registry/reader.hxx"
35*cdf0e10cSrcweir #include "registry/version.h"
36*cdf0e10cSrcweir #include	<codemaker/options.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir struct TypeReader_Impl
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir 	TypeReader_Impl(const sal_uInt8* buffer,
41*cdf0e10cSrcweir 			   	    sal_uInt32 bufferLen,
42*cdf0e10cSrcweir 			   	    sal_Bool copyData)
43*cdf0e10cSrcweir 		: m_refCount(0)
44*cdf0e10cSrcweir 		, m_copyData(copyData)
45*cdf0e10cSrcweir 		, m_blopSize(bufferLen)
46*cdf0e10cSrcweir 		, m_pBlop(buffer)
47*cdf0e10cSrcweir 		{
48*cdf0e10cSrcweir 			if (copyData)
49*cdf0e10cSrcweir 			{
50*cdf0e10cSrcweir 				m_pBlop = (sal_uInt8*)rtl_allocateMemory(bufferLen);
51*cdf0e10cSrcweir 				rtl_copyMemory((void*)m_pBlop, buffer, bufferLen);
52*cdf0e10cSrcweir 			} else
53*cdf0e10cSrcweir 			{
54*cdf0e10cSrcweir 				m_blopSize = bufferLen;
55*cdf0e10cSrcweir 				m_pBlop = buffer;
56*cdf0e10cSrcweir 			}
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 			m_pReader = new typereg::Reader(
59*cdf0e10cSrcweir                 m_pBlop, m_blopSize, false, TYPEREG_VERSION_1);
60*cdf0e10cSrcweir 		}
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	~TypeReader_Impl()
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 			if (m_copyData && m_pReader)
65*cdf0e10cSrcweir 			{
66*cdf0e10cSrcweir 				delete m_pReader;
67*cdf0e10cSrcweir 			}
68*cdf0e10cSrcweir 		}
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 	sal_Int32			m_refCount;
71*cdf0e10cSrcweir 	sal_Bool			m_copyData;
72*cdf0e10cSrcweir 	sal_Int32			m_blopSize;
73*cdf0e10cSrcweir 	const sal_uInt8* 	m_pBlop;
74*cdf0e10cSrcweir 	typereg::Reader*	m_pReader;
75*cdf0e10cSrcweir };
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir class TypeReader
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir /*
80*cdf0e10cSrcweir 	inline TypeReader(const RegistryTypeReader_Api* pApi,
81*cdf0e10cSrcweir 							  const sal_uInt8* buffer,
82*cdf0e10cSrcweir 							  sal_uInt32 bufferLen,
83*cdf0e10cSrcweir 							  sal_Bool copyData);
84*cdf0e10cSrcweir */
85*cdf0e10cSrcweir public:
86*cdf0e10cSrcweir 	inline TypeReader()
87*cdf0e10cSrcweir 		: m_pImpl(NULL)
88*cdf0e10cSrcweir 	{}
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	inline TypeReader(        const sal_uInt8* buffer,
91*cdf0e10cSrcweir 							  sal_uInt32 bufferLen,
92*cdf0e10cSrcweir 							  sal_Bool copyData)
93*cdf0e10cSrcweir 	{
94*cdf0e10cSrcweir 		m_pImpl = new TypeReader_Impl(buffer, bufferLen, copyData);
95*cdf0e10cSrcweir 		acquire();
96*cdf0e10cSrcweir 	}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	inline TypeReader(const TypeReader& toCopy)
99*cdf0e10cSrcweir 		: m_pImpl(toCopy.m_pImpl)
100*cdf0e10cSrcweir 	{
101*cdf0e10cSrcweir 		acquire();
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     inline ~TypeReader()
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 		release();
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     inline void acquire()
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		if (m_pImpl)
112*cdf0e10cSrcweir 			osl_incrementInterlockedCount(&m_pImpl->m_refCount);
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	inline void release()
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		if (m_pImpl && 0 == osl_decrementInterlockedCount(&m_pImpl->m_refCount))
118*cdf0e10cSrcweir 		{
119*cdf0e10cSrcweir 			delete m_pImpl;
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir 	}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	inline TypeReader& operator = ( const TypeReader& value )
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		release();
126*cdf0e10cSrcweir 		m_pImpl = value.m_pImpl;
127*cdf0e10cSrcweir 		acquire();
128*cdf0e10cSrcweir 		return *this;
129*cdf0e10cSrcweir 	}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	inline sal_Bool			isValid() const
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			if (m_pImpl)
134*cdf0e10cSrcweir 				return m_pImpl->m_pReader->isValid();
135*cdf0e10cSrcweir 			else
136*cdf0e10cSrcweir 				return sal_False;
137*cdf0e10cSrcweir 		}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	inline RTTypeClass 				getTypeClass() const
140*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getTypeClass(); }
141*cdf0e10cSrcweir 	inline const ::rtl::OString 	getTypeName() const
142*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getTypeName() ); }
143*cdf0e10cSrcweir     inline sal_uInt16 getSuperTypeCount() const
144*cdf0e10cSrcweir         { return m_pImpl->m_pReader->getSuperTypeCount(); }
145*cdf0e10cSrcweir 	inline const ::rtl::OString 	getSuperTypeName(sal_uInt16 index) const
146*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getSuperTypeName(index) ); }
147*cdf0e10cSrcweir 	inline const ::rtl::OString 	getDoku() const
148*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getDocumentation() ); }
149*cdf0e10cSrcweir 	inline const ::rtl::OString 	getFileName() const
150*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getFileName() ); }
151*cdf0e10cSrcweir 	inline sal_uInt32				getFieldCount() const
152*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getFieldCount(); }
153*cdf0e10cSrcweir 	inline const ::rtl::OString 	getFieldName( sal_uInt16 index ) const
154*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldName(index) ); }
155*cdf0e10cSrcweir 	inline const ::rtl::OString		getFieldType( sal_uInt16 index ) const
156*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldTypeName(index) ); }
157*cdf0e10cSrcweir 	inline RTFieldAccess			getFieldAccess( sal_uInt16 index ) const
158*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getFieldFlags(index); }
159*cdf0e10cSrcweir 	inline RTConstValue				getFieldConstValue( sal_uInt16 index ) const
160*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getFieldValue(index); }
161*cdf0e10cSrcweir 	inline const ::rtl::OString 	getFieldDoku( sal_uInt16 index ) const
162*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldDocumentation(index) ); }
163*cdf0e10cSrcweir 	inline const ::rtl::OString 	getFieldFileName( sal_uInt16 index ) const
164*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getFieldFileName(index) ); }
165*cdf0e10cSrcweir 	inline sal_uInt32				getMethodCount() const
166*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getMethodCount(); }
167*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodName( sal_uInt16 index ) const
168*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodName(index) ); }
169*cdf0e10cSrcweir 	inline sal_uInt32    			getMethodParamCount( sal_uInt16 index ) const
170*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getMethodParameterCount(index); }
171*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodParamType( sal_uInt16 index, sal_uInt16 paramIndex ) const
172*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodParameterTypeName(index,paramIndex) ); }
173*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodParamName( sal_uInt16 index, sal_uInt16 paramIndex ) const
174*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodParameterName(index,paramIndex) ); }
175*cdf0e10cSrcweir 	inline RTParamMode				getMethodParamMode( sal_uInt16 index, sal_uInt16 paramIndex ) const
176*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getMethodParameterFlags(index,paramIndex); }
177*cdf0e10cSrcweir 	inline sal_uInt32    			getMethodExcCount( sal_uInt16 index ) const
178*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getMethodExceptionCount(index); }
179*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodExcType( sal_uInt16 index, sal_uInt16 excIndex ) const
180*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodExceptionTypeName(index,excIndex) ); }
181*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodReturnType( sal_uInt16 index ) const
182*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodReturnTypeName(index) ); }
183*cdf0e10cSrcweir 	inline RTMethodMode				getMethodMode( sal_uInt16 index ) const
184*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getMethodFlags(index); }
185*cdf0e10cSrcweir 	inline const ::rtl::OString 	getMethodDoku( sal_uInt16 index ) const
186*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getMethodDocumentation(index) ); }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	inline sal_uInt32				getReferenceCount() const
189*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getReferenceCount(); }
190*cdf0e10cSrcweir 	inline const ::rtl::OString 	getReferenceName( sal_uInt16 index ) const
191*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getReferenceTypeName(index) ); }
192*cdf0e10cSrcweir 	inline RTReferenceType			getReferenceType( sal_uInt16 index ) const
193*cdf0e10cSrcweir 		{ return m_pImpl->m_pReader->getReferenceSort(index); }
194*cdf0e10cSrcweir 	inline const ::rtl::OString 	getReferenceDoku( sal_uInt16 index ) const
195*cdf0e10cSrcweir 		{ return inGlobalSet( m_pImpl->m_pReader->getReferenceDocumentation(index) ); }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	inline sal_uInt32 getBlopSize() const
198*cdf0e10cSrcweir 		{ return m_pImpl->m_blopSize; }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	inline const sal_uInt8* getBlop() const
201*cdf0e10cSrcweir 		{ return m_pImpl->m_pBlop; }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir private:
204*cdf0e10cSrcweir 	TypeReader_Impl* m_pImpl;
205*cdf0e10cSrcweir };
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir #endif // _CODEMAKER_REGISTRY_HXX_
209