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