xref: /trunk/main/registry/inc/registry/writer.hxx (revision 5a5f4a75)
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 INCLUDED_registry_writer_hxx
25 #define INCLUDED_registry_writer_hxx
26 
27 #include "registry/writer.h"
28 #include "registry/refltype.hxx"
29 #include "registry/types.h"
30 #include "registry/version.h"
31 
32 #include "rtl/ustring.hxx"
33 #include "sal/types.h"
34 
35 #include <new>
36 
37 namespace typereg {
38 
39 /// @HTML
40 
41 /**
42    A type writer working on a binary blob that represents a UNOIDL type.
43 
44    <p>Instances of this class are not multi-thread&ndash;safe.</p>
45 
46    @since UDK 3.2.0
47  */
48 class Writer {
49 public:
50     /**
51        Creates a type writer.
52 
53        @param version the version of the created type writer; must not be
54        negative
55 
56        @param documentation the documentation
57 
58        @param fileName the file name (deprecated, use an empty string)
59 
60        @param typeClass the type class of the created type writer
61 
62        @param published whether the created type writer is published; for a type
63        class that cannot be published, this should be false
64 
65        @param typeName the type name of the created type writer
66 
67        @param superTypeCount the number of super types of the created type
68        writer
69 
70        @param fieldCount the number of fields of the created type writer
71 
72        @param methodCount the number of methods of the created type writer
73 
74        @param referenceCount the number of references of the created type writer
75 
76        @exception std::bad_alloc is raised if an out-of-memory condition occurs
77      */
Writer(typereg_Version version,rtl::OUString const & documentation,rtl::OUString const & fileName,RTTypeClass typeClass,bool published,rtl::OUString const & typeName,sal_uInt16 superTypeCount,sal_uInt16 fieldCount,sal_uInt16 methodCount,sal_uInt16 referenceCount)78     Writer(
79         typereg_Version version, rtl::OUString const & documentation,
80         rtl::OUString const & fileName, RTTypeClass typeClass, bool published,
81         rtl::OUString const & typeName, sal_uInt16 superTypeCount,
82         sal_uInt16 fieldCount, sal_uInt16 methodCount,
83         sal_uInt16 referenceCount):
84         m_handle(
85             typereg_writer_create(
86                 version, documentation.pData, fileName.pData, typeClass,
87                 published, typeName.pData, superTypeCount, fieldCount,
88                 methodCount, referenceCount))
89     {
90         if (m_handle == 0) {
91             throw std::bad_alloc();
92         }
93     }
94 
95     /**
96        Destroys this <code>Writer</code> instance.
97      */
~Writer()98     ~Writer() {
99         typereg_writer_destroy(m_handle);
100     }
101 
102     /**
103        Sets the type name of a super type of this type writer.
104 
105        @param index a valid index into the range of super types of this type
106        writer
107 
108        @param typeName the super type name
109 
110        @exception std::bad_alloc is raised if an out-of-memory condition occurs
111      */
setSuperTypeName(sal_uInt16 index,rtl::OUString const & typeName)112     void setSuperTypeName(sal_uInt16 index, rtl::OUString const & typeName) {
113         if (!typereg_writer_setSuperTypeName(m_handle, index, typeName.pData)) {
114             throw std::bad_alloc();
115         }
116     }
117 
118     /**
119        Sets the data of a field of this type writer.
120 
121        @param index a valid index into the range of fields of this type writer
122 
123        @param documentation the documentation of the field
124 
125        @param fileName the file name of the field (deprecated, use an empty string)
126 
127        @param flags the flags of the field
128 
129        @param name the name of the field
130 
131        @param typeName the type name of the field
132 
133        @param valueType the type of the value of the field
134 
135        @param valueValue the value of the value of the field
136 
137        @exception std::bad_alloc is raised if an out-of-memory condition occurs
138      */
setFieldData(sal_uInt16 index,rtl::OUString const & documentation,rtl::OUString const & fileName,RTFieldAccess flags,rtl::OUString const & name,rtl::OUString const & typeName,RTConstValue const & value)139     void setFieldData(
140         sal_uInt16 index, rtl::OUString const & documentation,
141         rtl::OUString const & fileName, RTFieldAccess flags, rtl::OUString const & name,
142         rtl::OUString const & typeName, RTConstValue const & value)
143     {
144         if (!typereg_writer_setFieldData(
145                 m_handle, index, documentation.pData, fileName.pData, flags,
146                 name.pData, typeName.pData, value.m_type, value.m_value))
147         {
148             throw std::bad_alloc();
149         }
150     }
151 
152     /**
153        Sets the data of a method of this type writer.
154 
155        @param index a valid index into the range of methods of this type writer
156 
157        @param documentation the documentation of the method
158 
159        @param flags the flags of the method
160 
161        @param name the name of the method
162 
163        @param returnTypeName the return type name of the method
164 
165        @param parameterCount the number of parameters of the method
166 
167        @param exceptionCount the number of exceptions of the method
168 
169        @exception std::bad_alloc is raised if an out-of-memory condition occurs
170      */
setMethodData(sal_uInt16 index,rtl::OUString const & documentation,RTMethodMode flags,rtl::OUString const & name,rtl::OUString const & returnTypeName,sal_uInt16 parameterCount,sal_uInt16 exceptionCount)171     void setMethodData(
172         sal_uInt16 index, rtl::OUString const & documentation,
173         RTMethodMode flags, rtl::OUString const & name,
174         rtl::OUString const & returnTypeName, sal_uInt16 parameterCount,
175         sal_uInt16 exceptionCount)
176     {
177         if (!typereg_writer_setMethodData(
178                 m_handle, index, documentation.pData, flags, name.pData,
179                 returnTypeName.pData, parameterCount, exceptionCount))
180         {
181             throw std::bad_alloc();
182         }
183     }
184 
185     /**
186        Sets the data of a parameter of a method of this type writer.
187 
188        @param methodIndex a valid index into the range of methods of this type
189        writer
190 
191        @param parameterIndex a valid index into the range of parameters of the
192        given method
193 
194        @param flags the flags of the parameter
195 
196        @param name the name of the parameter
197 
198        @param typeName the type name of the parameter
199 
200        @exception std::bad_alloc is raised if an out-of-memory condition occurs
201      */
setMethodParameterData(sal_uInt16 methodIndex,sal_uInt16 parameterIndex,RTParamMode flags,rtl::OUString const & name,rtl::OUString const & typeName)202     void setMethodParameterData(
203         sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
204         RTParamMode flags, rtl::OUString const & name,
205         rtl::OUString const & typeName)
206     {
207         if (!typereg_writer_setMethodParameterData(
208                 m_handle, methodIndex, parameterIndex, flags, name.pData,
209                 typeName.pData))
210         {
211             throw std::bad_alloc();
212         }
213     }
214 
215     /**
216        Sets an exception type name of a method of this type writer.
217 
218        @param methodIndex a valid index into the range of methods of this type
219        writer
220 
221        @param exceptionIndex a valid index into the range of exceptions of the
222        given method
223 
224        @param typeName the exception type name
225 
226        @exception std::bad_alloc is raised if an out-of-memory condition occurs
227      */
setMethodExceptionTypeName(sal_uInt16 methodIndex,sal_uInt16 exceptionIndex,rtl::OUString const & typeName)228     void setMethodExceptionTypeName(
229         sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
230         rtl::OUString const & typeName)
231     {
232         if (!typereg_writer_setMethodExceptionTypeName(
233                 m_handle, methodIndex, exceptionIndex, typeName.pData))
234         {
235             throw std::bad_alloc();
236         }
237     }
238 
239     /**
240        Sets the data of a reference of this type writer.
241 
242        @param handle a handle on a type writer
243 
244        @param index a valid index into the range of references of this type
245        writer
246 
247        @param documentation the documentation of the reference
248 
249        @param sort the sort of the reference
250 
251        @param flags the flags of the reference
252 
253        @param typeName the type name of the reference
254 
255        @exception std::bad_alloc is raised if an out-of-memory condition occurs
256      */
setReferenceData(sal_uInt16 index,rtl::OUString const & documentation,RTReferenceType sort,RTFieldAccess flags,rtl::OUString const & typeName)257     void setReferenceData(
258         sal_uInt16 index, rtl::OUString const & documentation,
259         RTReferenceType sort, RTFieldAccess flags,
260         rtl::OUString const & typeName)
261     {
262         if (!typereg_writer_setReferenceData(
263                 m_handle, index, documentation.pData, sort, flags,
264                 typeName.pData))
265         {
266             throw std::bad_alloc();
267         }
268     }
269 
270     /**
271        Returns the blob of this type writer.
272 
273        @param size an out-parameter obtaining the size of the blob
274 
275        @return a (byte-aligned) pointer to the blob; the returned pointer and
276        the returned <code>size</code> remain valid until the next function is
277        called on this type writer
278 
279        @exception std::bad_alloc is raised if an out-of-memory condition occurs
280        (in which case <code>siez</code> is not modified
281      */
getBlob(sal_uInt32 * size)282     void const * getBlob(sal_uInt32 * size) {
283         void const * p = typereg_writer_getBlob(m_handle, size);
284         if (p == 0) {
285             throw std::bad_alloc();
286         }
287         return p;
288     }
289 
290 private:
291     Writer(Writer &); // not implemented
292     void operator =(Writer); // not implemented
293 
294     void * m_handle;
295 };
296 
297 }
298 
299 #endif
300