xref: /trunk/main/registry/inc/registry/reflwrit.hxx (revision a4b70a5c)
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 
24 #ifndef _REGISTRY_REFLWRIT_HXX_
25 #define _REGISTRY_REFLWRIT_HXX_
26 
27 #include <registry/refltype.hxx>
28 #include <registry/regtype.h>
29 #include "registry/registrydllapi.h"
30 #include <rtl/ustring.hxx>
31 
32 /// Implememetation handle
33 typedef void* TypeWriterImpl;
34 
35 /****************************************************************************
36 
37 	C-Api
38 
39 *****************************************************************************/
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /** specifies a collection of function pointers which represents the complete registry type writer C-API.
46 
47     This funtions pointers are used by the C++ wrapper to call the C-API.
48 */
49 struct RegistryTypeWriter_Api
50 {
51 	TypeWriterImpl	 		(TYPEREG_CALLTYPE *createEntry) 		(RTTypeClass, rtl_uString*, rtl_uString*, sal_uInt16, sal_uInt16, sal_uInt16);
52 	void					(TYPEREG_CALLTYPE *acquire) 			(TypeWriterImpl);
53 	void					(TYPEREG_CALLTYPE *release) 			(TypeWriterImpl);
54 	void					(TYPEREG_CALLTYPE *setUik) 				(TypeWriterImpl, const RTUik*);
55 	void					(TYPEREG_CALLTYPE *setDoku)				(TypeWriterImpl, rtl_uString*);
56 	void					(TYPEREG_CALLTYPE *setFileName)			(TypeWriterImpl, rtl_uString*);
57 	void 					(TYPEREG_CALLTYPE *setFieldData) 		(TypeWriterImpl, sal_uInt16, rtl_uString*, rtl_uString*, rtl_uString*, rtl_uString*, RTFieldAccess,	RTValueType, RTConstValueUnion);
58 	void 					(TYPEREG_CALLTYPE *setMethodData)		(TypeWriterImpl, sal_uInt16, rtl_uString*, rtl_uString*, RTMethodMode, sal_uInt16, sal_uInt16, rtl_uString*);
59 	void 					(TYPEREG_CALLTYPE *setParamData)		(TypeWriterImpl, sal_uInt16, sal_uInt16, rtl_uString*, rtl_uString*, RTParamMode);
60 	void 					(TYPEREG_CALLTYPE *setExcData)			(TypeWriterImpl, sal_uInt16, sal_uInt16, rtl_uString*);
61 	const sal_uInt8*		(TYPEREG_CALLTYPE *getBlop)				(TypeWriterImpl);
62 	sal_uInt32 				(TYPEREG_CALLTYPE *getBlopSize)			(TypeWriterImpl);
63 
64 	void 					(TYPEREG_CALLTYPE *setReferenceData) 	(TypeWriterImpl, sal_uInt16, rtl_uString*, RTReferenceType, rtl_uString*, RTFieldAccess);
65 };
66 
67 /** the API initialization function.
68 */
69 REGISTRY_DLLPUBLIC RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void);
70 
71 #ifdef __cplusplus
72 }
73 #endif
74 
75 /** RegistryTypeWriter writes/creates a binary type blob.
76 
77     This class provides the necessary functions to write type informations
78     for all kinds of types into a blob.
79 	The class is inline and use a C-Api.
80 
81     @deprecated
82     use typereg::Writer instead
83 */
84 class RegistryTypeWriter
85 {
86 public:
87 
88 	/** Constructor.
89 
90         @param RTTypeClass specifies the type of the new blob.
91         @param typeName specifies the full qualified type name with '/' as separator.
92         @param superTypeName specifies the full qualified type name of the base type
93                              with '/' as separator.
94         @param fieldCount specifies the number of fields (eg. number of attrbutes/properties,
95                           enum values or constants).
96         @param methodCount specifies the number of methods.
97         @param referenceCount specifies the number of references (eg. number of supported interfaces,
98                               exported services ...)
99 	 */
100 	inline RegistryTypeWriter(RTTypeClass 				RTTypeClass,
101 							  const ::rtl::OUString& 	typeName,
102 							  const ::rtl::OUString& 	superTypeName,
103 							  sal_uInt16 				fieldCount,
104 							  sal_uInt16 				methodCount,
105 							  sal_uInt16				referenceCount);
106 
107 	/// Copy constructcor
108 	inline RegistryTypeWriter(const RegistryTypeWriter& toCopy);
109 
110 	/** Destructor. The Destructor frees the internal data block.
111 
112         The pointer (returned by getBlop) will be set to NULL.
113      */
114 	inline ~RegistryTypeWriter();
115 
116 	/// Assign operator
117 	inline RegistryTypeWriter& operator == (const RegistryTypeWriter& toAssign);
118 
119     /** @deprecated
120         sets the unique identifier for an interface type.
121 
122         An earlier version of UNO used an unique identifier for interfaces. In the
123         current version of UNO this uik was eliminated and this function is
124         not longer used.
125      */
126 	inline void setUik(const RTUik& uik);
127 
128     /** sets a documentation string for the type.
129 
130         This documentation should be the same as the documentation which is provided
131         for this type in IDL.
132      */
133 	inline void setDoku(const ::rtl::OUString& doku);
134 
135     /** sets the IDL filename where this type is defined.
136      */
137 	inline void setFileName(const ::rtl::OUString& fileName);
138 
139     /** sets the data for a field member of a type blob.
140 
141         @param index indicates the index of the field.
142         @param name specifies the name.
143         @param typeName specifies the full qualified typename.
144         @param doku specifies the documentation string of the field.
145         @param fileName specifies the name of the IDL file where the field is defined.
146         @param access specifies the access mode of the field.
147         @param constValue specifies the value of the field. The value is only interesting
148                           for enum values or constants.
149      */
150 	inline void setFieldData( sal_uInt16 				index,
151 							  const ::rtl::OUString& 	name,
152 							  const ::rtl::OUString& 	typeName,
153 							  const ::rtl::OUString&	doku,
154 							  const ::rtl::OUString& 	fileName,
155 							  RTFieldAccess 			access,
156 							  RTConstValue 				constValue = RTConstValue());
157 
158     /** sets the data for a method.
159 
160         @param index indicates the index of the method.
161         @param name specifies the name.
162         @param typeName specifies the full qualified return typename.
163         @param mode specifies the method mode.
164         @param paramCount specifies the number of parameters.
165         @param excCount specifies the number of exceptions.
166         @param doku specifies the documentation string of the field.
167      */
168 	inline void setMethodData(sal_uInt16				index,
169 							  const ::rtl::OUString& 	name,
170 							  const ::rtl::OUString& 	returnTypeName,
171 							  RTMethodMode				mode,
172 							  sal_uInt16				paramCount,
173 							  sal_uInt16				excCount,
174 							  const ::rtl::OUString&	doku);
175 
176     /** sets the data for the specified parameter of a method.
177 
178         @param index indicates the index of the method.
179         @param paramIndex specifies the index of the parameter.
180         @param type specifies the full qualified typename.
181         @param name specifies the name.
182         @param mode specifies the parameter mode.
183      */
184 	inline void setParamData(sal_uInt16				index,
185 							 sal_uInt16				paramIndex,
186 							 const ::rtl::OUString&	type,
187 							 const ::rtl::OUString&	name,
188 							 RTParamMode			mode);
189 
190     /** sets the data for the specified exception of a method.
191 
192         @param index indicates the index of the method.
193         @param excIndex specifies the index of the exception.
194         @param type specifies the full qualified typename of the exception.
195      */
196 	inline void setExcData(sal_uInt16				index,
197 						   sal_uInt16				excIndex,
198 						   const ::rtl::OUString&	type);
199 
200     /** returns a pointer to the new type blob.
201 
202         The pointer will be invalid (NULL) if the instance of
203         the RegistryTypeWriter will be destroyed.
204      */
205 	inline const sal_uInt8* 	getBlop();
206 
207     /** returns the size of the new type blob in bytes.
208      */
209 	inline sal_uInt32 		getBlopSize();
210 
211     /** sets the data for a reference member.
212 
213         @param index indicates the index of the reference.
214         @param name specifies the name.
215         @param refType specifies the full qualified typename of the reference.
216         @param doku specifies the documentation string of the reference.
217         @param access specifies the access mode of the reference.
218      */
219 	inline void setReferenceData( sal_uInt16 				index,
220 							  	  const ::rtl::OUString& 	name,
221 							  	  RTReferenceType 			refType,
222 							  	  const ::rtl::OUString& 	doku,
223 							  	  RTFieldAccess				access = RT_ACCESS_INVALID);
224 
225 protected:
226 
227     /// stores the registry type writer Api.
228 	const RegistryTypeWriter_Api*								 m_pApi;
229     /// stores the handle of an implementation class
230 	TypeWriterImpl												 m_hImpl;
231 };
232 
233 
234 
RegistryTypeWriter(RTTypeClass RTTypeClass,const::rtl::OUString & typeName,const::rtl::OUString & superTypeName,sal_uInt16 fieldCount,sal_uInt16 methodCount,sal_uInt16 referenceCount)235 inline RegistryTypeWriter::RegistryTypeWriter(RTTypeClass 				RTTypeClass,
236 											  const ::rtl::OUString& 	typeName,
237 											  const ::rtl::OUString& 	superTypeName,
238 											  sal_uInt16 				fieldCount,
239 											  sal_uInt16 				methodCount,
240 											  sal_uInt16				referenceCount)
241 	: m_pApi(initRegistryTypeWriter_Api())
242 	, m_hImpl(NULL)
243 {
244 	m_hImpl = m_pApi->createEntry(RTTypeClass,
245 								  typeName.pData,
246 								  superTypeName.pData,
247 								  fieldCount,
248 								  methodCount,
249 								  referenceCount);
250 }
251 
252 
RegistryTypeWriter(const RegistryTypeWriter & toCopy)253 inline RegistryTypeWriter::RegistryTypeWriter(const RegistryTypeWriter& toCopy)
254 	: m_pApi(toCopy.m_pApi)
255 	, m_hImpl(toCopy.m_hImpl)
256 {
257 	m_pApi->acquire(m_hImpl);
258 }
259 
~RegistryTypeWriter()260 inline RegistryTypeWriter::~RegistryTypeWriter()
261 {
262 	m_pApi->release(m_hImpl);
263 }
264 
operator ==(const RegistryTypeWriter & toAssign)265 inline RegistryTypeWriter& RegistryTypeWriter::operator == (const RegistryTypeWriter& toAssign)
266 {
267 	if (m_hImpl != toAssign.m_hImpl)
268 	{
269 		m_pApi->release(m_hImpl);
270 		m_hImpl = toAssign.m_hImpl;
271 		m_pApi->acquire(m_hImpl);
272 	}
273 
274 	return *this;
275 }
276 
setFieldData(sal_uInt16 index,const::rtl::OUString & name,const::rtl::OUString & typeName,const::rtl::OUString & doku,const::rtl::OUString & fileName,RTFieldAccess access,RTConstValue constValue)277 inline void RegistryTypeWriter::setFieldData( sal_uInt16 				index,
278 											  const ::rtl::OUString& 	name,
279 											  const ::rtl::OUString& 	typeName,
280 											  const ::rtl::OUString&	doku,
281 											  const ::rtl::OUString&	fileName,
282 											  RTFieldAccess 			access,
283 											  RTConstValue 				constValue)
284 {
285 	m_pApi->setFieldData(m_hImpl, index, name.pData, typeName.pData, doku.pData, fileName.pData, access, constValue.m_type, constValue.m_value);
286 }
287 
288 
setMethodData(sal_uInt16 index,const::rtl::OUString & name,const::rtl::OUString & returnTypeName,RTMethodMode mode,sal_uInt16 paramCount,sal_uInt16 excCount,const::rtl::OUString & doku)289 inline void RegistryTypeWriter::setMethodData(sal_uInt16				index,
290 											  const ::rtl::OUString& 	name,
291 											  const ::rtl::OUString& 	returnTypeName,
292 											  RTMethodMode				mode,
293 											  sal_uInt16				paramCount,
294 											  sal_uInt16				excCount,
295 											  const ::rtl::OUString&	doku)
296 {
297 	m_pApi->setMethodData(m_hImpl, index, name.pData, returnTypeName.pData, mode, paramCount, excCount, doku.pData);
298 }
299 
300 
setUik(const RTUik & uik)301 inline void RegistryTypeWriter::setUik(const RTUik& uik)
302 {
303 	m_pApi->setUik(m_hImpl, &uik);
304 }
305 
setDoku(const::rtl::OUString & doku)306 inline void RegistryTypeWriter::setDoku(const ::rtl::OUString& doku)
307 {
308 	m_pApi->setDoku(m_hImpl, doku.pData);
309 }
310 
setFileName(const::rtl::OUString & doku)311 inline void RegistryTypeWriter::setFileName(const ::rtl::OUString& doku)
312 {
313 	m_pApi->setFileName(m_hImpl, doku.pData);
314 }
315 
setParamData(sal_uInt16 index,sal_uInt16 paramIndex,const::rtl::OUString & type,const::rtl::OUString & name,RTParamMode mode)316 inline void RegistryTypeWriter::setParamData(sal_uInt16				index,
317 											 sal_uInt16				paramIndex,
318 											 const ::rtl::OUString&	type,
319 											 const ::rtl::OUString&	name,
320 											 RTParamMode			mode)
321 {
322 	m_pApi->setParamData(m_hImpl, index, paramIndex, type.pData, name.pData, mode);
323 }
324 
setExcData(sal_uInt16 index,sal_uInt16 excIndex,const::rtl::OUString & type)325 inline void RegistryTypeWriter::setExcData(sal_uInt16				index,
326 										   sal_uInt16				excIndex,
327 										   const ::rtl::OUString&	type)
328 {
329 	m_pApi->setExcData(m_hImpl, index, excIndex, type.pData);
330 }
331 
getBlop()332 inline const sal_uInt8* RegistryTypeWriter::getBlop()
333 {
334 	return m_pApi->getBlop(m_hImpl);
335 }
336 
getBlopSize()337 inline sal_uInt32 RegistryTypeWriter::getBlopSize()
338 {
339 	return m_pApi->getBlopSize(m_hImpl);
340 }
341 
342 
setReferenceData(sal_uInt16 index,const::rtl::OUString & name,RTReferenceType refType,const::rtl::OUString & doku,RTFieldAccess access)343 inline void RegistryTypeWriter::setReferenceData( sal_uInt16 				index,
344 											  	  const ::rtl::OUString& 	name,
345 											  	  RTReferenceType 			refType,
346 											  	  const ::rtl::OUString& 	doku,
347 											  	  RTFieldAccess 			access)
348 {
349 	m_pApi->setReferenceData(m_hImpl, index, name.pData, refType, doku.pData, access);
350 }
351 
352 #endif
353